2026-08-11 00:49:41 +08:00
|
|
|
|
/**
|
|
|
|
|
|
* 功能:静态检查平台总后台全部标准资源是否具备独立记录页配置。
|
2026-08-11 22:38:20 +08:00
|
|
|
|
* 版本:v1.1.0
|
2026-08-11 00:49:41 +08:00
|
|
|
|
*/
|
|
|
|
|
|
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');
|
2026-08-11 22:38:20 +08:00
|
|
|
|
if (
|
|
|
|
|
|
!listSource.includes(
|
|
|
|
|
|
'[() => props.definition.resource, () => staffType.value]',
|
|
|
|
|
|
)
|
|
|
|
|
|
) {
|
|
|
|
|
|
fail('工作人员角色菜单切换未触发列表重新加载');
|
|
|
|
|
|
}
|
2026-08-11 00:49:41 +08:00
|
|
|
|
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} 类。`,
|
|
|
|
|
|
);
|