feat: 增加模板确定性打包命令

This commit is contained in:
que01 committed 2026-10-16 14:01:45 +08:00
1 parent 58370224b5
commit cddf836f4f
4 files changed
+231 -2

No files matched your search

+44
View File
@@ -0,0 +1,44 @@
import assert from "node:assert/strict";
import { execFileSync } from "node:child_process";
import { mkdtempSync, readFileSync, rmSync } from "node:fs";
import path from "node:path";
import { fileURLToPath } from "node:url";
import test from "node:test";
const root = path.resolve(path.dirname(fileURLToPath(import.meta.url)), "..");
const script = path.join(root, "scripts/template-pack.cjs");
const templatePackages = [
["acheng-campus-food", "1.0.0"],
["atelier-solopreneur", "1.1.0"],
["linjing-editorial", "1.0.0"],
];
for (const [packageKey, version] of templatePackages) {
test(`${packageKey} produces a stable package directory and archive`, () => {
const output = mkdtempSync(path.join("/tmp", "personal-brand-template-pack-"));
try {
const args = [script, "--template", packageKey, "--out", output];
const first = execFileSync(process.execPath, args, { cwd: root, encoding: "utf8" });
const firstChecksums = readFileSync(
path.join(output, `${packageKey}-${version}`, "checksums.json"),
"utf8",
);
const firstArchive = readFileSync(path.join(output, `${packageKey}-${version}.tar.gz`));
const second = execFileSync(process.execPath, args, { cwd: root, encoding: "utf8" });
const secondChecksums = readFileSync(
path.join(output, `${packageKey}-${version}`, "checksums.json"),
"utf8",
);
const secondArchive = readFileSync(path.join(output, `${packageKey}-${version}.tar.gz`));
assert.match(first, /content checksum: [a-f0-9]{64}/);
assert.match(second, /content checksum: [a-f0-9]{64}/);
assert.deepEqual(JSON.parse(secondChecksums), JSON.parse(firstChecksums));
assert.deepEqual(secondArchive, firstArchive);
assert.ok(
JSON.parse(firstChecksums).files.every((file) => !file.path.includes("node_modules")),
);
} finally {
rmSync(output, { recursive: true, force: true });
}
});
}