zhou zhou
22 小时以前 40905cbd04c2e332cd4bc2b9e0c5b3e1da9cccfa
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
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 = /["']([a-z0-9-]+):([a-z0-9-]+)["']/g
  const knownPrefixes = new Set([
    'fluent',
    'icon-park-outline',
    'iconamoon',
    'ix',
    'line-md',
    'ri',
    'svg-spinners',
    'system-uicons',
    'vaadin'
  ])
  const prefixes = new Set()
 
  for (const filePath of collectSourceFiles(srcRoot)) {
    const content = fs.readFileSync(filePath, 'utf8')
 
    for (const [, prefix] of content.matchAll(iconPattern)) {
      if (!knownPrefixes.has(prefix)) {
        continue
      }
 
      prefixes.add(prefix)
    }
  }
 
  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(', ')}`
  )
})