1- import * as path from 'path' ;
2- import * as fs from 'fs' ;
1+ import * as path from 'path'
2+ import * as fs from 'fs'
33
4- import { IconGenerateScript } from '../interface/index' ;
5- import componentTemplate from '../template/iconComponent' ;
6- import iconIndexTemplate from '../template/iconIndex' ;
4+ import { IconGenerateScript } from '../interface/index'
5+ import componentTemplate from '../template/iconComponent'
6+ import iconIndexTemplate from '../template/iconIndex'
77
8- async function generateIconComponents ( { type, from} : IconGenerateScript ) {
9-
10- const iconNames = await fs . promises . readdir ( from ) ;
11- for ( const iconName of iconNames ) {
12- const fileName = iconName . slice ( 0 , iconName . length - 4 ) . concat ( type . charAt ( 0 ) . toUpperCase ( ) + type . slice ( 1 ) ) ;
8+ async function generateIconComponents ( { type, from } : IconGenerateScript ) {
9+ const iconNames = await fs . promises . readdir ( from )
10+ for ( const iconName of iconNames ) {
11+ const fileName = iconName . slice ( 0 , iconName . length - 4 ) . concat ( type . charAt ( 0 ) . toUpperCase ( ) + type . slice ( 1 ) )
1312
1413 // fetching Data of the required SVG file
15- fs . readFile ( path . resolve ( __dirname , `../svg/${ type } /${ iconName } ` ) , 'utf8' , async function ( err , data ) {
16- if ( err ) {
17- console . error ( err ) ;
14+ fs . readFile ( path . resolve ( __dirname , `../svg/${ type } /${ iconName } ` ) , 'utf8' , async function ( err , data ) {
15+ if ( err ) {
16+ console . error ( err )
1817 }
1918
20- if ( type === 'animated' ) {
21- data = data . replace ( 'xml:space="preserve"' , '' ) ;
22- if ( fileName === 'installingAnimated' ) {
23- while ( data . includes ( 'class="st0"' ) ) {
24- data = data . replace ( 'class="st0"' , 'className="st0"' ) ;
19+ if ( type === 'animated' ) {
20+ data = data . replace ( 'xml:space="preserve"' , '' )
21+ if ( fileName === 'installingAnimated' ) {
22+ while ( data . includes ( 'class="st0"' ) ) {
23+ data = data . replace ( 'class="st0"' , 'className="st0"' )
2524 }
2625 }
2726 }
2827
29- const propString = "svg transform={`rotate(${rotate})`} fill={color} width={size} height={size}"
30- data = data . replace ( 'svg' , propString ) ;
28+ // eslint-disable-next-line no-template-curly-in-string
29+ const propString = 'svg transform={`rotate(${rotate})`} fill={color} width={size} height={size}'
30+ data = data . replace ( 'svg' , propString )
3131
32- const render = componentTemplate ( { fileName, data} ) ;
33- const indexContent = iconIndexTemplate ( { fileName} ) ;
32+ const render = componentTemplate ( { fileName, data } )
33+ const indexContent = iconIndexTemplate ( { fileName } )
3434
3535 // creates a .tsx file at src/icon/ containing a react component
3636 fs . writeFile (
37- path . resolve ( __dirname , `../src/icon/${ fileName } .tsx` ) ,
38- render ,
37+ path . resolve ( __dirname , `../src/icon/${ fileName } .tsx` ) ,
38+ render ,
3939 {
4040 flag : 'w+'
4141 } ,
4242 err => {
43- if ( err ) {
43+ if ( err ) {
4444 console . error ( err )
4545 }
46- } )
47-
46+ } )
47+
4848 // creates a .tsx index file at src/icon/ containing exports of all the icons
4949 fs . writeFile (
50- path . resolve ( __dirname , ` ../src/icon/index.tsx` ) ,
50+ path . resolve ( __dirname , ' ../src/icon/index.tsx' ) ,
5151 indexContent ,
5252 {
5353 flag : 'a+'
5454 } ,
5555 err => {
56- if ( err ) {
56+ if ( err ) {
5757 console . error ( err )
5858 }
59- } ) ;
59+ } )
6060 } )
61-
62- fs . close
6361 }
6462}
6563
66- export default generateIconComponents ;
64+ export default generateIconComponents
0 commit comments