Skip to content

Commit 9be7053

Browse files
committed
Generates icon maps for codicons and glicons
1 parent cb71cee commit 9be7053

File tree

13 files changed

+1455
-2158
lines changed

13 files changed

+1455
-2158
lines changed

.fantasticonrc.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,12 @@ const config = {
1212
fontTypes: ['woff2'],
1313
normalize: true,
1414
// @ts-ignore
15-
assetTypes: ['html', 'scss', 'json'],
15+
assetTypes: ['html', 'scss', 'json', 'sass', 'css'],
1616
templates: {
1717
html: './images/icons/template/icons-contribution.hbs',
1818
scss: './images/icons/template/styles.hbs',
19+
sass: './images/icons/template/sass-map.hbs',
20+
css: './images/icons/template/component-map.hbs',
1921
},
2022
formatOptions: {
2123
json: {
@@ -25,8 +27,10 @@ const config = {
2527
pathOptions: {
2628
woff2: './dist/glicons.woff2',
2729
scss: './dist/glicons.scss',
30+
sass: './dist/glicons-map.scss',
2831
html: './dist/icons-contribution.json',
2932
json: './images/icons/template/mapping.json',
33+
css: './dist/glicons-map.ts',
3034
},
3135
};
3236

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
// This file is generated by (vscode-gitlens)/scripts/export-codicons.js
2+
// Do not edit this file directly
3+
4+
export const iconFontFamily = '{{ name }}';
5+
6+
export const iconMap = Object.freeze({
7+
{{#each codepoints}}
8+
'{{ @key }}': '\\\{{ codepoint this }}',
9+
{{/each}}
10+
});

images/icons/template/sass-map.hbs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
// This file is generated by (vscode-gitlens)/scripts/export-codicons.js
2+
// Do not edit this file directly
3+
4+
$icon-font-family: '{{ name }}';
5+
6+
$icon-map: (
7+
{{#each codepoints}}
8+
'{{@key}}': '\\{{ codepoint this }}',
9+
{{/each}}
10+
);

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19559,7 +19559,7 @@
1955919559
"build:extension": "webpack --mode development --config-name extension:node",
1956019560
"build:extension:browser": "webpack --mode development --config-name extension:webworker",
1956119561
"build:webviews": "webpack --mode development --config-name webviews",
19562-
"build:icons": "pnpm run icons:svgo && pnpm fantasticon && pnpm run icons:apply",
19562+
"build:icons": "pnpm run icons:svgo && pnpm fantasticon && pnpm run icons:apply && pnpm run icons:export",
1956319563
"build:tests": "node ./scripts/esbuild.tests.mjs --mode development",
1956419564
"generate:docs:telemetry": "node ./scripts/generate-telemetry-docs.mjs",
1956519565
"generate:emoji": "node ./scripts/generateEmojiShortcodeMap.mjs",
@@ -19576,6 +19576,7 @@
1957619576
"graph:unlink": "pnpm unlink @gitkraken/gitkraken-components && pnpm install --force",
1957719577
"graph:unlink:main": "pnpm graph:unlink && pushd \"../GitKrakenComponents\" && pnpm unlink && popd",
1957819578
"icons:apply": "node ./scripts/applyIconsContribution.mjs",
19579+
"icons:export": "node ./scripts/export-codicons.mjs",
1957919580
"icons:svgo": "svgo -q -f ./images/icons/ --config svgo.config.js",
1958019581
"lint": "pnpm run clean:lint && eslint .",
1958119582
"lint:fix": "pnpm run clean:lint && eslint . --fix",

scripts/applyIconsContribution.mjs

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@ const packageJSONPromises = Promise.all([
88
const scssPromises = Promise.all([
99
fs.promises.readFile('./dist/glicons.scss', 'utf8'),
1010
fs.promises.readFile('./src/webviews/apps/shared/glicons.scss', 'utf8'),
11+
fs.promises.readFile('./dist/glicons-map.scss', 'utf8'),
12+
fs.promises.readFile('./src/webviews/apps/shared/styles/icons/glicons-map.scss', 'utf8'),
13+
fs.promises.readFile('./dist/glicons-map.ts', 'utf8'),
14+
fs.promises.readFile('./src/webviews/apps/shared/components/icons/glicons-map.ts', 'utf8'),
1115
]);
1216

1317
let pending = [];
@@ -22,11 +26,24 @@ if (JSON.stringify(packageJSON.contributes.icons) !== JSON.stringify(icons.icons
2226
}
2327

2428
// Update the scss file
25-
const [newScss, scss] = await scssPromises;
29+
const [newScss, scss, newSassMap, sassMap, newTsMap, tsMap] = await scssPromises;
2630

2731
if (scss !== newScss) {
2832
pending.push(fs.promises.writeFile('./src/webviews/apps/shared/glicons.scss', newScss));
2933
}
3034

31-
pending.push(fs.promises.rm('./dist/icons-contribution.json'), fs.promises.rm('./dist/glicons.scss'));
35+
if (sassMap !== newSassMap) {
36+
pending.push(fs.promises.writeFile('./src/webviews/apps/shared/styles/icons/glicons-map.scss', newSassMap));
37+
}
38+
39+
if (tsMap !== newTsMap) {
40+
pending.push(fs.promises.writeFile('./src/webviews/apps/shared/components/icons/glicons-map.ts', newTsMap));
41+
}
42+
43+
pending.push(
44+
fs.promises.rm('./dist/icons-contribution.json'),
45+
fs.promises.rm('./dist/glicons.scss'),
46+
fs.promises.rm('./dist/glicons-map.scss'),
47+
fs.promises.rm('./dist/glicons-map.ts'),
48+
);
3249
await Promise.allSettled(pending);

scripts/export-codicons.mjs

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
import fs from 'fs';
2+
3+
function numberToCssContent(number, escape = '\\\\') {
4+
return `${escape}${number.toString(16)}`;
5+
}
6+
7+
console.time('Exported codicons');
8+
const { default: iconConfig } = await import('../node_modules/@vscode/codicons/.fantasticonrc.js');
9+
const { name, codepoints: icons } = iconConfig;
10+
11+
const iconEntries = Object.entries(icons);
12+
13+
const headerText = `// This file is generated by (vscode-gitlens)/scripts/export-codicons.js
14+
// Do not edit this file directly
15+
`;
16+
17+
const sassMapEntries = [];
18+
const tsMapEntries = [];
19+
for (const [key, value] of iconEntries) {
20+
sassMapEntries.push(` '${key}': '${numberToCssContent(value, '\\')}'`);
21+
tsMapEntries.push(` '${key}': '${numberToCssContent(value)}'`);
22+
}
23+
24+
// create a sass map of codicons and a ts file with a frozen object
25+
const scss = `${headerText}
26+
$icon-font-family: '${name}';
27+
28+
$icon-map: (
29+
${sassMapEntries.join(',\n')}
30+
);
31+
`;
32+
33+
const ts = `${headerText}
34+
export const iconFontFamily = '${name}';
35+
36+
export const iconMap = Object.freeze({
37+
${tsMapEntries.join(',\n')}
38+
});
39+
`;
40+
41+
const pending = [];
42+
43+
pending.push(fs.promises.writeFile('./src/webviews/apps/shared/styles/icons/codicons-map.scss', scss));
44+
pending.push(fs.promises.writeFile('./src/webviews/apps/shared/components/icons/codicons-map.ts', ts));
45+
46+
await Promise.allSettled(pending);
47+
console.timeEnd('Exported codicons');

0 commit comments

Comments
 (0)