-
Notifications
You must be signed in to change notification settings - Fork 2
/
util.js
53 lines (42 loc) · 1.31 KB
/
util.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
const fs = require('fs');
const encoding = "utf8";
const folder = `${__dirname}/../`;
const packageName = 'svg'
const getVersion = (overridePackageName) => {
const pName = overridePackageName || packageName;
const file = fs.readFileSync(`${folder}${pName}/package.json`, { encoding });
return JSON.parse(file).version;
};
const getMeta = (withPaths, overridePackageName) => {
const pName = overridePackageName || packageName;
const file = fs.readFileSync(`${folder}${pName}/meta.json`, { encoding });
const meta = JSON.parse(file);
if (withPaths) {
const total = meta.length;
meta.forEach((icon, i) => {
const svg = fs.readFileSync(`${folder}${pName}/svg/${icon.name}.svg`, { encoding });
icon.path = svg.match(/ d="([^"]+)"/)[1];
});
}
return meta;
};
exports.getVersionLight = () => {
return getVersion('light-svg');
}
exports.getMetaLight = (withPaths) => {
return getMeta(withPaths, 'light-svg');
}
exports.getVersion = getVersion;
exports.getMeta = getMeta;
exports.closePath = (path) => {
return path.replace(/(\d)M/g, '$1ZM');
};
exports.write = (file, data) => {
fs.writeFileSync(file, data);
};
exports.read = (file) => {
return fs.readFileSync(file, 'utf8');
};
exports.exists = (file) => {
return fs.exists(file);
};