-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcreateSVGSet.js
More file actions
69 lines (61 loc) · 1.86 KB
/
Copy pathcreateSVGSet.js
File metadata and controls
69 lines (61 loc) · 1.86 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
const fs = require('fs');
const path = require("path")
const getAllFiles = function(dirPath, objOfFiles) {
const files = fs.readdirSync(dirPath);
objOfFiles = objOfFiles || {};
files.forEach(function(file) {
if (fs.statSync(dirPath + "/" + file).isDirectory()) {
objOfFiles = getAllFiles(dirPath + "/" + file, objOfFiles);
return;
}
if (file.indexOf('svg') < 0) return;
if (file.indexOf('48px') < 0) return;
if (dirPath.indexOf('production') < 0) return;
const key = file.replace(/ic_/g, '').replace(/_48px.svg/g, '');
objOfFiles[key] = path.join(__dirname, dirPath, "/", file);
})
return objOfFiles;
}
const files = getAllFiles('material-design-icons');
const filesKeys = Object.keys(files);
const iconObject = {};
let readIndex = 0;
let failCount = 0;
let sucessCount = 0;
filesKeys.forEach(key => {
fs.readFile(files[key], 'utf8', (err, data) => {
const fdata = data.substring(data.indexOf('path') + 4, data.length - 9);
const f2data = fdata.substring(fdata.indexOf(' d="') + 4);
if (
f2data[0] !== 'M'
|| f2data.indexOf('path') > 0
|| f2data.indexOf('circle') > 0
|| f2data.indexOf('fill') > 0
|| key === 'fiber_smart_record'
) {
failCount += 1;
console.log(`tranfer fail: ${failCount}`);
console.log(data);
console.log(`${key} === ${f2data}\r\n`);
} else {
iconObject[key] = f2data;
sucessCount += 1;
}
readIndex += 1;
if (readIndex === filesKeys.length) {
console.log(`sucessCount: ${sucessCount}`);
fs.writeFile(
'test.js',
`const icons = ${JSON.stringify(iconObject, null, 2)}`,
'utf8',
() => {}
);
fs.writeFile(
'icons.js',
`module.exports = ${JSON.stringify(iconObject, null, 2)}`,
'utf8',
() => {}
);
}
});
});