feat: 分离模板演示数据并校验预览资源
This commit is contained in:
1 parent
6edde5a8d6
commit
b60174885e
31 files changed
+1785
-69
No files matched your search
@@ -6,6 +6,9 @@
|
||||
"exports": {
|
||||
".": "./src/index.ts"
|
||||
},
|
||||
"dependencies": {
|
||||
"@personal-brand/validation": "workspace:^"
|
||||
},
|
||||
"scripts": {
|
||||
"typecheck": "tsc -p tsconfig.json --noEmit",
|
||||
"test": "node --experimental-strip-types --test test/*.test.mjs"
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
import { validateTemplatePreviewFixtures } from "@personal-brand/validation";
|
||||
|
||||
export const TEMPLATE_RUNTIME_CONTRACT = "1.0" as const;
|
||||
|
||||
export type TemplatePageKey =
|
||||
@@ -158,12 +160,20 @@ export type TemplatePackageManifest = {
|
||||
admin: TemplateAdminManifest;
|
||||
trustContentTypes?: TemplateTrustContentType[];
|
||||
sampleContent?: Record<string, TemplateSampleContent>;
|
||||
previewFixture?: Record<string, unknown>;
|
||||
};
|
||||
|
||||
export function validateTemplatePackageManifest(value: unknown): string[] {
|
||||
const errors: string[] = [];
|
||||
if (!value || typeof value !== "object") return ["manifest must be an object"];
|
||||
const manifest = value as Partial<TemplatePackageManifest>;
|
||||
if (manifest.previewFixture !== undefined) {
|
||||
for (const issue of validateTemplatePreviewFixtures(
|
||||
manifest.previewFixture,
|
||||
manifest.supportedIndustryTemplates ?? [],
|
||||
))
|
||||
errors.push(`previewFixture.${issue.path}: ${issue.message}`);
|
||||
}
|
||||
if (!manifest.packageKey?.trim()) errors.push("packageKey is required");
|
||||
if (!manifest.version?.trim()) errors.push("version is required");
|
||||
if (manifest.runtimeContract !== TEMPLATE_RUNTIME_CONTRACT)
|
||||
|
||||
@@ -8,6 +8,45 @@ import { runtimeContractForBinding } from "../../types/src/runtime-content-contr
|
||||
|
||||
const packageRoot = path.resolve(path.dirname(fileURLToPath(import.meta.url)), "../..");
|
||||
|
||||
test("independent preview fixtures validate safety and industry without changing bootstrap content", () => {
|
||||
const manifest = JSON.parse(
|
||||
fs.readFileSync(path.join(packageRoot, "template-atelier-solopreneur/template.json"), "utf8"),
|
||||
);
|
||||
assert.deepEqual(validateTemplatePackageManifest(manifest), []);
|
||||
assert.notEqual(
|
||||
manifest.previewFixture.personal.content.brandConfig.founder,
|
||||
manifest.sampleContent.personal.brandConfig.founder,
|
||||
);
|
||||
for (const mutate of [
|
||||
(value) => {
|
||||
value.previewFixture.personal.safety.submissions = "enabled";
|
||||
},
|
||||
(value) => {
|
||||
value.previewFixture.personal.brand.contactPhone = "13800000000";
|
||||
},
|
||||
(value) => {
|
||||
value.previewFixture.personal.content.fields = [null];
|
||||
},
|
||||
(value) => {
|
||||
value.previewFixture.personal.content.templateKey = "food";
|
||||
},
|
||||
(value) => {
|
||||
value.previewFixture = [];
|
||||
},
|
||||
(value) => {
|
||||
value.previewFixture.personal = null;
|
||||
},
|
||||
]) {
|
||||
const invalid = structuredClone(manifest);
|
||||
mutate(invalid);
|
||||
assert.ok(
|
||||
validateTemplatePackageManifest(invalid).some((message) =>
|
||||
message.startsWith("previewFixture"),
|
||||
),
|
||||
);
|
||||
}
|
||||
});
|
||||
|
||||
for (const key of ["acheng-campus-food", "linjing-editorial"]) {
|
||||
test(`${key} declares valid admin content and asset requirements`, () => {
|
||||
const manifestPath = path.join(packageRoot, `template-${key}`, "template.json");
|
||||
|
||||
Reference in new issue
Block a user