feat: 建立可复现字体包构建链

This commit is contained in:
SkyJourney
2026-07-31 21:52:36 +08:00
parent 9f96d51922
commit ae9fde3ac6
14 changed files with 1225 additions and 5 deletions
+76
View File
@@ -0,0 +1,76 @@
import { resolve } from "node:path";
import { buildFontPack, verifyFontPack } from "./builder.js";
function argumentsMap(values: string[]) {
const result = new Map<string, string>();
for (let index = 0; index < values.length; index += 2) {
const key = values[index];
const value = values[index + 1];
if (!key?.startsWith("--") || !value || value.startsWith("--")) {
throw new Error(`无效命令参数:${key ?? ""}`);
}
result.set(key.slice(2), value);
}
return result;
}
function option(
values: Map<string, string>,
name: string,
fallback?: string
) {
const value = values.get(name) ?? fallback;
if (!value) {
throw new Error(`缺少参数 --${name}`);
}
return value;
}
async function main() {
const command = process.argv[2];
const values = argumentsMap(process.argv.slice(3));
if (command === "build") {
return buildFontPack({
recipePath: resolve(
option(
values,
"recipe",
"font-packs/recipes/mdtp-serif-sc/recipe.json"
)
),
sourceRoot: resolve(
option(
values,
"source-root",
".local/font-pack-sources/mdtp-serif-sc/1.0.0"
)
),
outputRoot: resolve(
option(values, "output-root", "output/font-packs/root")
),
reportPath: resolve(
option(values, "report", "output/font-packs/build-report.json")
)
});
}
if (command === "verify") {
return verifyFontPack({
root: resolve(option(values, "root", "output/font-packs/root")),
appVersion: option(values, "app-version", "0.6.0"),
packId: option(values, "pack-id", "mdtp-serif-sc"),
packVersion: option(values, "pack-version", "1.0.0")
});
}
throw new Error("命令必须是 build 或 verify");
}
main()
.then((result) => {
process.stdout.write(`${JSON.stringify(result, null, 2)}\n`);
})
.catch((error: unknown) => {
process.stderr.write(
`${error instanceof Error ? error.stack ?? error.message : String(error)}\n`
);
process.exitCode = 1;
});