feat: 收口多品牌与模板构建基础
This commit is contained in:
1 parent
0425a1c672
commit
77224ea51f
317 files changed
+11290
-1158
No files matched your search
@@ -0,0 +1,3 @@
|
||||
# Template Contract
|
||||
|
||||
模板包是构建期输入。模板必须声明 runtime contract、页面入口、导航、行业兼容性和能力依赖;不得在模板包中实现数据库访问、鉴权或业务状态机。
|
||||
@@ -0,0 +1,12 @@
|
||||
{
|
||||
"name": "@personal-brand/template-contract",
|
||||
"version": "0.1.0",
|
||||
"private": true,
|
||||
"type": "module",
|
||||
"exports": {
|
||||
".": "./src/index.ts"
|
||||
},
|
||||
"scripts": {
|
||||
"typecheck": "tsc -p tsconfig.json --noEmit"
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,66 @@
|
||||
export const TEMPLATE_RUNTIME_CONTRACT = "1.0" as const;
|
||||
|
||||
export type TemplatePageKey =
|
||||
"home" | "offerings" | "detail" | "inquiry" | "success" | "records" | "profile" | (string & {});
|
||||
|
||||
export type TemplateRenderers = Partial<Record<"home" | "offerings" | "profile", string>>;
|
||||
|
||||
export type TemplateRuntimeOwnedPage = "detail" | "inquiry" | "success" | "records";
|
||||
|
||||
export type TemplatePackageManifest = {
|
||||
packageKey: string;
|
||||
version: string;
|
||||
displayName: string;
|
||||
runtimeContract: typeof TEMPLATE_RUNTIME_CONTRACT;
|
||||
supportedIndustryTemplates: string[];
|
||||
entrypoints: Record<string, string>;
|
||||
navigation: Array<{
|
||||
key: string;
|
||||
label: string;
|
||||
page: TemplatePageKey;
|
||||
iconPath?: string;
|
||||
selectedIconPath?: string;
|
||||
}>;
|
||||
requiredCapabilities: string[];
|
||||
renderers?: TemplateRenderers;
|
||||
runtimeOwnedPages?: TemplateRuntimeOwnedPage[];
|
||||
ownedPaths?: string[];
|
||||
};
|
||||
|
||||
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.packageKey?.trim()) errors.push("packageKey is required");
|
||||
if (!manifest.version?.trim()) errors.push("version 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");
|
||||
if (
|
||||
!Array.isArray(manifest.supportedIndustryTemplates) ||
|
||||
!manifest.supportedIndustryTemplates.length
|
||||
)
|
||||
errors.push("supportedIndustryTemplates must not be empty");
|
||||
if (!Array.isArray(manifest.navigation) || !manifest.navigation.length)
|
||||
errors.push("navigation must not be empty");
|
||||
if (manifest.ownedPaths !== undefined && !Array.isArray(manifest.ownedPaths))
|
||||
errors.push("ownedPaths must be an array when provided");
|
||||
if (
|
||||
manifest.renderers !== undefined &&
|
||||
(typeof manifest.renderers !== "object" || Array.isArray(manifest.renderers))
|
||||
)
|
||||
errors.push("renderers must be an object when provided");
|
||||
for (const page of [
|
||||
"home",
|
||||
"offerings",
|
||||
"detail",
|
||||
"inquiry",
|
||||
"success",
|
||||
"records",
|
||||
"profile",
|
||||
] as const) {
|
||||
if (!manifest.entrypoints || typeof manifest.entrypoints[page] !== "string")
|
||||
errors.push(`entrypoints.${page} is required`);
|
||||
}
|
||||
return errors;
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
{
|
||||
"extends": "../../tsconfig.base.json",
|
||||
"compilerOptions": { "rootDir": "src", "outDir": "dist" },
|
||||
"include": ["src/**/*.ts"]
|
||||
}
|
||||
Reference in new issue
Block a user