55
66import webfont from 'webfont'
77import * as path from 'path'
8- import * as fs from 'fs-extra '
8+ import * as nodefs from 'fs'
99
1010const fontId = 'aws-toolkit-icons'
1111const projectDir = process . cwd ( ) // root/packages/toolkit
1212const rootDir = path . join ( projectDir , '../..' ) // root/
1313const iconsDir = path . join ( projectDir , 'resources' , 'icons' )
1414const fontsDir = path . join ( projectDir , 'resources' , 'fonts' )
1515const stylesheetsDir = path . join ( projectDir , 'resources' , 'css' )
16- const packageJson = JSON . parse ( fs . readFileSync ( path . join ( projectDir , 'package.json' ) , { encoding : 'utf-8' } ) )
16+ const packageJson = JSON . parse ( nodefs . readFileSync ( path . join ( projectDir , 'package.json' ) , { encoding : 'utf-8' } ) )
1717const iconSources = [
1818 // Paths relative to packages/toolkit
1919 `resources/icons/**/*.svg` ,
@@ -69,7 +69,7 @@ async function updatePackage(fontPath: string, icons: [id: string, icon: Package
6969
7070 // prettier adds a newline to JSON files
7171 const newPackage = `${ JSON . stringify ( packageJson , undefined , 4 ) } \n`
72- await fs . writeFile ( path . join ( projectDir , 'package.json' ) , newPackage )
72+ nodefs . writeFileSync ( path . join ( projectDir , 'package.json' ) , newPackage )
7373 console . log ( 'Updated package.json' )
7474}
7575
@@ -81,15 +81,15 @@ const themes = {
8181async function generateCloud9Icons ( targets : { name : string ; path : string } [ ] , destination : string ) : Promise < void > {
8282 console . log ( 'Generating icons for Cloud9' )
8383
84- async function replaceColor ( file : string , color : string , dst : string ) : Promise < void > {
85- const contents = await fs . readFile ( file , 'utf-8' )
84+ function replaceColor ( file : string , color : string , dst : string ) : void {
85+ const contents = nodefs . readFileSync ( file , 'utf-8' )
8686 const replaced = contents . replace ( / c u r r e n t C o l o r / g, color )
87- await fs . writeFile ( dst , replaced )
87+ nodefs . writeFileSync ( dst , replaced )
8888 }
8989
9090 for ( const [ theme , color ] of Object . entries ( themes ) ) {
9191 const themeDest = path . join ( destination , theme )
92- await fs . mkdirp ( themeDest )
92+ nodefs . mkdirSync ( themeDest , { recursive : true } )
9393 await Promise . all ( targets . map ( ( t ) => replaceColor ( t . path , color , path . join ( themeDest , `${ t . name } .svg` ) ) ) )
9494 }
9595}
@@ -169,9 +169,11 @@ ${result.template}
169169 const cloud9Dest = path . join ( iconsDir , 'cloud9' , 'generated' )
170170 const isValidIcon = ( i : ( typeof icons ) [ number ] ) : i is Required < typeof i > => i . data !== undefined
171171
172- await fs . mkdirp ( fontsDir )
173- await fs . writeFile ( dest , result . woff )
174- await fs . writeFile ( stylesheetPath , template )
172+ nodefs . mkdirSync ( fontsDir , { recursive : true } )
173+ if ( result . woff ) {
174+ nodefs . writeFileSync ( dest , result . woff )
175+ }
176+ nodefs . writeFileSync ( stylesheetPath , template )
175177 await updatePackage (
176178 `./${ relativeDest } ` ,
177179 icons . filter ( isValidIcon ) . map ( ( i ) => [ i . name , i . data ] )
@@ -182,7 +184,7 @@ ${result.template}
182184 generated . addEntry ( stylesheetPath )
183185 generated . addEntry ( cloud9Dest )
184186
185- await generated . emit ( path . join ( projectDir , 'dist' ) )
187+ generated . emit ( path . join ( projectDir , 'dist' ) )
186188}
187189
188190class GeneratedFilesManifest {
@@ -192,17 +194,17 @@ class GeneratedFilesManifest {
192194 this . files . push ( file )
193195 }
194196
195- public async emit ( dir : string ) : Promise < void > {
197+ public emit ( dir : string ) : void {
196198 const dest = path . join ( dir , 'generated.buildinfo' )
197199 const data = JSON . stringify ( this . files , undefined , 4 )
198- await fs . mkdirp ( dir )
199- await fs . writeFile ( dest , data )
200+ nodefs . mkdirSync ( dir , { recursive : true } )
201+ nodefs . writeFileSync ( dest , data )
200202 }
201203}
202204
203205async function loadCodiconMappings ( ) : Promise < Record < string , number | undefined > > {
204206 const codicons = path . join ( rootDir , 'node_modules' , '@vscode' , 'codicons' , 'src' )
205- const data = JSON . parse ( await fs . readFile ( path . join ( codicons , 'template' , 'mapping.json' ) , 'utf-8' ) )
207+ const data = JSON . parse ( nodefs . readFileSync ( path . join ( codicons , 'template' , 'mapping.json' ) , 'utf-8' ) )
206208 const mappings : Record < string , number | undefined > = { }
207209 for ( const [ k , v ] of Object . entries ( data ) ) {
208210 if ( typeof k === 'string' && typeof v === 'number' ) {
0 commit comments