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

54 lines
2.3 KiB
JavaScript
Raw Normal View History

import fs from 'node:fs'
import path from 'node:path'
import { fileURLToPath } from 'node:url'
const currentDir = path.dirname(fileURLToPath(import.meta.url))
const rootDir = path.resolve(currentDir, '../../../..')
const files = {
staticRouter: path.resolve(rootDir, 'routers/modules/staticRouter.ts'),
dynamicRouter: path.resolve(rootDir, 'routers/modules/dynamicRouter.ts'),
authStore: path.resolve(rootDir, 'stores/modules/auth.ts'),
page: path.resolve(rootDir, 'views/steady/steadyTrend/index.vue'),
api: path.resolve(rootDir, 'api/steady/steadyTrend/index.ts'),
apiInterface: path.resolve(rootDir, 'api/steady/steadyTrend/interface/index.ts')
}
const read = file => fs.readFileSync(file, 'utf8')
const exists = file => fs.existsSync(file)
const checks = [
['steadyTrend page exists', () => exists(files.page)],
['steadyTrend API exists', () => exists(files.api)],
['steadyTrend API interface exists', () => exists(files.apiInterface)],
['static router registers /steadyTrend/index', () => /path:\s*'\/steadyTrend\/index'/.test(read(files.staticRouter))],
['static route name is steadyTrend', () => /name:\s*'steadyTrend'/.test(read(files.staticRouter))],
['static router imports steadyTrend page', () => /@\/views\/steady\/steadyTrend\/index\.vue/.test(read(files.staticRouter))],
[
'dynamic router aliases steady-trend to steadyTrend',
() => /\/steady\/steady-trend[\s\S]*\/steady\/steadyTrend/.test(read(files.dynamicRouter))
],
[
'dynamic router keeps steadyTrend static route from being overwritten',
() => /STATIC_ROUTE_NAMES[\s\S]*'steadyTrend'/.test(read(files.dynamicRouter))
],
[
'auth normalizes backend steadyTrend menu to static entry',
() => /isSteadyTrendMenu[\s\S]*menu\.path\s*=\s*'\/steadyTrend\/index'/.test(read(files.authStore))
],
[
'business menu path resolver handles steadyTrend',
() => /isSteadyTrendMenu\(menu\)[\s\S]*return\s+'\/steadyTrend\/index'/.test(read(files.authStore))
]
]
const failures = checks.filter(([, check]) => !check()).map(([name]) => name)
if (failures.length) {
console.error('steadyTrend route contract failed:')
failures.forEach(name => console.error(`- ${name}`))
process.exit(1)
}
console.log('steadyTrend route contract passed')