Skip to content

Commit 12e33b1

Browse files
committed
Script to update codicons
1 parent 8dc3d52 commit 12e33b1

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+166
-98
lines changed

build/filters.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ module.exports.copyrightFilter = [
6464
'!tsconfig.json',
6565
'!tsconfig.test.json',
6666
'!tsconfig.webviews.json',
67+
'!tsconfig.scripts.json',
6768
'!tsfmt.json',
6869
'!**/queries*.gql',
6970
'!**/*.yml',

build/update-codicons.ts

Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
/*---------------------------------------------------------------------------------------------
2+
* Copyright (c) Microsoft Corporation. All rights reserved.
3+
* Licensed under the MIT License. See License.txt in the project root for license information.
4+
*--------------------------------------------------------------------------------------------*/
5+
6+
import * as fs from 'fs';
7+
import * as path from 'path';
8+
import * as https from 'https';
9+
10+
const CODICONS_DIR = path.join(__dirname, '..', 'resources', 'icons', 'codicons');
11+
const BASE_URL = 'https://raw.githubusercontent.com/microsoft/vscode-codicons/refs/heads/mrleemurray/new-icons/src/icons';
12+
13+
interface UpdateResult {
14+
filename: string;
15+
status: 'updated' | 'unchanged' | 'error';
16+
error?: string;
17+
}
18+
19+
function readLocalIconFilenames(): string[] {
20+
return fs.readdirSync(CODICONS_DIR).filter(f => f.endsWith('.svg'));
21+
}
22+
23+
function fetchRemoteIcon(filename: string): Promise<string> {
24+
const url = `${BASE_URL}/${encodeURIComponent(filename)}`;
25+
return new Promise((resolve, reject) => {
26+
https.get(url, res => {
27+
const { statusCode } = res;
28+
if (statusCode !== 200) {
29+
res.resume(); // drain
30+
return reject(new Error(`Failed to fetch ${filename}: HTTP ${statusCode}`));
31+
}
32+
let data = '';
33+
res.setEncoding('utf8');
34+
res.on('data', chunk => { data += chunk; });
35+
res.on('end', () => resolve(data));
36+
}).on('error', reject);
37+
});
38+
}
39+
40+
async function updateIcon(filename: string): Promise<UpdateResult> {
41+
const localPath = path.join(CODICONS_DIR, filename);
42+
const oldContent = fs.readFileSync(localPath, 'utf8');
43+
try {
44+
const newContent = await fetchRemoteIcon(filename);
45+
if (normalize(oldContent) === normalize(newContent)) {
46+
return { filename, status: 'unchanged' };
47+
}
48+
fs.writeFileSync(localPath, newContent, 'utf8');
49+
return { filename, status: 'updated' };
50+
} catch (err: any) {
51+
return { filename, status: 'error', error: err?.message ?? String(err) };
52+
}
53+
}
54+
55+
function normalize(svg: string): string {
56+
return svg.replace(/\r\n?/g, '\n').trim();
57+
}
58+
59+
async function main(): Promise<void> {
60+
const icons = readLocalIconFilenames();
61+
if (!icons.length) {
62+
console.log('No codicon SVGs found to update.');
63+
return;
64+
}
65+
console.log(`Updating ${icons.length} codicon(s) from upstream...`);
66+
67+
const concurrency = 8;
68+
const queue = icons.slice();
69+
const results: UpdateResult[] = [];
70+
71+
async function worker(): Promise<void> {
72+
while (queue.length) {
73+
const file = queue.shift();
74+
if (!file) {
75+
break;
76+
}
77+
const result = await updateIcon(file);
78+
results.push(result);
79+
if (result.status === 'updated') {
80+
console.log(` ✔ ${file} updated`);
81+
} else if (result.status === 'unchanged') {
82+
console.log(` • ${file} unchanged`);
83+
} else {
84+
// allow-any-unicode-next-line
85+
console.warn(` ✖ ${file} ${result.error}`);
86+
}
87+
}
88+
}
89+
90+
const workers = Array.from({ length: Math.min(concurrency, icons.length) }, () => worker());
91+
await Promise.all(workers);
92+
93+
const updated = results.filter(r => r.status === 'updated').length;
94+
const unchanged = results.filter(r => r.status === 'unchanged').length;
95+
const errored = results.filter(r => r.status === 'error').length;
96+
console.log(`Done. Updated: ${updated}, Unchanged: ${unchanged}, Errors: ${errored}.`);
97+
if (errored) {
98+
process.exitCode = 1;
99+
}
100+
}
101+
102+
main().catch(err => {
103+
console.error(err?.stack || err?.message || String(err));
104+
process.exit(1);
105+
});
106+
107+
export { }; // ensure this file is treated as a module

eslint.config.mjs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ export default defineConfig([
1515
// Global ignore patterns
1616
{
1717
ignores: [
18+
'build',
1819
'dist/**/*',
1920
'out/**/*',
2021
'src/@types/**/*.d.ts',

package.json

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4257,7 +4257,8 @@
42574257
"watch": "webpack --watch --mode development --env esbuild",
42584258
"watch:web": "webpack --watch --mode development --config-name extension:webworker --config-name webviews",
42594259
"hygiene": "node ./build/hygiene.js",
4260-
"prepare": "husky install"
4260+
"prepare": "husky install",
4261+
"update:codicons": "npx ts-node --project tsconfig.scripts.json build/update-codicons.ts"
42614262
},
42624263
"devDependencies": {
42634264
"@eslint/js": "^9.36.0",
@@ -4321,6 +4322,7 @@
43214322
"terser-webpack-plugin": "5.1.1",
43224323
"timers-browserify": "^2.0.12",
43234324
"ts-loader": "9.5.2",
4325+
"ts-node": "^10.9.2",
43244326
"tty": "1.0.1",
43254327
"typescript": "^5.9.2",
43264328
"typescript-eslint": "^8.44.0",
@@ -4364,4 +4366,4 @@
43644366
"string_decoder": "^1.3.0"
43654367
},
43664368
"license": "MIT"
4367-
}
4369+
}
Lines changed: 1 addition & 10 deletions
Loading

resources/icons/codicons/add.svg

Lines changed: 1 addition & 3 deletions
Loading

resources/icons/codicons/check.svg

Lines changed: 1 addition & 3 deletions
Loading
Lines changed: 1 addition & 3 deletions
Loading
Lines changed: 1 addition & 3 deletions
Loading

resources/icons/codicons/close.svg

Lines changed: 1 addition & 3 deletions
Loading

0 commit comments

Comments
 (0)