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.

51 lines
1.3 KiB
TypeScript

import { buildUtilsWriteFile } from '../../utils'
import {
IconBundleConfig,
SvgPrefix,
iconBundlePath,
iconListPath,
iconSVGPath,
} from '../src'
export async function generateIconDev() {
const names = IconBundleConfig.list.filter(i => i !== SvgPrefix)
const JSONName = (i: string) => `${i.replace('-', '')}Icons`
const customJSONName = 'CustomSvgJSON'
const importJSON = names.map(
i =>
`import ${JSONName(i)
} from '@iconify/json/json/${i}.json' \n`,
)
const addCollections = names.map(
i => `addCollection(${JSONName(i)}) \n`,
)
const generateListFromJSON = `const collections = [${names.map(i => JSONName(i))}, ${customJSONName}];
const ret: string[] = []
collections.forEach((item) => {
ret.push(...Object.keys(item.icons).map(key => \`\${item.prefix}:\${key}\`))
})
export default ret
`
const addImport = 'import { addCollection } from \'@iconify/vue\''
const importString = `
${importJSON.join('')}
import ${customJSONName} from '/${iconSVGPath}'\n
`
const addCollection = `${addCollections.join('')}
addCollection(${customJSONName})`
// addCollection bundle
await buildUtilsWriteFile(iconBundlePath, addImport + importString + addCollection)
// generate icon list
await buildUtilsWriteFile(iconListPath, importString + generateListFromJSON)
}