forked from yeungchenwa/FontDiffuser
-
Notifications
You must be signed in to change notification settings - Fork 0
/
run_pico.js
53 lines (49 loc) · 1.58 KB
/
run_pico.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
// https://github.com/chiaoooo/PngToTTF SVG ---> SVG 空白突出
const fs = require("fs").promises;
const { exec } = require("child_process");
const util = require("util");
const asyncPool = require("tiny-async-pool");
const inputFolder = process.argv[2] || "./svg_separate";
const outputFolder = process.argv[3] || "./pico";
const concurrency = 20; // 同时执行的最大任务数量 太高可能导致 EBADF 错误
const execPromise = util.promisify(exec);
async function asyncPoolAll(...args) {
const results = [];
for await (const result of asyncPool(...args)) {
results.push(result);
}
return results;
}
async function processFiles() {
const startTime = Date.now();
// Create output folder if it doesn't exist
try {
await fs.mkdir(outputFolder);
} catch (err) {
if (err.code !== "EEXIST") {
console.error("Error creating output folder:", err);
return;
}
}
try {
const files = await fs.readdir(inputFolder);
await asyncPoolAll(concurrency, files, async (filename) => {
try {
await execPromise(
`picosvg ${inputFolder}/${filename} > ${outputFolder}/${filename}`
);
console.log(
`picosvg ${inputFolder}/${filename} > ${outputFolder}/${filename}`
);
} catch (err) {
console.error(filename, `Error executing picosvg: ${err}`);
}
});
} catch (err) {
console.error("Error reading input folder:", err);
}
console.log("Conversion complete!");
const endTime = Date.now();
console.log("Time taken:", (endTime - startTime) / 1000, "seconds");
}
processFiles();