verify-medtech-theme.mjs 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178
  1. import { readFileSync, readdirSync, statSync } from 'node:fs'
  2. import { join, relative } from 'node:path'
  3. const root = new URL('..', import.meta.url).pathname
  4. const src = join(root, 'src')
  5. const requiredFiles = [
  6. 'src/styles/theme.css',
  7. 'src/styles/components.css',
  8. 'src/styles/element-plus.css'
  9. ]
  10. const requiredTokens = [
  11. '--color-brand: #2b1f99',
  12. '--color-accent: #3ad4d8',
  13. '--color-bg:',
  14. '--color-surface:',
  15. '--color-border:',
  16. '--color-text:',
  17. '--radius-xs: 4px',
  18. '--radius-sm: 6px',
  19. '--radius-md: 8px'
  20. ]
  21. const bannedEmoji = /[📋📌⚡⏳✅❌🎯🚀💡🔥💬]/u
  22. const bannedDecor = /(radial-gradient|gradient orb|bokeh|blur\(60px\)|border-radius:\s*(1[2-9]|[2-9]\d)px)/
  23. const bannedTextIcon = /[←→↑↓]/
  24. const rawHexColor = /#[0-9a-fA-F]{3,8}\b/
  25. const bannedLegacyPatterns = [
  26. { re: /page-hero/, msg: '禁止 page-hero(改用 data-toolbar)' },
  27. { re: /section-badge/, msg: '禁止 section-badge 胶囊徽章' },
  28. { re: /grade-ring/, msg: '禁止 grade-ring 圆环' },
  29. { re: /score-hero/, msg: '禁止 score-hero 渐变区' },
  30. { re: /hint-card/, msg: '禁止 hint-card 大引导卡' },
  31. { re: /conic-gradient/, msg: '禁止 conic-gradient' }
  32. ]
  33. const migratedMarkers = [
  34. 'clinical-shell',
  35. 'internal-login',
  36. 'period-workbench',
  37. 'period-status-strip',
  38. 'okr-workbench',
  39. 'alignment-workbench',
  40. 'team-okr-workbench',
  41. 'notification-workbench',
  42. 'review-workbench',
  43. 'scoring-worklist',
  44. 'result-workbench',
  45. 'history-workbench',
  46. 'feedback-workbench',
  47. 'org-workbench',
  48. 'log-workbench',
  49. 'dimension-workbench',
  50. 'template-workbench'
  51. ]
  52. function walk(dir) {
  53. return readdirSync(dir).flatMap((name) => {
  54. const path = join(dir, name)
  55. return statSync(path).isDirectory() ? walk(path) : [path]
  56. })
  57. }
  58. const failures = []
  59. for (const file of requiredFiles) {
  60. try {
  61. readFileSync(join(root, file), 'utf8')
  62. } catch {
  63. failures.push(`missing required style file: ${file}`)
  64. }
  65. }
  66. const themePath = join(root, 'src/styles/theme.css')
  67. let theme = ''
  68. try {
  69. theme = readFileSync(themePath, 'utf8')
  70. } catch {}
  71. for (const token of requiredTokens) {
  72. if (!theme.includes(token)) failures.push(`missing theme token: ${token}`)
  73. }
  74. const main = readFileSync(join(root, 'src/main.js'), 'utf8')
  75. for (const file of requiredFiles) {
  76. const importPath = './' + file.replace('src/', '')
  77. if (!main.includes(importPath)) failures.push(`main.js must import ${importPath}`)
  78. }
  79. const layout = readFileSync(join(root, 'src/components/MainLayout.vue'), 'utf8')
  80. const login = readFileSync(join(root, 'src/views/auth/LoginView.vue'), 'utf8')
  81. const periodList = readFileSync(join(root, 'src/views/period/PeriodListView.vue'), 'utf8')
  82. const periodBanner = readFileSync(join(root, 'src/components/PeriodBanner.vue'), 'utf8')
  83. const myOkr = readFileSync(join(root, 'src/views/okr/MyOkrView.vue'), 'utf8')
  84. const teamOkr = readFileSync(join(root, 'src/views/okr/TeamOkrView.vue'), 'utf8')
  85. const scoringEdit = readFileSync(join(root, 'src/views/scoring/ScoringEditView.vue'), 'utf8')
  86. const scoringList = readFileSync(join(root, 'src/views/scoring/ScoringListView.vue'), 'utf8')
  87. const myResult = readFileSync(join(root, 'src/views/scoring/MyResultView.vue'), 'utf8')
  88. if (!layout.includes('clinical-shell')) failures.push('MainLayout must use clinical-shell')
  89. if (!layout.includes('clinical-sidebar')) failures.push('MainLayout must use clinical-sidebar')
  90. if (!login.includes('internal-login')) failures.push('LoginView must use internal-login')
  91. if (login.includes('radial-gradient')) failures.push('LoginView must not use radial-gradient')
  92. if (!periodList.includes('period-workbench')) failures.push('PeriodListView must use period-workbench')
  93. if (!periodList.includes('period-metrics')) failures.push('PeriodListView must show period-metrics')
  94. if (!periodBanner.includes('period-status-strip')) failures.push('PeriodBanner must use period-status-strip')
  95. if (!myOkr.includes('okr-workbench')) failures.push('MyOkrView must use okr-workbench')
  96. if (!teamOkr.includes('team-okr-workbench')) failures.push('TeamOkrView must use team-okr-workbench')
  97. if (!teamOkr.includes('@update:model-value="selectPeriod"')) failures.push('TeamOkrView period switch must reload subordinate OKRs')
  98. if (!scoringEdit.includes('review-workbench')) failures.push('ScoringEditView must use review-workbench')
  99. if (!scoringList.includes('scoring-worklist')) failures.push('ScoringListView must use scoring-worklist')
  100. // v2 信息架构断言
  101. if (!myOkr.includes('data-toolbar')) failures.push('MyOkrView must use data-toolbar (replaced page-hero)')
  102. if (!myOkr.includes('data-table')) failures.push('MyOkrView must use data-table (table-based O/KR)')
  103. if (!myOkr.includes('side-drawer__content') && !myOkr.includes('el-drawer')) {
  104. failures.push('MyOkrView must use side drawer for KR detail/progress')
  105. }
  106. if (!scoringEdit.includes('compare-grid-3')) failures.push('ScoringEditView must use compare-grid-3 (3-column comparison)')
  107. if (!scoringEdit.includes('section-band')) failures.push('ScoringEditView must use section-band')
  108. if (!scoringEdit.includes('review-summary-bar')) failures.push('ScoringEditView must use review-summary-bar')
  109. if (!myResult.includes('metric-bar')) failures.push('MyResultView must use metric-bar (replaced grade-ring)')
  110. if (!myResult.includes('history-trend')) failures.push('MyResultView must use history-trend')
  111. if (myResult.includes('conic-gradient')) failures.push('MyResultView must not use conic-gradient (grade-ring removed)')
  112. if (!login.includes('underline-input')) failures.push('LoginView must use underline-input')
  113. if (!login.includes('login-brand')) failures.push('LoginView must use login-brand (full-screen split)')
  114. const v2LegacyCheckFiles = new Map([
  115. ['src/components/MainLayout.vue', layout],
  116. ['src/views/auth/LoginView.vue', login],
  117. ['src/views/okr/MyOkrView.vue', myOkr],
  118. ['src/views/scoring/ScoringEditView.vue', scoringEdit],
  119. ['src/views/scoring/MyResultView.vue', myResult]
  120. ])
  121. for (const [file, text] of v2LegacyCheckFiles) {
  122. for (const { re, msg } of bannedLegacyPatterns) {
  123. if (re.test(text)) failures.push(`${file}: ${msg}`)
  124. }
  125. }
  126. const requiredClasses = new Map([
  127. ['src/views/scoring/MyResultView.vue', 'result-workbench'],
  128. ['src/views/scoring/HistoryView.vue', 'history-workbench'],
  129. ['src/views/feedback/FeedbackView.vue', 'feedback-workbench'],
  130. ['src/views/org/OrgView.vue', 'org-workbench'],
  131. ['src/views/system/LogView.vue', 'log-workbench'],
  132. ['src/views/system/DimensionConfigView.vue', 'dimension-workbench'],
  133. ['src/views/period/KpiTemplateView.vue', 'template-workbench'],
  134. ['src/views/okr/AlignmentView.vue', 'alignment-workbench'],
  135. ['src/views/notification/NotificationView.vue', 'notification-workbench']
  136. ])
  137. for (const [file, className] of requiredClasses) {
  138. const text = readFileSync(join(root, file), 'utf8')
  139. if (!text.includes(className)) failures.push(`${file} must use ${className}`)
  140. }
  141. const vueAndCssFiles = walk(src).filter((file) => /\.(vue|css)$/.test(file))
  142. for (const file of vueAndCssFiles) {
  143. const text = readFileSync(file, 'utf8')
  144. const rel = relative(root, file)
  145. const mustFollowMedtechRules = rel.startsWith('src/styles/') || migratedMarkers.some((marker) => text.includes(marker))
  146. if (mustFollowMedtechRules && bannedEmoji.test(text)) failures.push(`banned emoji in ${rel}`)
  147. if (mustFollowMedtechRules && bannedDecor.test(text)) failures.push(`banned decorative style in ${rel}`)
  148. if (mustFollowMedtechRules && rel !== 'src/styles/theme.css' && rawHexColor.test(text)) failures.push(`raw hex color in migrated file: ${rel}`)
  149. if (mustFollowMedtechRules && bannedTextIcon.test(text)) failures.push(`text arrow used as icon in ${rel}`)
  150. }
  151. if (failures.length) {
  152. console.error(failures.join('\n'))
  153. process.exit(1)
  154. }
  155. console.log('medtech theme checks passed')