Browse Source

Converts icons script to esm

Attempts to improve perf will better parallel i/o
main
Eric Amodio 1 year ago
parent
commit
e6c9fffae0
3 changed files with 33 additions and 23 deletions
  1. +1
    -1
      .fantasticonrc.js
  2. +0
    -22
      scripts/applyIconsContribution.js
  3. +32
    -0
      scripts/applyIconsContribution.mjs

+ 1
- 1
.fantasticonrc.js View File

@ -1,6 +1,6 @@
//@ts-check
/** @type { import('@twbs/fantasticon').RunnerOptions} } */
/** @type {import('@twbs/fantasticon').RunnerOptions} */
const config = {
name: 'glicons',
prefix: 'glicon',

+ 0
- 22
scripts/applyIconsContribution.js View File

@ -1,22 +0,0 @@
/* eslint-disable @typescript-eslint/no-var-requires */
const fs = require('fs');
// Update the icons contribution point in package.json
const package = require('../package.json');
const icons = require('../dist/icons-contribution.json').icons;
if (JSON.stringify(package.contributes.icons) !== JSON.stringify(icons)) {
package.contributes.icons = icons;
const packageJSON = `${JSON.stringify(package, undefined, '\t')}\n`;
fs.writeFileSync('./package.json', packageJSON);
}
fs.rmSync('./dist/icons-contribution.json');
// Update the scss file
const newScss = fs.readFileSync('./dist/glicons.scss', 'utf8');
const scss = fs.readFileSync('./src/webviews/apps/shared/glicons.scss', 'utf8');
if (scss !== newScss) {
fs.writeFileSync('./src/webviews/apps/shared/glicons.scss', newScss);
}
fs.rmSync('./dist/glicons.scss');

+ 32
- 0
scripts/applyIconsContribution.mjs View File

@ -0,0 +1,32 @@
import fs from 'fs';
const packageJSONPromises = Promise.all([
import('../package.json', { assert: { type: 'json' } }),
import('../dist/icons-contribution.json', { assert: { type: 'json' } }),
]);
const scssPromises = Promise.all([
fs.promises.readFile('./dist/glicons.scss', 'utf8'),
fs.promises.readFile('./src/webviews/apps/shared/glicons.scss', 'utf8'),
]);
let pending = [];
// Update the icons contribution point in package.json
const [{ default: packageJSON }, { default: icons }] = await packageJSONPromises;
if (JSON.stringify(packageJSON.contributes.icons) !== JSON.stringify(icons.icons)) {
packageJSON.contributes.icons = icons;
const json = `${JSON.stringify(packageJSON, undefined, '\t')}\n`;
pending.push(fs.promises.writeFile('./package.json', json));
}
// Update the scss file
const [newScss, scss] = await scssPromises;
if (scss !== newScss) {
pending.push(fs.promises.writeFile('./src/webviews/apps/shared/glicons.scss', newScss));
}
pending.push(fs.promises.rm('./dist/icons-contribution.json'), fs.promises.rm('./dist/glicons.scss'));
await Promise.allSettled(pending);

Loading…
Cancel
Save