feat: add platform resource audit baseline
This commit is contained in:
@@ -11,6 +11,7 @@
|
||||
"report": "vite build --config ./config/vite.config.ts --mode report",
|
||||
"preview": "pnpm run build && vite preview --host",
|
||||
"type:check": "vue-tsc -p tsconfig.build.json --noEmit --skipLibCheck",
|
||||
"audit:platform": "node scripts/audit-check.mjs",
|
||||
"lint": "biome check .",
|
||||
"lint:fix": "biome check --write .",
|
||||
"format": "biome format --write ."
|
||||
|
||||
@@ -1,6 +1,38 @@
|
||||
import fs from 'node:fs';
|
||||
import path from 'node:path';
|
||||
|
||||
const baseline = process.argv.includes('--baseline');
|
||||
|
||||
const expectedResources = [
|
||||
['gas', 'gas_basic', 'list'], ['gas', 'gas_account', 'list'],
|
||||
['delivery', 'delivery_basic', 'list'], ['delivery', 'delivery_account', 'list'], ['delivery', 'delivery_task', 'list'], ['delivery', 'delivery_track', 'list'], ['delivery', 'delivery_track_point', 'list'],
|
||||
['staff', 'staff_account', 'list'], ['staff', 'staff_credential', 'list'],
|
||||
['user', 'user_account', 'list'], ['user', 'user_address', 'list'], ['user', 'user_service_relation', 'list'],
|
||||
['device', 'dev_smart_cylinder_valve', 'list'], ['device', 'dev_device_binding', 'list'], ['device', 'dev_telemetry', 'list'], ['device', 'saf_rule', 'list'], ['device', 'saf_event', 'list'], ['device', 'saf_event_disposal', 'list'], ['device', 'saf_inspection', 'list'],
|
||||
['commerce', 'ec_category', 'list'], ['commerce', 'ec_product', 'list'], ['commerce', 'ec_product_attribute', 'list'], ['commerce', 'ec_product_image', 'list'], ['commerce', 'ec_cart', 'list'], ['commerce', 'ec_order', 'list'], ['commerce', 'ec_review', 'list'],
|
||||
['finance', 'fin_payment', 'list'], ['finance', 'fin_settlement', 'list'], ['finance', 'fin_reconciliation', 'list'],
|
||||
['content', 'cnt_content', 'list'], ['notification', 'ntf_template', 'list'], ['customer_service', 'cs_ticket', 'list'],
|
||||
['platform', 'platfrom_account', 'list'], ['platform', 'platform_role', 'list'], ['platform', 'platform_menu', 'tree'],
|
||||
['wallet', 'wallet', 'list'], ['wallet', 'wallet_ledger', 'list'], ['wallet', 'wallet_recharge', 'list'], ['wallet', 'wallet_withdrawal', 'list'],
|
||||
['report', 'report', 'list'], ['report', 'report_item', 'list'], ['report', 'report_metric_snapshot', 'list'],
|
||||
['audit', 'aud_operation_log', 'list'], ['audit', 'aud_export_log', 'list'], ['audit', 'aud_approval', 'list'],
|
||||
];
|
||||
|
||||
function fileIncludes(file, value) {
|
||||
return fs.existsSync(file) && fs.readFileSync(file, 'utf8').includes(value);
|
||||
}
|
||||
|
||||
function checkResourceLayers() {
|
||||
const missing = [];
|
||||
for (const [domain, name, pageKind] of expectedResources) {
|
||||
if (!fileIncludes('src/api/resources.ts', name)) missing.push(`${domain}/${name}: missing api`);
|
||||
if (!fileIncludes(path.join('src/router/routes/modules', `${domain}.ts`), name)) missing.push(`${domain}/${name}: missing route`);
|
||||
const page = pageKind === 'tree' ? 'TreePage.vue' : 'ListPage.vue';
|
||||
if (!fs.existsSync(path.join('src/views', domain, name, page))) missing.push(`${domain}/${name}: missing view`);
|
||||
}
|
||||
return missing;
|
||||
}
|
||||
|
||||
function walk(dir, acc = []) {
|
||||
for (const entry of fs.readdirSync(dir, { withFileTypes: true })) {
|
||||
const full = path.join(dir, entry.name);
|
||||
@@ -49,3 +81,10 @@ console.log(JSON.stringify({
|
||||
settingsHttp: fs.readFileSync('src/locale/zh-CN/settings.ts', 'utf8').includes('http.logout.title'),
|
||||
rootMenu: fs.readFileSync('src/locale/zh-CN.ts', 'utf8').includes('仪表盘'),
|
||||
}, null, 2));
|
||||
|
||||
const missingLayers = checkResourceLayers();
|
||||
for (const missing of missingLayers) console.log(missing);
|
||||
|
||||
if (missingLayers.length > 0 && !baseline) {
|
||||
process.exitCode = 1;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user