-
Notifications
You must be signed in to change notification settings - Fork 19
/
Copy pathkamon.ts
90 lines (86 loc) · 2.75 KB
/
kamon.ts
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
import { readdirSync, readFileSync, writeFileSync, existsSync } from "fs";
import { XMLParser } from "fast-xml-parser";
const options = {
ignoreAttributes: false,
format: true,
};
const parser = new XMLParser(options);
const root = './svgs/kamons';
const categories = readdirSync(root);
//console.log(categories);
categories.map(category => {
if (category == '.DS_Store') {
return;
}
let files = readdirSync(`${root}/${category}`);
//console.log(category, files.length);
if (category == 'suhama') {
let files = readdirSync(`${root}/${category}`);
//console.log(files);
const items = files.filter((file, index) => {
return index < 100;
})
.filter((file, index) =>{ return (index>=0 && index<=999) && file != '.DS_Store'; })
.map((file, index) => {
let xml = readFileSync(`${root}/${category}/${file}`, 'utf8');
//console.log(xml);
const obj = parser.parse(xml);
const svg = obj.svg;
const width = parseInt(svg['@_width']);
const height = parseInt(svg['@_height']);
if (svg.path && (!svg.rect || !Array.isArray(svg.rect)) && !svg.g && !svg.polygon && !svg.circle) {
const paths = Array.isArray(svg.path) ? svg.path : [svg.path];
const bodies = paths.filter((path:any) => {
return !path['@_fill'] && path['@_style'] != "fill:none";
}).map((path:any) => {
return path['@_d'];
});
const item = { name:file.replace(/\.svg/, "").replace(/_/g, " "), width, height, bodies };
return item;
} else {
console.error(file, svg);
process.exit(0);
}
});
console.log(`export const assets = ${JSON.stringify(items)} ;`);
}
});
/*
mkdir(`./svgs/materials/${category}`, { recursive:false }, (err)=>{
console.error(err);
});
*/
/*
const path = `../material/src/${category}`;
const files = readdirSync(path);
files.map((file) => {
const path2 = `${path}/${file}/materialicons`;
if (existsSync(path2)) {
let files2 = readdirSync(path2);
files2 = files2.sort((f0, f1) => {
return parseInt(f0) > parseInt(f1) ? -1 : 1 ;
});
let xml = readFileSync(`${path2}/${files2[0]}`, 'utf8');
writeFileSync(`./svgs/materials/${category}/${file}.svg`, xml, 'utf8');
}
const obj = parser.parse(xml);
const svg = obj.svg;
const width = parseInt(svg['@_width']);
const height = parseInt(svg['@_height']);
if (svg.path) {
const paths = svg.path;
console.log("***", file, width, height, "***", paths);
} else if (svg.g) {
const g = svg.g;
console.log("***", file, width, height, "***", g);
} else {
console.error("error", file);
}
*/
/*
paths.map((path2:any) => {
console.log(path2);
});
});
})
*/