verify-medtech-theme.mjs 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  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 = /[📋📌⚡⏳✅❌🎯🚀💡🔥]/
  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 vueAndCssFiles = walk(src).filter((file) => /\.(vue|css)$/.test(file))
  68. for (const file of vueAndCssFiles) {
  69. const text = readFileSync(file, 'utf8')
  70. const rel = relative(root, file)
  71. const mustFollowMedtechRules = rel.startsWith('src/styles/') || migratedMarkers.some((marker) => text.includes(marker))
  72. if (mustFollowMedtechRules && bannedEmoji.test(text)) failures.push(`banned emoji in ${rel}`)
  73. if (mustFollowMedtechRules && bannedDecor.test(text)) failures.push(`banned decorative style in ${rel}`)
  74. }
  75. if (failures.length) {
  76. console.error(failures.join('\n'))
  77. process.exit(1)
  78. }
  79. console.log('medtech theme checks passed')