-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprocess.js
62 lines (55 loc) · 1.62 KB
/
process.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
import { promisify } from "util";
import { exec } from "child_process";
import { existsSync } from "fs";
import { readFile, readdir, mkdir, rm } from "fs/promises";
import { IconSet, exportIconPackage } from "@iconify/tools";
console.log("updating icons...");
const execP = promisify(exec);
if (existsSync("icon-sets")) {
await execP("git -C icon-sets pull");
} else {
await execP(
"git clone https://github.com/iconify/icon-sets icon-sets --depth=1 --branch=master"
);
}
console.log("finished updating icons");
if (existsSync("icon-sets-output"))
await rm("icon-sets-output", { recursive: true });
await mkdir("icon-sets-output");
const process = async (name) => {
const rawData = JSON.parse(
await readFile(`icon-sets/json/${name}.json`, "utf8")
);
const iconSet = new IconSet(rawData);
if (iconSet.count() == 0) {
console.log(`skipping ${name}`);
return;
}
const version = rawData.info.version
? rawData.info.version
: rawData.lastModified
? `0.0.${rawData.lastModified}`
: null;
if (!version) {
throw new Error(`version missing for ${name}`);
}
console.log(`processing ${name}`);
await exportIconPackage(iconSet, {
target: `icon-sets-output/${name}`,
module: true,
package: {
name: `@ktibow/iconset-${name}`,
version,
homepage: "https://github.com/KTibow/to-icon-sets",
license: rawData.info.license.spdx,
},
});
};
const sets = await readdir("icon-sets/json");
let i = 0;
console.log("starting...");
sets.map(async (set) => {
const name = set.replace(".json", "");
await process(name);
console.log(`${++i}/${sets.length} ${name}`);
});