-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcli.ts
88 lines (76 loc) · 2.23 KB
/
cli.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
import fs from "node:fs";
import path from "node:path";
import inquirer from "inquirer";
import fg from "fast-glob";
import { downloadProfile, type Profile } from "./src/downloadProfile";
import {
DEFAULT_CSS,
DEFAULT_EXT,
DEFAULT_OUTDIR,
DEFAULT_PATTERN,
DEFAULT_UA,
} from "./src/const";
import { Subset } from "./src/Subset";
async function main() {
const profiles = await fg.glob("profiles/*.json", {
ignore: ["profiles/schema.json"],
});
const file = await inquirer
// biome-ignore lint/suspicious/noExplicitAny: <explanation>
.prompt<any, { file: string }>([
{
type: "list",
message: "プロファイルを選択してください",
name: "file",
choices: profiles,
},
])
.then(async (answers) => answers.file);
const json = await fs.promises.readFile(file);
const profile = JSON.parse(json.toString()) as Profile;
const { $schema, chunk, subset, ...settings } = profile;
const defaultSettings = {
outDir: `${DEFAULT_OUTDIR}/${path.parse(file).name}`,
cssFile: `${DEFAULT_CSS}`,
urlPrefix: "(N/A)",
userAgent: `${DEFAULT_UA}`,
ext: `${DEFAULT_EXT}`,
pattern: `${DEFAULT_PATTERN}`,
};
if (!profile.outDir) {
profile.outDir = `${DEFAULT_OUTDIR}/${path.parse(file).name}`;
}
console.info("Settings");
console.table({ ...defaultSettings, ...settings });
console.info("Chunks");
console.table(chunk);
console.info("Subsets");
console.table(
subset?.map((s) => {
const { text, ...rest } = s;
const resolvedText = Subset.textFormatter(text);
return {
...rest,
text: `${resolvedText.slice(0, 10)}${
resolvedText.length > 10 ? "..." : ""
} (${resolvedText.length} chars)`,
};
}),
);
const confirm = await inquirer
// biome-ignore lint/suspicious/noExplicitAny: <explanation>
.prompt<any, { confirm: boolean }>({
confirm: {
type: "confirm",
message: "上記のフォントをダウンロードします、よろしいですか?",
default: false,
},
})
.then(async (answers) => answers.confirm);
if (!confirm) {
console.info("中止しました");
process.exit(0);
}
await downloadProfile(profile);
}
main();