feat(platform-admin): align frontend with backend contracts

This commit is contained in:
david
2026-07-28 14:26:09 +08:00
parent bc8138f978
commit 4cc17c9efb
6 changed files with 438 additions and 68 deletions

View File

@@ -9,7 +9,10 @@ const contract = JSON.parse(
readFileSync(resolve(root, 'src/contracts/platform-resources.json'), 'utf8'),
);
const backend = new Map(contract.resources.map((item) => [item.name, item]));
const frontendNames = [...source.matchAll(/define\('([^']+)'/g)].map((match) => match[1]);
const frontendDefinitions = [
...source.matchAll(/define\('([^']+)',\s*'[^']+',\s*'([^']+)'/g),
].map((match) => ({ name: match[1], mode: match[2] }));
const frontendNames = frontendDefinitions.map((item) => item.name);
for (const name of frontendNames) {
const item = backend.get(name);
@@ -19,6 +22,15 @@ for (const name of frontendNames) {
for (const item of contract.resources) {
if (!frontendNames.includes(item.name))
throw new Error(`缺少后端资源配置:${item.name}`);
const frontend = frontendDefinitions.find(
(definition) => definition.name === item.name,
);
if (frontend?.mode !== item.mode)
throw new Error(
`资源模式不一致:${item.name},后端=${item.mode},前端=${frontend?.mode}`,
);
if (!routes.includes(`'/${item.name}'`))
throw new Error(`缺少后端资源路由:${item.name}`);
}
const forbidden = [