import fs from 'fs' interface IconfontJson { font_family: string; css_prefix_text: string; glyphs: { icon_id: string font_class: string unicode: string name: string }[]; } export default function iconfontDts(outFile: string) { return function (content: string) { const json = JSON.parse(content) as IconfontJson const names = json.glyphs.map(glyph => glyph.font_class) console.log('正在生成文件:', outFile) const dts = `export {} declare global { namespace IconfontTypes { type name = ${names.map(name => `'${name}'`).join('\n | ')} } } ` fs.writeFileSync(outFile, dts, {encoding: 'utf-8'}) console.log('文件生成完成') } }