verify-medtech-theme.mjs 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  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 migratedMarkers = [
  24. 'clinical-shell',
  25. 'internal-login',
  26. 'period-workbench',
  27. 'period-status-strip',
  28. 'okr-workbench',
  29. 'team-okr-workbench',
  30. 'review-workbench',
  31. 'scoring-worklist',
  32. 'result-workbench',
  33. 'history-workbench',
  34. 'feedback-workbench',
  35. 'org-workbench',
  36. 'log-workbench',
  37. 'dimension-workbench',
  38. 'template-workbench'
  39. ]
  40. function walk(dir) {
  41. return readdirSync(dir).flatMap((name) => {
  42. const path = join(dir, name)
  43. return statSync(path).isDirectory() ? walk(path) : [path]
  44. })
  45. }
  46. const failures = []
  47. for (const file of requiredFiles) {
  48. try {
  49. readFileSync(join(root, file), 'utf8')
  50. } catch {
  51. failures.push(`missing required style file: ${file}`)
  52. }
  53. }
  54. const themePath = join(root, 'src/styles/theme.css')
  55. let theme = ''
  56. try {
  57. theme = readFileSync(themePath, 'utf8')
  58. } catch {}
  59. for (const token of requiredTokens) {
  60. if (!theme.includes(token)) failures.push(`missing theme token: ${token}`)
  61. }
  62. const main = readFileSync(join(root, 'src/main.js'), 'utf8')
  63. for (const file of requiredFiles) {
  64. const importPath = './' + file.replace('src/', '')
  65. if (!main.includes(importPath)) failures.push(`main.js must import ${importPath}`)
  66. }
  67. const layout = readFileSync(join(root, 'src/components/MainLayout.vue'), 'utf8')
  68. const login = readFileSync(join(root, 'src/views/auth/LoginView.vue'), 'utf8')
  69. const periodList = readFileSync(join(root, 'src/views/period/PeriodListView.vue'), 'utf8')
  70. const periodBanner = readFileSync(join(root, 'src/components/PeriodBanner.vue'), 'utf8')
  71. const myOkr = readFileSync(join(root, 'src/views/okr/MyOkrView.vue'), 'utf8')
  72. const teamOkr = readFileSync(join(root, 'src/views/okr/TeamOkrView.vue'), 'utf8')
  73. const scoringEdit = readFileSync(join(root, 'src/views/scoring/ScoringEditView.vue'), 'utf8')
  74. const scoringList = readFileSync(join(root, 'src/views/scoring/ScoringListView.vue'), 'utf8')
  75. if (!layout.includes('clinical-shell')) failures.push('MainLayout must use clinical-shell')
  76. if (!layout.includes('clinical-sidebar')) failures.push('MainLayout must use clinical-sidebar')
  77. if (!login.includes('internal-login')) failures.push('LoginView must use internal-login')
  78. if (login.includes('radial-gradient')) failures.push('LoginView must not use radial-gradient')
  79. if (!periodList.includes('period-workbench')) failures.push('PeriodListView must use period-workbench')
  80. if (!periodList.includes('period-metrics')) failures.push('PeriodListView must show period-metrics')
  81. if (!periodBanner.includes('period-status-strip')) failures.push('PeriodBanner must use period-status-strip')
  82. if (!myOkr.includes('okr-workbench')) failures.push('MyOkrView must use okr-workbench')
  83. if (!myOkr.includes('okr-standard-panel')) failures.push('MyOkrView must use okr-standard-panel')
  84. if (!teamOkr.includes('team-okr-workbench')) failures.push('TeamOkrView must use team-okr-workbench')
  85. if (!scoringEdit.includes('review-workbench')) failures.push('ScoringEditView must use review-workbench')
  86. if (!scoringEdit.includes('evidence-panel')) failures.push('ScoringEditView must use evidence-panel')
  87. if (!scoringEdit.includes('decision-panel')) failures.push('ScoringEditView must use decision-panel')
  88. if (!scoringList.includes('scoring-worklist')) failures.push('ScoringListView must use scoring-worklist')
  89. const requiredClasses = new Map([
  90. ['src/views/scoring/MyResultView.vue', 'result-workbench'],
  91. ['src/views/scoring/HistoryView.vue', 'history-workbench'],
  92. ['src/views/feedback/FeedbackView.vue', 'feedback-workbench'],
  93. ['src/views/org/OrgView.vue', 'org-workbench'],
  94. ['src/views/system/LogView.vue', 'log-workbench'],
  95. ['src/views/system/DimensionConfigView.vue', 'dimension-workbench'],
  96. ['src/views/period/KpiTemplateView.vue', 'template-workbench']
  97. ])
  98. for (const [file, className] of requiredClasses) {
  99. const text = readFileSync(join(root, file), 'utf8')
  100. if (!text.includes(className)) failures.push(`${file} must use ${className}`)
  101. }
  102. const vueAndCssFiles = walk(src).filter((file) => /\.(vue|css)$/.test(file))
  103. for (const file of vueAndCssFiles) {
  104. const text = readFileSync(file, 'utf8')
  105. const rel = relative(root, file)
  106. const mustFollowMedtechRules = rel.startsWith('src/styles/') || migratedMarkers.some((marker) => text.includes(marker))
  107. if (mustFollowMedtechRules && bannedEmoji.test(text)) failures.push(`banned emoji in ${rel}`)
  108. if (mustFollowMedtechRules && bannedDecor.test(text)) failures.push(`banned decorative style in ${rel}`)
  109. }
  110. if (failures.length) {
  111. console.error(failures.join('\n'))
  112. process.exit(1)
  113. }
  114. console.log('medtech theme checks passed')