import fg from "fast-glob" ; import makeDir from "make-dir" ; import path from "path" ; const svgexport = require ( "svgexport" ) ; const INPUT_DIR = "./font-awesome/svgs" ; const INPUT_SVG_PATHS = fg . sync ( `${ INPUT_DIR }/**/*.svg` ) ; const OUTPUT_DIR = "./assets/icons" ; const PARAMS = "pad 128:128" ; const outputPath = ( inputPath ) : string => { const outputDir = path . parse ( inputPath . replace ( INPUT_DIR , OUTPUT_DIR ) ) . dir ; const name = path . parse ( inputPath ) . name ; return `${ outputDir }/${ name }.png` ; } ; type TSvg = Readonly < { input : string ; output : string ; } > ; const SVGS = INPUT_SVG_PATHS . map ( ( inputPath ) => { return { input : inputPath , output : `${ outputPath ( inputPath ) } ${ PARAMS }` , } as TSvg ; } ) ; const makeStylesDir = async ( svgs ) : Promise < string [ ] > => { const outputPaths = svgs . map ( ( svg ) => path . parse ( svg . output ) . dir ) ; const outputDirs = [ ... new Set ( outputPaths ) ] ; return await Promise . all ( outputDirs . map ( async ( dir ) => await makeDir ( dir ) ) ) ; } ; const convert = ( svgs ) => { svgexport . render ( svgs , process ) ; } ; const main = async ( ) => { console . log ( "SVG2PNG is progress..." ) ; await makeStylesDir ( SVGS ) ; convert ( SVGS ) ; } ; main ( ) ;