-
Notifications
You must be signed in to change notification settings - Fork 25
/
import.js
executable file
·353 lines (308 loc) · 9.89 KB
/
import.js
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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
#!/usr/bin/env node
const cson = require("cson");
const fs = require("fs");
const {execSync} = require("child_process");
const util = require("util");
const genex = require("genex");
const defs = cson.parseCSFile("./defs/config.cson");
const stylesIcons = fs.readFileSync("./defs/styles/icons.less").toString();
const darkFontColour = "#cccccc";
const lightFontColour = "#6c6c6c";
// HACK(#42)
defs.fileIcons["Pre-commit"].match = /^\.pre-commit-config\.(ya?ml)$/i;
const icons = {};
const regex = /\.(.*?)-icon:before\s+{\s+\.(\w+); content: "(.*?)"/g;
const fontMap = {
fi: "file-icons",
fa: "fontawesome",
octicons: "octicons",
mf: "mfixx",
devicons: "devopicons",
};
// Hardcoded file- and folder-icons (i.e, those that are default in Atom)
const hardcoded = {
_folder: "\\f016",
_file: "\\f011",
"_icon-file-text": "\\f011",
"_icon-file-binary": "\\f094",
"_icon-file-zip": "\\f013",
"_icon-file-pdf": "\\f014",
"_icon-file-code": "\\f05f",
_fd_root: "\\f001",
_fd_root_open: "\\f001",
};
for(const key in hardcoded){
const value = hardcoded[key];
icons[key] = {
fontCharacter: value,
fontColor: darkFontColour,
fontId: "octicons",
};
icons[`${key}_l`] = {
fontCharacter: value,
fontColor: lightFontColour,
fontId: "octicons",
};
}
let match;
while(null !== (match = regex.exec(stylesIcons))){
const name = `_${match[1]}`;
const font = match[2];
const char = match[3];
icons[name] = {
fontCharacter: char,
fontColor: darkFontColour,
fontId: fontMap[font],
};
icons[`${name}_l`] = {
fontCharacter: char,
fontColor: lightFontColour,
fontId: fontMap[font],
};
}
const fonts = Object.values(fontMap).map(name => ({
id: name,
src: [{path: `./${name}.woff2`, format: "woff2"}],
weight: "normal",
style: "normal",
size: "100%",
}));
const extensions = {};
const extensions_l = {};
const files = {};
const files_l = {};
const folders = {};
const folders_l = {};
const colourMap = {
// Red
"medium-red": "#ac4142",
"light-red": "#c97071",
"dark-red": "#c97071",
// Green
"medium-green": "#90a959",
"light-green": "#b2c38b",
"dark-green": "#66783e",
// Yellow
"medium-yellow": "#f4bf75",
"light-yellow": "#fae0bc",
"dark-yellow": "#ee9e2e",
// Blue
"medium-blue": "#6a9fb5",
"light-blue": "#9dc0ce",
"dark-blue": "#46788d",
// Maroon
"medium-maroon": "#8f5536",
"light-maroon": "#be7953",
"dark-maroon": "#573421",
// Purple
"medium-purple": "#aa759f",
"light-purple": "#c7a4c0",
"dark-purple": "#825078",
// Orange
"medium-orange": "#d28445",
"light-orange": "#e1ad83",
"dark-orange": "#a35f27",
// Cyan
"medium-cyan": "#75b5aa",
"light-cyan": "#a7d0c9",
"dark-cyan": "#4d9085",
// Pink
"medium-pink": "#ff00cc",
"light-pink": "#ff4ddb",
"dark-pink": "#b3008f",
};
function darkColourFor(colourName){
if(Array.isArray(colourName))
return colourMap[colourName[0]];
else if(colourMap[colourName])
return colourMap[colourName];
else if("string" === typeof colourName && colourName.startsWith("auto"))
return colourMap[colourName.replace("auto", "medium")];
else return darkFontColour;
}
function lightColourFor(colourName){
if(Array.isArray(colourName))
return colourMap[colourName[1]];
else if(colourMap[colourName])
return colourMap[colourName];
else if("string" === typeof colourName && colourName.startsWith("auto"))
return colourMap[colourName.replace("auto", "dark")];
else return lightFontColour;
}
function parseRegex(regex){
const gen = [];
try{
const count = genex(regex).count();
count <= 1000
? genex(regex).generate(output => gen.push(output))
: console.warn(`${regex} skipped; too many cases to generate: ${count}`);
}
catch(exception){
console.error(`${regex} skipped: ${exception}`);
}
return gen;
}
function process(hash, set, set_l){
const {match, icon, colour} = hash;
if(Array.isArray(match)){
for(let m = 0; m < match.length; ++m){
const nested = match[m];
const [ext, colour] = nested;
let iconName = icon;
if(icons[`_${icon}`] && undefined !== colour){
iconName = `${icon}_${colour}`;
const darkColour = darkColourFor(colour);
if(darkColour === undefined)
console.warn(`no dark colour in colourMap = ${colour}`);
icons[`_${iconName}`] = JSON.parse(JSON.stringify(icons[`_${icon}`]));
icons[`_${iconName}`].fontColor = darkColour;
const lightColour = lightColourFor(colour);
if(undefined === lightColour)
console.warn(`no light colour in colourMap = ${colour}`);
icons[`_${iconName}_l`] = JSON.parse(JSON.stringify(icons[`_${icon}_l`]));
icons[`_${iconName}_l`].fontColor = darkColour;
}
if(ext instanceof RegExp){
console.info(`regexp ${util.inspect(ext)}`);
const exts = parseRegex(ext);
for(let i = 0; i < exts.length; ++i){
const ext = exts[i];
if(ext.startsWith(".")){
extensions[ext.substring(1).toLowerCase()] = `_${iconName}`;
extensions_l[ext.substring(1).toLowerCase()] = `_${iconName}_l`;
}
else{
set[ext.toLowerCase()] = `_${iconName}`;
set_l[ext.toLowerCase()] = `_${iconName}_l`;
}
console.info(`${ext} => ${iconName}`);
}
}
else if("string" === typeof ext){
console.info(`string ${util.inspect(ext)}`);
if(ext.startsWith(".")){
extensions[ext.substring(1).toLowerCase()] = `_${iconName}`;
extensions_l[ext.substring(1).toLowerCase()] = `_${iconName}_l`;
}
else{
set[ext.toLowerCase()] = `_${iconName}`;
set_l[ext.toLowerCase()] = `_${iconName}_l`;
}
console.info(`${ext} => ${iconName}`);
}
else console.warn(`skipped ${ext}`);
}
}
else if(match instanceof RegExp){
const exts = parseRegex(match);
let iconName = icon;
if(icons[`_${icon}`] && undefined !== colour){
iconName = `${icon}_${colour}`;
const darkColour = darkColourFor(colour);
if(undefined === darkColour)
console.warn(`no dark colour in colourMap = ${colour}`);
icons[`_${iconName}`] = JSON.parse(JSON.stringify(icons[`_${icon}`]));
icons[`_${iconName}`].fontColor = darkColour;
const lightColour = lightColourFor(colour);
if(undefined === lightColour)
console.warn(`no light colour in colourMap = ${colour}`);
icons[`_${iconName}_l`] = JSON.parse(JSON.stringify(icons[`_${icon}_l`]));
icons[`_${iconName}_l`].fontColor = darkColour;
}
for(let i = 0; i < exts.length; ++i){
const ext = exts[i];
if(ext.startsWith(".")){
extensions[ext.substring(1).toLowerCase()] = `_${iconName}`;
extensions_l[ext.substring(1).toLowerCase()] = `_${iconName}_l`;
}
else{
set[ext.toLowerCase()] = `_${iconName}`;
set_l[ext.toLowerCase()] = `_${iconName}_l`;
}
console.info(`${ext} => ${iconName}`);
}
}
else if("string" === typeof match){
if(match.startsWith(".")){
let iconName = icon;
if(icons[`_${icon}`] && undefined !== colour){
iconName = `${icon}_${colour}`;
const darkColour = darkColourFor(colour);
if(undefined === darkColour)
console.warn(`no dark colour in colourMap = ${colour}`);
icons[`_${iconName}`] = JSON.parse(JSON.stringify(icons[`_${icon}`]));
icons[`_${iconName}`].fontColor = darkColour;
const lightColour = lightColourFor(colour);
if(undefined === lightColour)
console.warn(`no light colour in colourMap = ${colour}`);
icons[`_${iconName}_l`] = JSON.parse(JSON.stringify(icons[`_${icon}_l`]));
icons[`_${iconName}_l`].fontColor = darkColour;
}
extensions[match.substring(1).toLowerCase()] = `_${iconName}`;
extensions_l[match.substring(1).toLowerCase()] = `_${iconName}_l`;
console.info(`${match} => ${iconName}`);
}
else console.warn(`${match} skipped not a file extension`);
}
else console.warn(`${match} skipped type`);
}
// Hardcoded file- and folder-icons (i.e, those that are default in Atom)
extensions["gitattributes"] =
extensions["gitmodules"] =
extensions["gitignore"] = "_git_medium-red";
extensions["cfignore"] = "_gear_medium-yellow";
extensions_l["gitattributes"] =
extensions_l["gitmodules"] =
extensions_l["gitignore"] = "_git_medium-red_l";
extensions_l["cfignore"] = "_gear_medium-yellow_l";
// HACK(#47): Include JS test-file icons dropped by `genex` module
extensions["test.js"] =
extensions["tests.js"] =
extensions["-test.js"] =
extensions["-tests.js"] =
extensions["_test.js"] =
extensions["_tests.js"] = "_test-js_auto-yellow";
extensions_l["test.js"] =
extensions_l["tests.js"] =
extensions_l["-test.js"] =
extensions_l["-tests.js"] =
extensions_l["_test.js"] =
extensions_l["_tests.js"] = "_test-js_auto-yellow_l";
for(const fileIcon in defs.fileIcons)
process(defs.fileIcons[fileIcon], files, files_l);
for(const directoryIcon in defs.directoryIcons)
process(defs.directoryIcons[directoryIcon], folders, folders_l);
// BUGFIX: BUILD as a fileName has precendence over a file extension, i.e. build.js
delete files["BUILD"];
delete files_l["BUILD"];
// Export `file-icons-icon-theme.json` and `file-icons-colourless-icon-theme.json`
const root = {
fonts: fonts,
iconDefinitions: icons,
file: "_file",
folder: "_folder",
folderExpanded: "_folder",
rootFolder: "_fd_root",
rootFolderExpanded: "_fd_root_open",
fileExtensions: extensions,
fileNames: files,
folderNames: folders,
folderNamesExpanded: folders,
languageIds: {},
light: {
file: "_file_l",
folder: "_folder_l",
folderExpanded: "_folder_l",
fileExtensions: extensions_l,
fileNames: files_l,
folderNames: folders_l,
folderNamesExpanded: folders_l,
},
version: `https://github.com/file-icons/vscode/commit/${execSync("git rev-parse HEAD")}`.replace(/\n+/g, ""),
};
fs.writeFileSync("./icons/file-icons-icon-theme.json", JSON.stringify(root, null, "\t"));
for(const key of Object.keys(icons))
icons[key].fontColor = key.endsWith("_l")
? lightFontColour
: darkFontColour;
fs.writeFileSync("./icons/file-icons-colourless-icon-theme.json", JSON.stringify(root, null, "\t"));