-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathsource.ts
More file actions
31 lines (27 loc) · 992 Bytes
/
Copy pathsource.ts
File metadata and controls
31 lines (27 loc) · 992 Bytes
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
import { join } from "node:path";
import { consola } from "consola";
import { writeFileSync } from "node:fs";
import { pinyin } from "@napi-rs/pinyin";
import { projectDir } from "../shared/dir";
import { genSources } from "../shared/pre-sources";
const sources = genSources();
try {
const pinyinMap = Object.fromEntries(
Object.entries(sources)
.filter(([, v]) => !v.redirect)
.map(([k, v]) => [k, pinyin(v.title ? `${v.name}-${v.title}` : v.name).join("")])
);
writeFileSync(join(projectDir, "./shared/pinyin.json"), JSON.stringify(pinyinMap, undefined, 2));
consola.info("Generated pinyin.json");
} catch {
consola.error("Failed to generate pinyin.json");
}
try {
writeFileSync(
join(projectDir, "./shared/sources.json"),
JSON.stringify(Object.fromEntries(Object.entries(sources)), undefined, 2)
);
consola.info("Generated sources.json");
} catch {
consola.error("Failed to generate sources.json");
}