You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
42 lines
1.0 KiB
TypeScript
42 lines
1.0 KiB
TypeScript
12 months ago
|
import fg from 'fast-glob'
|
||
|
|
||
|
import { buildUtilsReadFile, buildUtilsWriteFile } from '../../utils'
|
||
|
import { IconLog, iconListPath } from '../src/index'
|
||
|
import { getIconListAllArray } from './icon-list-all'
|
||
|
|
||
|
export async function generateIconListScan() {
|
||
|
const iconPool = await getIconListAllArray()
|
||
|
|
||
|
const files = await fg('src/**/*.{vue,ts,tsx}', { dot: true })
|
||
|
|
||
|
IconLog(
|
||
|
'Icon Scan',
|
||
|
`Scanning all 'vue, ts, tsx' files under 'src'. File number: ${files.length}`,
|
||
|
)
|
||
|
|
||
|
const buffers = await Promise.all(files.map(i => buildUtilsReadFile(i)))
|
||
|
|
||
|
const ret = [
|
||
|
...new Set(
|
||
|
buffers
|
||
|
.map(i =>
|
||
|
iconPool
|
||
|
.map(q => i.toString().match(new RegExp(q, 'gm')))
|
||
|
.filter(i => i),
|
||
|
)
|
||
|
.filter(i => i.length !== 0)
|
||
|
.flat(Number.POSITIVE_INFINITY),
|
||
|
),
|
||
|
]
|
||
|
|
||
|
await buildUtilsWriteFile(
|
||
|
iconListPath,
|
||
|
`export default ${JSON.stringify(ret)}`,
|
||
|
)
|
||
|
|
||
|
IconLog(
|
||
|
'Icon Scan',
|
||
|
`Detected ${ret.length} matched icons, writing into file: ${iconListPath}`,
|
||
|
)
|
||
|
}
|