@volverjs/ui-vue
Version:
@volverjs/ui-vue is a lightweight Vue 3 component library to accompany @volverjs/style.
3 lines (2 loc) • 1.7 kB
JavaScript
import o from"node:fs";import r from"node:path";import e from"yargs";import{hideBin as t}from"yargs/helpers";import{blankIconSet as n,SVG as i,cleanupSVG as c,parseColors as s,isEmptyColor as a,runSVGO as f}from"@iconify/tools";import{validateIconSet as l}from"@iconify/utils";import p from"chokidar";function h(e,t="iconify",n={}){return o.readdirSync(e).forEach(i=>{o.statSync(`${e}/${i}`).isDirectory()?n=h(`${e}/${i}`,i,n):i.includes(".svg")&&(n[t]?n[t].push(r.join(e,"/",i)):n[t]=[r.join(e,"/",i)])}),n}function d(e,t,p){const d=h(e,p?.prefix);Object.keys(d).length?Object.keys(d).forEach(e=>{!async function(e,t,p,h){const d=n(e);for(const r of t)try{const e=await o.promises.readFile(r,{encoding:"utf-8"}),t=new i(e);await c(t),h?.keepColors||await s(t,{defaultColor:"currentColor",callback:(o,r,e)=>!e||a(e)||r.includes("var(")?r:"currentColor"}),await f(t);const n=r.replace(/^.*[\\/]/,"").split(".")[0].replace(/ /g,"-").replace(/[^a-z0-9-]/gi,"");d.fromSVG(n,t)}catch(g){console.error(g)}const m=d.export();try{l(m)}catch(g){throw new Error(`Icon set is not valid: ${g?.message}`)}const y=`${p}/${m.prefix}.json`;o.mkdirSync(r.dirname(y),{recursive:!0}),o.writeFileSync(y,JSON.stringify(m))}(e,d[e],t,p),console.info(`Icons generated in: ${t}/${e}.json\n`)}):console.error(`There are no files in ${e}`)}const m=e(t(process.argv)).argv,y=m.srcPath,g=m.destPath||y;y&&g||(console.error("Please specify the srcPath and destPath with --srcPath and --destPath"),process.exit());const u={prefix:m.prefix,keepColors:m.keepColors};m.watch?(d(y,g,u),p.watch(y,{ignoreInitial:!0}).on("add",()=>{d(y,g,u)}).on("change",()=>{d(y,g,u)})):d(y,g,u);export{d as createIconifyJsonFiles};