Files
venue-miniapp/miniprogram/scripts/verify-home-venue-switch.mjs

48 lines
2.1 KiB
JavaScript

import { existsSync, readFileSync } from 'node:fs'
import { fileURLToPath } from 'node:url'
import { dirname, resolve } from 'node:path'
const root = resolve(dirname(fileURLToPath(import.meta.url)), '..')
const srcRoot = resolve(root, 'src')
const failures = []
const read = (relativePath) => readFileSync(resolve(srcRoot, relativePath), 'utf8')
const expectFile = (relativePath) => {
const fullPath = resolve(srcRoot, relativePath)
if (!existsSync(fullPath)) failures.push(`Missing file: ${relativePath}`)
}
const expectIncludes = (content, expected, label) => {
if (!content.includes(expected)) failures.push(`${label} is missing: ${expected}`)
}
expectFile('components/VenueSwitchHeader.vue')
if (existsSync(resolve(srcRoot, 'components/VenueSwitchHeader.vue'))) {
const component = read('components/VenueSwitchHeader.vue')
expectIncludes(component, "uni.navigateTo({ url: '/pages/venue-select/index?mode=switch' })", 'VenueSwitchHeader switch navigation')
expectIncludes(component, 'class="venue-switch-header"', 'VenueSwitchHeader layout root')
expectIncludes(component, 'class="venue-switch-action"', 'VenueSwitchHeader action')
expectIncludes(component, '<text class="venue-switch-action__text">切换场馆</text>', 'VenueSwitchHeader action text')
expectIncludes(component, '<view class="venue-switch-action__arrow" />', 'VenueSwitchHeader css arrow')
}
const homePages = [
{ file: 'pages/ice/home/index.vue', venue: '冰场馆' },
{ file: 'pages/comprehensive/home/index.vue', venue: '综合场馆' }
]
for (const { file, venue } of homePages) {
const content = read(file)
expectIncludes(content, '<VenueSwitchHeader', `${file} template`)
expectIncludes(content, `venue-name="${venue}"`, `${file} venue name`)
expectIncludes(content, "import VenueSwitchHeader from '@/components/VenueSwitchHeader.vue'", `${file} imports`)
}
if (failures.length) {
console.error(`Home venue switch verification failed with ${failures.length} issue(s):`)
for (const failure of failures) console.error(`- ${failure}`)
process.exit(1)
}
console.log('Home venue switch verification passed.')