Files
CN_Tool_client/frontend/src/views/steady/steadyDataView/contracts/check-route-contract.mjs

35 lines
1.8 KiB
JavaScript
Raw Normal View History

2026-05-15 16:36:50 +08:00
/* eslint-env node */
import fs from 'node:fs'
import path from 'node:path'
import { fileURLToPath } from 'node:url'
const currentDir = path.dirname(fileURLToPath(import.meta.url))
const srcRoot = path.resolve(currentDir, '../../../..')
2026-05-15 16:36:50 +08:00
const staticRouter = fs.readFileSync(path.join(srcRoot, 'routers/modules/staticRouter.ts'), 'utf8')
const dynamicRouter = fs.readFileSync(path.join(srcRoot, 'routers/modules/dynamicRouter.ts'), 'utf8')
const authStore = fs.readFileSync(path.join(srcRoot, 'stores/modules/auth.ts'), 'utf8')
const expectations = [
['static router registers /steadyDataView/index', /path:\s*'\/steadyDataView\/index'/],
['static route name is steadyDataView', /name:\s*'steadyDataView'/],
['static router imports steadyDataView page', /@\/views\/steady\/steadyDataView\/index\.vue/],
['dynamic router aliases steady-data-view to steadyDataView', /\/steady\/steady-data-view[\s\S]*\/steady\/steadyDataView/],
['dynamic router keeps steadyDataView static route from being overwritten', /STATIC_ROUTE_NAMES[\s\S]*'steadyDataView'/],
['auth normalizes backend steady menu to static steadyDataView entry', /isSteadyDataViewMenu[\s\S]*menu\.path\s*=\s*'\/steadyDataView\/index'/],
['business menu path resolver handles steadyDataView', /isSteadyDataViewMenu\(menu\)\s*\?\s*'\/steadyDataView\/index'/]
]
const sourceByExpectation = [staticRouter, staticRouter, staticRouter, dynamicRouter, dynamicRouter, authStore, authStore]
const failures = expectations.filter(([, pattern], index) => !pattern.test(sourceByExpectation[index]))
if (failures.length) {
console.error('steadyDataView route contract failed:')
for (const [name] of failures) {
console.error(`- ${name}`)
}
process.exit(1)
}
console.log('steadyDataView route contract passed')