refactor: 统一模板契约并修复预览版本
This commit is contained in:
1 parent
cd2992c00a
commit
50b87e48de
56 files changed
+7849
-5756
No files matched your search
@@ -137,6 +137,7 @@ export type TemplatePackageManifest = {
|
||||
packageKey: string;
|
||||
version: string;
|
||||
displayName: string;
|
||||
visualTemplateKey: string;
|
||||
runtimeContract: typeof TEMPLATE_RUNTIME_CONTRACT;
|
||||
supportedIndustryTemplates: string[];
|
||||
entrypoints: Record<string, string>;
|
||||
@@ -160,22 +161,21 @@ export type TemplatePackageManifest = {
|
||||
admin: TemplateAdminManifest;
|
||||
trustContentTypes?: TemplateTrustContentType[];
|
||||
sampleContent?: Record<string, TemplateSampleContent>;
|
||||
previewFixture?: Record<string, unknown>;
|
||||
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}`);
|
||||
}
|
||||
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.visualTemplateKey?.trim()) errors.push("visualTemplateKey is required");
|
||||
if (manifest.runtimeContract !== TEMPLATE_RUNTIME_CONTRACT)
|
||||
errors.push(`runtimeContract must be ${TEMPLATE_RUNTIME_CONTRACT}`);
|
||||
if (!manifest.displayName?.trim()) errors.push("displayName is required");
|
||||
|
||||
@@ -58,6 +58,14 @@ for (const key of ["acheng-campus-food", "linjing-editorial"]) {
|
||||
test("template contract rejects technical or incomplete admin declarations", () => {
|
||||
const manifestPath = path.join(packageRoot, "template-acheng-campus-food/template.json");
|
||||
const manifest = JSON.parse(fs.readFileSync(manifestPath, "utf8"));
|
||||
const previewFixture = structuredClone(manifest.previewFixture);
|
||||
delete manifest.previewFixture;
|
||||
assert.ok(
|
||||
validateTemplatePackageManifest(manifest).some((message) =>
|
||||
message.startsWith("previewFixture"),
|
||||
),
|
||||
);
|
||||
manifest.previewFixture = previewFixture;
|
||||
manifest.admin.sections[0].fields[0].label = "";
|
||||
manifest.assetSlots[0].help = "";
|
||||
assert.deepEqual(validateTemplatePackageManifest(manifest), [
|
||||
|
||||
Reference in new issue
Block a user