Files
platforms/frontend/platform_admin/scripts/check-resource-pages.mjs

50 lines
2.5 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
/**
* 功能:静态检查平台总后台全部标准资源是否具备独立记录页配置。
* 版本v1.0.0
*/
import { readFileSync, existsSync } from 'node:fs';
import { fileURLToPath } from 'node:url';
import { dirname, resolve } from 'node:path';
const root = resolve(dirname(fileURLToPath(import.meta.url)), '..');
const contract = JSON.parse(readFileSync(resolve(root, 'src/contracts/platform-resources.json'), 'utf8'));
const routeSource = [
'platform.ts',
'finance-route.ts',
].map((file) => readFileSync(resolve(root, 'src/router/routes/modules', file), 'utf8')).join('\n');
const routeBuilderSource = readFileSync(resolve(root, 'src/router/routes/modules/resource-route-builder.ts'), 'utf8');
const ruleSource = readFileSync(resolve(root, 'src/api/resource-page-rules.ts'), 'utf8');
const listSource = readFileSync(resolve(root, 'src/views/shared/CrudListPage.vue'), 'utf8');
const treeResources = new Set(['ec_category', 'platform_menu']);
const listResources = contract.resources.filter((item) => !treeResources.has(item.name));
const createModes = new Set(['writable', 'editable', 'append_only', 'managed']);
const editModes = new Set(['writable', 'editable', 'managed']);
const editableResources = listResources.filter((item) => editModes.has(item.mode));
function fail(message) {
throw new Error(`资源独立页面检查失败:${message}`);
}
const missingRoutes = listResources
.filter((item) => !routeSource.includes(`'/${item.name}'`))
.map((item) => item.name);
if (missingRoutes.length) fail(`路由未覆盖 ${missingRoutes.join('、')}`);
const missingRules = editableResources
.filter((item) => !new RegExp(`\\n\\s*${item.name}:\\s*\\{`).test(ruleSource))
.map((item) => item.name);
if (missingRules.length) fail(`编辑字段规则未覆盖 ${missingRules.join('、')}`);
for (const marker of ["makeRecordRoute('create'", "makeRecordRoute('detail'", "makeRecordRoute('edit'"]) {
if (!routeBuilderSource.includes(marker)) fail(`通用路由生成器缺少 ${marker}`);
}
if (listSource.includes('<a-drawer')) fail('列表组件仍包含 CRUD Drawer');
if (existsSync(resolve(root, 'src/views/account/AccountProfilePage.vue'))) {
fail('旧账户资料组件仍存在,未统一到共享记录页');
}
const createCount = listResources.filter((item) => createModes.has(item.mode)).length;
console.log(
`资源独立页面检查通过:详情 ${listResources.length} 类,新建 ${createCount} 类,编辑 ${editableResources.length} 类。`,
);