/
build_bug.js
386 lines (362 loc) · 13.7 KB
/
build_bug.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
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
'use strict';
var Base64 = require('js-base64').Base64;
const fs = require('fs');
//const shell = require('shelljs')
//shell.exec('sh scan-icons.sh')
var json4icons = require('./img/json4icons.json');
var vFilename = "";
function get_extension(pFilename) {
var ext = "";
if (pFilename) {
ext = pFilename.substr(pFilename.lastIndexOf('.') + 1);
ext = ext.toLowerCase();
} else {
console.log("CALL: get_extension(pFilename) - pFilename undefined!");
}
return ext;
}
function replaceString(pString,pSearch,pReplace)
// replaces in the string "pString" multiple substrings "pSearch" by "pReplace"
{
var vReturnString = '';
//alert("cstring.js - replaceString() "+pString);
pString = pString || "undefined string parameter in replaceString() call ";
if (!pString) {
console.log("replaceString()-Call - pString not defined!");
} else if (pString != '') {
var vHelpString = '';
var vN = pString.indexOf(pSearch);
while ( vN+1 > 0 ) {
if (vN > 0) {
vReturnString += pString.substring(0, vN);
};
vReturnString += pReplace;
if (vN + pSearch.length < pString.length) {
pString = pString.substring(vN+pSearch.length, pString.length);
} else {
pString = ''
}
vN = pString.indexOf(pSearch);
};
};
return (vReturnString + pString);
}
function capitalizeFirstLetter(string) {
if (!string) {
string = "undef_string"
};
return string.charAt(0).toUpperCase() + string.slice(1);
}
function get_wikicommons_url(data) {
var url = "https://jquerymobile.com/download/";
if (data) {
var pos = data.indexOf("wikicommons");
if (pos > 0) {
data = data.substr(pos + 1);
var arr = data.split('"');
if (arr.length > 2) {
url = arr[1];
console.log("WikiCommons URL: '" + url + "'");
}
}
}
return url;
}
function save_icon4color(pFilename,pInsert,pData) {
var position = pFilename.lastIndexOf(".");
if (pFilename.indexOf("-white.") > 0) {
// WHITE: exclude files that are already styled with a specfic color
console.warn("File '" + pFilename + "' is already an Icon with a defined color! File ignored");
} else if (pFilename.indexOf("-black.") > 0) {
// BLACK: exclude files that are already styled with a specfic color
console.warn("File '" + pFilename + "' is already an Icon with a defined color! File ignored");
} else if (pFilename.indexOf("-red.") > 0) {
// WHITE: exclude files that are already styled with a specfic color
console.warn("File '" + pFilename + "' is already an Icon with a defined color! File ignored");
} else {
var vFilename4Color = [pFilename.slice(0, position), pInsert, pFilename.slice(position)].join('');
console.log("Save Icon with color postfix 'pInsert' to '" + vFilename4Color + "'");
fs.writeFile(vFilename4Color, pData, (err) => {
// throws an error, you could also catch it here
if (err) throw err;
// success case, the file was saved
console.log("DONE: Save Icon for Color '" + vFilename4Color + "'!");
});
}
}
function correct_size(pData) {
if (pData) {
pData = replaceString(pData,'width="100%"','width="14px"');
pData = replaceString(pData,'height="100%"','height="14px"');
} else {
pData = "undefined image";
}
return pData;
}
function save_color_icons(pFilename,pi,pName,pData) {
var data = pData;
if (pName.indexOf("fa-") == 0) {
if ((pName.indexOf("-white.svg") > 0) || (pName.indexOf("-black.svg") > 0)) {
// no write files
} else {
// search 'style="fill:currentColor"' and replace with
data = replaceString(data,'style="fill:currentColor"','style="fill:#FFF"');
data = replaceString(data,'fill="currentColor"','fill="#FFF"');
// fill="currentColor"
data = correct_size(data);
save_icon4color(pFilename,"-white",data);
data = pData;
data = replaceString(data,'style="fill:currentColor"','style="fill:#000"');
data = replaceString(data,'fill="currentColor"','fill="#000"');
data = correct_size(data);
save_icon4color(pFilename,"-black",data);
}
}
}
function save_data2json(pFilename,pi,pName) {
var ext = get_extension(pFilename);
switch (ext) {
case "svg":
var data = fs.readFileSync(pFilename, 'utf8');
console.log("Read Icon File SYNC: '" + pFilename + "'");
//json4icons.icons[i].src = "data:image/svg+xml;utf8," + data; // SVG is a XML string so store as string
//json4icons.icons[i].src = "data:image/svg+xml;base64," + data.toString('base64'); // SVG is a XML string so store as string
json4icons.icons[i].src = "data:image/svg+xml;base64," + Base64.encode(data);
json4icons.icons[i].raw = data;
json4icons.icons[i].wikicommons = get_wikicommons_url(data);
save_color_icons(pFilename,pi,pName,data);
break;
case "png":
var data = fs.readFileSync(pFilename);
console.log("PNG-File '" + pFilename + "' stored base64 encoded");
json4icons.icons[i].src = "data:image/png;base64," + data.toString('base64');
json4icons.icons[i].wikicommons = get_wikicommons_url(null);
break;
default:
console.error("Unsupported Filetype '" + ext + "' of Icon: '" + pFilename + "'");
}
}
function init_icon_group() {
var vName = "";
for (var i = 0; i < json4icons.icons.length; i++) {
json4icons.icons[i].group="other";
vName = json4icons.icons[i].name;
if (vName.indexOf("fa-file-archive") == 0) {
//---- FILE TYPES ----
json4icons.icons[i].group = "filetype";
} else if (vName.indexOf("home") == 0) {
//---- MAIN ----
json4icons.icons[i].group = "main";
} else if (vName.indexOf("action") == 0) {
//---- MAIN ----
json4icons.icons[i].group = "main";
} else if (vName.indexOf("fa-folder") == 0) {
//---- MAIN ----
json4icons.icons[i].group = "main";
} else if (vName.indexOf("fa-save") == 0) {
//---- MAIN ----
json4icons.icons[i].group = "main";
} else if (vName.indexOf("shop") == 0) {
//---- MAIN ----
json4icons.icons[i].group = "main";
} else if (vName.indexOf("home") == 0) {
//---- MAIN ----
json4icons.icons[i].group = "main";
} else if (vName.indexOf("info") == 0) {
//---- MAIN ----
json4icons.icons[i].group = "main";
} else if (vName.indexOf("fa-settings") == 0) {
//---- MAIN ----
json4icons.icons[i].group = "main";
} else if (vName.indexOf("fa-trash") == 0) {
//---- MAIN ----
json4icons.icons[i].group = "main";
} else if (vName.indexOf("grid") == 0) {
//---- MAIN ----
json4icons.icons[i].group = "main";
} else if (vName.indexOf("fa-print") == 0) {
//---- MAIN ----
json4icons.icons[i].group = "main";
} else if (vName.indexOf("fa-hamburger") == 0) {
//---- MAIN ----
json4icons.icons[i].group = "main";
} else if (vName.indexOf("fa-cancel") == 0) {
//---- ACTION/PROCESSES ----
json4icons.icons[i].group = "action";
} else if (vName.indexOf("fa-undo") == 0) {
//---- ACTION/PROCESSES ----
json4icons.icons[i].group = "action";
} else if (vName.indexOf("fa-cancel") == 0) {
//---- ACTION/PROCESSES ----
json4icons.icons[i].group = "action";
} else if (vName.indexOf("plus") == 0) {
//---- ACTION/PROCESSES ----
json4icons.icons[i].group = "action";
} else if (vName.indexOf("minus") == 0) {
//---- ACTION/PROCESSES ----
json4icons.icons[i].group = "action";
} else if (vName.indexOf("star") == 0) {
//---- ACTION/PROCESSES ----
json4icons.icons[i].group = "action";
} else if (vName.indexOf("refresh") == 0) {
//---- ACTION/PROCESSES ----
json4icons.icons[i].group = "action";
} else if (vName.indexOf("fa-spinner") == 0) {
//---- ACTION/PROCESSES ----
json4icons.icons[i].group = "action";
} else if (vName.indexOf("forbidden") == 0) {
//---- ACTION/PROCESSES ----
json4icons.icons[i].group = "action";
} else if (vName.indexOf("tag") == 0) {
//---- ACTION/PROCESSES ----
json4icons.icons[i].group = "action";
} else if (vName.indexOf("arrow-") == 0) {
//---- ARROWS ----
json4icons.icons[i].group = "arrow";
} else if (vName.indexOf("alert-") == 0) {
//---- ACTIONS ----
json4icons.icons[i].group = "action";
} else if (vName.indexOf("location") == 0) {
//---- NAVIGATION ----
json4icons.icons[i].group = "navigation";
} else if (vName.indexOf("carat-") == 0) {
//---- NAVIGATION ----
json4icons.icons[i].group = "navigation";
} else if (vName.indexOf("navigation-") == 0) {
//---- NAVIGATION ----
json4icons.icons[i].group = "navigation";
} else if (vName.indexOf("location") == 0) {
//---- NAVIGATION ----
json4icons.icons[i].group = "navigation";
} else if (vName.indexOf("audio-") == 0) {
//---- MEDIA ----
json4icons.icons[i].group = "media";
} else if (vName.indexOf("video-") == 0) {
json4icons.icons[i].group = "media";
} else if (vName.indexOf("fa-line-chart") == 0) {
json4icons.icons[i].group = "media";
} else if (vName.indexOf("fa-chart-pie") == 0) {
json4icons.icons[i].group = "media";
} else if (vName.indexOf("fa-audio-") == 0) {
json4icons.icons[i].group = "audio";
} else if (vName.indexOf("audio-") == 0) {
json4icons.icons[i].group = "audio";
} else if (vName.indexOf("user") == 0) {
//---- LOGIN/SIGN IN/OUT ----
json4icons.icons[i].group = "login";
} else if (vName.indexOf("fa-sign") == 0) {
//---- LOGIN/SIGN IN/OUT ----
json4icons.icons[i].group = "login";
} else if (vName.indexOf("power") == 0) {
//---- LOGIN/SIGN IN/OUT ----
json4icons.icons[i].group = "login";
} else if (vName.indexOf("fa-enumeration") == 0) {
//---- EDITOR ----
json4icons.icons[i].group = "editor";
} else if (vName.indexOf("fa-list") == 0) {
json4icons.icons[i].group = "editor";
} else if (vName.indexOf("fa-copy") == 0) {
json4icons.icons[i].group = "editor";
} else if (vName.indexOf("fa-paste") == 0) {
json4icons.icons[i].group = "editor";
} else if (vName.indexOf("fa-font") == 0) {
json4icons.icons[i].group = "editor";
} else if (vName.indexOf("search") == 0) {
json4icons.icons[i].group = "editor";
} else if (vName.indexOf("fa-plus-") == 0) {
json4icons.icons[i].group = "editor";
} else if (vName.indexOf("fa-minus-") == 0) {
json4icons.icons[i].group = "editor";
} else if (vName.indexOf("heart") == 0) {
//---- MEDICAL ----
json4icons.icons[i].group = "medical";
} else if (vName.indexOf("fa-vr-") == 0) {
//---- DEVICE ----
json4icons.icons[i].group = "device";
} else if (vName.indexOf("fa-tablet") == 0) {
//---- DEVICE ----
json4icons.icons[i].group = "device";
} else if (vName.indexOf("phone") == 0) {
//---- DEVICE ----
json4icons.icons[i].group = "device";
} else if (vName.indexOf("phone") == 0) {
//---- DEVICE ----
json4icons.icons[i].group = "device";
} else if (vName.indexOf("fa-camera") == 0) {
//---- DEVICE ----
json4icons.icons[i].group = "device";
} else if (vName.indexOf("fa-tablet") == 0) {
//---- DEVICE ----
json4icons.icons[i].group = "device";
} else if (vName.indexOf("fa-book") == 0) {
//---- PRODUCT/OBJECTS ----
json4icons.icons[i].group = "product";
} else if (vName.indexOf("fa-key") == 0) {
//---- ACTION/PROCESSES ----
json4icons.icons[i].group = "product";
} else if (vName.indexOf("fa-picture") == 0) {
//---- PRODUCT/OBJECTS ----
json4icons.icons[i].group = "product";
} else if (vName.indexOf("fa-truck") == 0) {
//---- VEHICLE ----
json4icons.icons[i].group = "vehicle";
}
}
}
function init_data2json() {
var vName = "";
for (var i = 0; i < json4icons.icons.length; i++) {
json4icons.icons[i].src="data_url";
vName = json4icons.icons[i].name;
if (vName.indexOf("fa-") == 0) {
json4icons.icons[i].license = "CC BY-SA 3.0";
} else {
json4icons.icons[i].license = "CC0";
};
/*
json4icons.icons[i].id4src = "/5/5d/";
json4icons.icons[i].name4src = "Font_Awesome____.svg";
json4icons.icons[i].adddate = "2019"
*/
}
init_icon_group();
}
//==== START SCANNING IMAGES for ICON4MENU ============
init_data2json();
// -------------- Convert and Encode Files --------------------------
for (var i = 0; i < json4icons.icons.length; i++) {
//console.log("Icon: json4icons.icons[i].path='" + json4icons.icons[i].path + "'");
// set the filename
vFilename = "./" + json4icons.icons[i].path + "/" + json4icons.icons[i].name;
//console.log("Icon File: '" + vFilename + "'");
try {
if (fs.existsSync(vFilename)) {
//console.log("Icon File EXISTS: '" + vFilename + "'");
//file exists
save_data2json(vFilename,i,json4icons.icons[i].name);
}
} catch(err) {
console.error(err);
}
}
function save_icons4json() {
var json_string = JSON.stringify(json4icons,null,4);
fs.writeFile('./img/json4icons.json', json_string, (err) => {
// throws an error, you could also catch it here
if (err) throw err;
// success case, the file was saved
console.log('JSON file json4icons.json saved with Base64 encoded icons!');
});
json_string = "vDataJSON.json4icons = " + json_string + ";";
fs.writeFile('./img/json4icons.js', json_string, (err) => {
// throws an error, you could also catch it here
if (err) throw err;
// success case, the file was saved
console.log('Javascript Library for Icons json2icons.js saved with Base64 encoded icons!');
});
}
function save_all_files() {
//save_icons4json();
//save_wget_icons()
}
setTimeout(save_all_files, 2000);