import { readFileSync } from 'node:fs' import { resolve } from 'node:path' import process from 'node:process' const root = process.cwd() const dataPath = resolve(root, 'src/pages/message/data.ts') const indexPath = resolve(root, 'src/pages/message/index.vue') const source = readFileSync(dataPath, 'utf8') const indexSource = readFileSync(indexPath, 'utf8') const forbiddenWords = ['代理', '未来', '敬请期待', 'agent', 'future'] const forbiddenRoutePatterns = [ /url\s*:/, /path\s*:/, /route\s*:/, /navigateTo/, /switchTab/, /redirectTo/, /reLaunch/, ] for (const word of forbiddenWords) { if (source.includes(word) || indexSource.includes(word)) { throw new Error(`消息页默认内容包含禁用词:${word}`) } } for (const pattern of forbiddenRoutePatterns) { if (source.match(pattern) || indexSource.match(pattern)) { throw new Error(`消息页一级页面不应包含跳转配置或跳转调用:${pattern}`) } } const groupCount = (source.match(/^\s{4}key:\s*'(system|card)',/gm) || []).length if (groupCount !== 2) { throw new Error(`消息页应只保留 2 个用户侧消息分类,当前为 ${groupCount} 个`) } for (const required of ['系统消息', '卡片消息', '端午假期服务时间调整通知', '尾号 8821 流量不足']) { if (!source.includes(required)) { throw new Error(`消息页缺少来自暂存设计的用户侧内容:${required}`) } } console.log('message page scope checked')