zhou zhou
20 小时以前 46d872c1a5b77aa8799de4a64888a0a24a1422d6
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
import assert from 'node:assert/strict'
import test from 'node:test'
import fs from 'node:fs'
import path from 'node:path'
import { fileURLToPath, pathToFileURL } from 'node:url'
 
const __dirname = path.dirname(fileURLToPath(import.meta.url))
const projectRoot = path.resolve(__dirname, '..')
const srcRoot = path.join(projectRoot, 'src')
const iconRegistryModule = pathToFileURL(path.join(srcRoot, 'plugins', 'iconify.js')).href
 
function collectSourceFiles(dir) {
  const entries = fs.readdirSync(dir, { withFileTypes: true })
  return entries.flatMap((entry) => {
    const fullPath = path.join(dir, entry.name)
 
    if (entry.isDirectory()) {
      return collectSourceFiles(fullPath)
    }
 
    return /\.(vue|js)$/.test(entry.name) ? [fullPath] : []
  })
}
 
function collectIconPrefixes() {
  const iconPattern = /icon\s*[:=]\s*["']([a-z0-9-]+):/g
  const prefixes = new Set()
 
  for (const filePath of collectSourceFiles(srcRoot)) {
    const content = fs.readFileSync(filePath, 'utf8')
 
    for (const match of content.matchAll(iconPattern)) {
      prefixes.add(match[1])
    }
  }
 
  return [...prefixes].sort()
}
 
test('all used Iconify prefixes are mapped to local collections', async () => {
  const { LOCAL_ICON_COLLECTIONS } = await import(iconRegistryModule)
  const actualPrefixes = collectIconPrefixes()
  const registeredPrefixes = Object.keys(LOCAL_ICON_COLLECTIONS).sort()
 
  assert.deepEqual(
    registeredPrefixes,
    actualPrefixes,
    `Missing local Iconify collections for: ${actualPrefixes.filter((prefix) => !registeredPrefixes.includes(prefix)).join(', ')}`
  )
})