-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathicon-inventory-gen.js
More file actions
114 lines (105 loc) · 3.6 KB
/
icon-inventory-gen.js
File metadata and controls
114 lines (105 loc) · 3.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
// VS Code Icon Inventory Data Generator
// This script scans the workspace for icons and images, counts their usage, and outputs icon-inventory.js data.
// Run with: node icon-inventory-gen.js
const fs = require('fs');
const path = require('path');
const workspace = __dirname;
const iconData = [];
// 1. Gather all SVG, PNG, JPG, etc. files
const exts = ['.svg', '.png', '.jpg', '.jpeg', '.gif', '.ico', '.icns', '.webp', '.bmp'];
function walk(dir) {
let results = [];
const list = fs.readdirSync(dir);
for (const file of list) {
const filePath = path.join(dir, file);
const stat = fs.statSync(filePath);
if (stat && stat.isDirectory()) {
results = results.concat(walk(filePath));
} else {
if (exts.includes(path.extname(file).toLowerCase())) {
results.push(filePath);
}
}
}
return results;
}
const imageFiles = walk(workspace);
// 2. For each image, try to count usage in the codebase
function countUsage(file) {
// Only search for the filename, not full path
const name = path.basename(file);
let count = 0;
function searchDir(dir) {
const list = fs.readdirSync(dir);
for (const f of list) {
const filePath = path.join(dir, f);
const stat = fs.statSync(filePath);
if (stat && stat.isDirectory()) {
searchDir(filePath);
} else if (f.endsWith('.ts') || f.endsWith('.js') || f.endsWith('.json') || f.endsWith('.md') || f.endsWith('.css') || f.endsWith('.html')) {
const content = fs.readFileSync(filePath, 'utf8');
count += (content.split(name).length - 1);
}
}
}
searchDir(workspace);
return count;
}
for (const file of imageFiles) {
const name = path.basename(file);
const type = path.extname(file).slice(1);
const relPath = path.relative(workspace, file);
const count = countUsage(file);
iconData.push({
iconType: 'img',
name,
desc: '',
count,
location: '',
type,
file: relPath
});
}
// 3. Codicons: extract from codiconsLibrary
const codiconsLibPath = path.join(workspace, 'src/vs/base/common/codiconsLibrary.ts');
if (fs.existsSync(codiconsLibPath)) {
const codiconSrc = fs.readFileSync(codiconsLibPath, 'utf8');
const codiconRegex = /register\('([\w-]+)'/g;
let match;
const codiconNames = new Set();
while ((match = codiconRegex.exec(codiconSrc))) {
codiconNames.add(match[1]);
}
for (const name of codiconNames) {
// Count usage: look for codicon-${name} and $(name)
let count = 0;
function searchCodiconUsage(dir) {
const list = fs.readdirSync(dir);
for (const f of list) {
const filePath = path.join(dir, f);
const stat = fs.statSync(filePath);
if (stat && stat.isDirectory()) {
searchCodiconUsage(filePath);
} else if (f.endsWith('.ts') || f.endsWith('.js') || f.endsWith('.json') || f.endsWith('.md') || f.endsWith('.css') || f.endsWith('.html')) {
const content = fs.readFileSync(filePath, 'utf8');
count += (content.split(`codicon-${name}`).length - 1);
count += (content.split(`$(${name})`).length - 1);
}
}
}
searchCodiconUsage(workspace);
iconData.push({
iconType: 'codicon',
name,
desc: '',
count,
location: '',
type: 'codicon',
file: ''
});
}
}
// 4. Output to icon-inventory.js
const out = `// Auto-generated icon data\nconst iconData = ${JSON.stringify(iconData, null, 2)};\n\n` + fs.readFileSync(path.join(workspace, 'icon-inventory.js'), 'utf8');
fs.writeFileSync(path.join(workspace, 'icon-inventory.js'), out);
console.log('Icon inventory generated. Open icon-inventory.html to view.');