import path from 'path' ; import fs from 'fs' ; import glob from 'glob' ; import svg2img from 'svg2img' ; export interface Settings { size : number ; suffix : string | boolean ; fill ? : string ; } const defaultOptions = [ { size : 24 , suffix : false } , { size : 48 , suffix : '@2x' } , { size : 72 , suffix : '@3x' } , ] ; glob ( './src/icons/**/*.svg' , function ( _ , files ) { files . forEach ( ( icon ) => { const iconPath = path . join ( __dirname , `../${ icon }` ) ; icon = iconPath . replace ( '.svg' , '' ) . replace ( 'src/icons' , 'textures' ) ; const distFolder = icon . split ( '/' ) . slice ( 0 , - 1 ) . join ( '/' ) ; fs . readFile ( iconPath , 'utf8' , ( err , data ) => { if ( err ) throw err ; data = Buffer . from ( data , 'utf8' ) ; defaultOptions . forEach ( ( setting ) => { const { size , suffix } = setting ; fs . mkdir ( distFolder , function ( ) { svg2img ( data , { width : size , height : size } , ( _ , buffer ) => { fs . writeFileSync ( `${ suffix ? icon + suffix : icon }.png` , buffer ) ; } ) ; } ) ; } ) ; } ) ; } ) ; } ) ;