5
5
6
6
import webfont from 'webfont'
7
7
import * as path from 'path'
8
- import * as fs from 'fs-extra '
8
+ import * as nodefs from 'fs'
9
9
10
10
const fontId = 'aws-toolkit-icons'
11
11
const projectDir = process . cwd ( ) // root/packages/toolkit
12
12
const rootDir = path . join ( projectDir , '../..' ) // root/
13
13
const iconsDir = path . join ( projectDir , 'resources' , 'icons' )
14
14
const fontsDir = path . join ( projectDir , 'resources' , 'fonts' )
15
15
const 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' } ) )
17
17
const iconSources = [
18
18
// Paths relative to packages/toolkit
19
19
`resources/icons/**/*.svg` ,
@@ -69,7 +69,7 @@ async function updatePackage(fontPath: string, icons: [id: string, icon: Package
69
69
70
70
// prettier adds a newline to JSON files
71
71
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 )
73
73
console . log ( 'Updated package.json' )
74
74
}
75
75
@@ -81,15 +81,15 @@ const themes = {
81
81
async function generateCloud9Icons ( targets : { name : string ; path : string } [ ] , destination : string ) : Promise < void > {
82
82
console . log ( 'Generating icons for Cloud9' )
83
83
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' )
86
86
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 )
88
88
}
89
89
90
90
for ( const [ theme , color ] of Object . entries ( themes ) ) {
91
91
const themeDest = path . join ( destination , theme )
92
- await fs . mkdirp ( themeDest )
92
+ nodefs . mkdirSync ( themeDest , { recursive : true } )
93
93
await Promise . all ( targets . map ( ( t ) => replaceColor ( t . path , color , path . join ( themeDest , `${ t . name } .svg` ) ) ) )
94
94
}
95
95
}
@@ -169,9 +169,11 @@ ${result.template}
169
169
const cloud9Dest = path . join ( iconsDir , 'cloud9' , 'generated' )
170
170
const isValidIcon = ( i : ( typeof icons ) [ number ] ) : i is Required < typeof i > => i . data !== undefined
171
171
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 )
175
177
await updatePackage (
176
178
`./${ relativeDest } ` ,
177
179
icons . filter ( isValidIcon ) . map ( ( i ) => [ i . name , i . data ] )
@@ -182,7 +184,7 @@ ${result.template}
182
184
generated . addEntry ( stylesheetPath )
183
185
generated . addEntry ( cloud9Dest )
184
186
185
- await generated . emit ( path . join ( projectDir , 'dist' ) )
187
+ generated . emit ( path . join ( projectDir , 'dist' ) )
186
188
}
187
189
188
190
class GeneratedFilesManifest {
@@ -192,17 +194,17 @@ class GeneratedFilesManifest {
192
194
this . files . push ( file )
193
195
}
194
196
195
- public async emit ( dir : string ) : Promise < void > {
197
+ public emit ( dir : string ) : void {
196
198
const dest = path . join ( dir , 'generated.buildinfo' )
197
199
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 )
200
202
}
201
203
}
202
204
203
205
async function loadCodiconMappings ( ) : Promise < Record < string , number | undefined > > {
204
206
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' ) )
206
208
const mappings : Record < string , number | undefined > = { }
207
209
for ( const [ k , v ] of Object . entries ( data ) ) {
208
210
if ( typeof k === 'string' && typeof v === 'number' ) {
0 commit comments