返回 slidev
unocss-scan.ts
根目录 / packages / client / scripts / unocss-scan.ts
1 import fs from 'node:fs/promises'
2 import { fileURLToPath } from 'node:url'
3 import { createGenerator } from '@unocss/core'
4 import fg from 'fast-glob'
5 import config from '../uno.config'
6
7 const uno = await createGenerator(config)
8
9 const files = await fg(
10 '**/*.vue',
11 {
12 cwd: fileURLToPath(new URL('..', import.meta.url)),
13 ignore: ['**/*.generated/**', '**/node_modules/**'],
14 absolute: true,
15 },
16 )
17
18 const tokens = new Set<string>()
19 for (const file of files) {
20 const content = await fs.readFile(file, 'utf-8')
21 await uno.applyExtractors(
22 content,
23 file,
24 tokens,
25 )
26 }
27
28 const result = await uno.generate(tokens)
29
30 await fs.writeFile(
31 fileURLToPath(new URL('../.generated/unocss-tokens.ts', import.meta.url)),
32 [
33 '/* eslint-disable eslint-comments/no-unlimited-disable */',
34 '/* eslint-disable */',
35 `export default ${JSON.stringify(Array.from(result.matched).sort(), null, 2)}`,
36 ].join('\n'),
37 'utf-8',
38 )
39
39 lines TYPESCRIPT