feat: 完善字体包发行与 Docker 内置字体
This commit is contained in:
@@ -0,0 +1,54 @@
|
||||
import { mkdtemp, mkdir, readFile, rm, writeFile } from "node:fs/promises";
|
||||
import { tmpdir } from "node:os";
|
||||
import { join } from "node:path";
|
||||
import { unzipSync } from "fflate";
|
||||
import { afterEach, describe, expect, it } from "vitest";
|
||||
import {
|
||||
createDeterministicFontPackArchive,
|
||||
fontPackArchiveName
|
||||
} from "../src/index.js";
|
||||
|
||||
const temporaryDirectories: string[] = [];
|
||||
|
||||
afterEach(async () => {
|
||||
await Promise.all(
|
||||
temporaryDirectories.splice(0).map((directory) =>
|
||||
rm(directory, { recursive: true, force: true })
|
||||
)
|
||||
);
|
||||
});
|
||||
|
||||
describe("字体包 ZIP 发行附件", () => {
|
||||
it("使用 MorphDoc 品牌和稳定文件名", () => {
|
||||
expect(fontPackArchiveName("mdtp-serif-sc", "1.0.0")).toBe(
|
||||
"MorphDoc-FontPack-mdtp-serif-sc-1.0.0.zip"
|
||||
);
|
||||
});
|
||||
|
||||
it("生成可复现且可直接解压到字体包根目录的归档", async () => {
|
||||
const root = await mkdtemp(join(tmpdir(), "morphdoc-font-archive-"));
|
||||
temporaryDirectories.push(root);
|
||||
await mkdir(join(root, "fonts"), { recursive: true });
|
||||
await Promise.all([
|
||||
writeFile(join(root, "font-pack.json"), "{}\n", "utf8"),
|
||||
writeFile(join(root, "fonts", "Regular.ttf"), new Uint8Array([1, 2, 3]))
|
||||
]);
|
||||
|
||||
const first = await createDeterministicFontPackArchive(
|
||||
root,
|
||||
"mdtp-serif-sc/1.0.0"
|
||||
);
|
||||
const second = await createDeterministicFontPackArchive(
|
||||
root,
|
||||
"mdtp-serif-sc/1.0.0"
|
||||
);
|
||||
expect(first.content).toEqual(second.content);
|
||||
expect(first.entries).toEqual([
|
||||
"mdtp-serif-sc/1.0.0/font-pack.json",
|
||||
"mdtp-serif-sc/1.0.0/fonts/Regular.ttf"
|
||||
]);
|
||||
const entries = unzipSync(first.content);
|
||||
expect(new TextDecoder().decode(entries[first.entries[0]!])).toBe("{}\n");
|
||||
expect(entries[first.entries[1]!]).toEqual(new Uint8Array([1, 2, 3]));
|
||||
});
|
||||
});
|
||||
@@ -41,7 +41,7 @@ describe("Windows 字体包安装器构建", () => {
|
||||
|
||||
it("生成稳定发行文件名和完整 NSIS 定义", () => {
|
||||
expect(windowsFontPackInstallerName("mdtp-serif-sc", "1.0.0")).toBe(
|
||||
"md-to-pdf-font-pack-mdtp-serif-sc-1.0.0-x86_64-Setup.exe"
|
||||
"MorphDoc-FontPack-mdtp-serif-sc-1.0.0-x86_64-Setup.exe"
|
||||
);
|
||||
const args = createWindowsFontPackInstallerArguments({
|
||||
packDirectory: "C:/pack",
|
||||
|
||||
Reference in New Issue
Block a user