gen-unocss.ts 934 B

123456789101112131415161718192021222324252627282930313233
  1. import path from 'path'
  2. import { theme } from 'ant-design-vue'
  3. import lodash from 'lodash'
  4. import fsExtra from 'fs-extra'
  5. const { defaultAlgorithm, defaultSeed } = theme
  6. const mapToken = defaultAlgorithm(defaultSeed)
  7. const formatKey = (key: string, prefixCls: string) => {
  8. return `${prefixCls}${lodash.kebabCase(key)}`
  9. }
  10. const prefixCls = '--pro-ant-'
  11. const variables: {
  12. colors: Record<string, any>
  13. } = {
  14. colors: {},
  15. }
  16. let colorTheme = ''
  17. for (const key in mapToken) {
  18. if (key.startsWith('color')) {
  19. const cssVar = formatKey(key, prefixCls)
  20. const colors = variables.colors
  21. const themeKey = lodash.camelCase(key.slice(5))
  22. colors[themeKey] = `var(${cssVar})`
  23. colorTheme += `${themeKey}\n`
  24. }
  25. }
  26. fsExtra.outputFile(path.resolve(process.cwd(), './themes/antd-uno-theme.json'), JSON.stringify(variables, null, 2))
  27. fsExtra.outputFile(path.resolve(process.cwd(), './themes/color-theme-var.md'), colorTheme)