@@ -32,8 +32,17 @@ async function build(rootDir: string) {
32
32
await createCheatsheet ( version , rootDir , distDir , svgSymbolsContent , srcSvgData ) ;
33
33
34
34
await createWebTypes ( version , rootDir , distDir , srcSvgData ) ;
35
-
36
- await copyToTesting ( rootDir , distDir , srcSvgData ) ;
35
+
36
+ await Promise . all ( [
37
+ await copyToTesting ( rootDir , distDir , srcSvgData ) ,
38
+ /**
39
+ * Writes the optimized SVGs back to its source directory. This directory is where
40
+ * SVGs are pulled from when previewing Ionicons in the Stencil dev server.
41
+ * As a result, we want to ensure that what we are testing is that same as
42
+ * what users will see in production.
43
+ */
44
+ await writeSVGData ( srcSvgDir , srcSvgData )
45
+ ] ) ;
37
46
} catch ( e ) {
38
47
console . error ( e ) ;
39
48
process . exit ( 1 ) ;
@@ -192,18 +201,27 @@ async function optimizeSvg(
192
201
await fs . writeFile ( svgData . distSvgFilePath , sourceSvg . data ) ;
193
202
}
194
203
204
+ /**
205
+ * Writes SVG data to a directory.
206
+ * @param distDir - The directory to write the SVG files
207
+ * @param svgData - An array of SVG data to write
208
+ */
209
+ async function writeSVGData ( distDir : string , svgData : SvgData [ ] ) {
210
+ await Promise . all (
211
+ svgData . map ( async ( svgData ) => {
212
+ const outPath = join ( distDir , svgData . fileName ) ;
213
+ await fs . writeFile ( outPath , svgData . optimizedSvgContent ) ;
214
+ } ) ,
215
+ ) ;
216
+ }
217
+
195
218
async function copyToTesting ( rootDir : string , distDir : string , srcSvgData : SvgData [ ] ) {
196
219
const testDir = join ( rootDir , 'www' ) ;
197
220
const testBuildDir = join ( testDir , 'build' ) ;
198
221
const testSvgDir = join ( testBuildDir , 'svg' ) ;
199
222
await fs . ensureDir ( testSvgDir ) ;
200
-
201
- await Promise . all (
202
- srcSvgData . map ( async ( svgData ) => {
203
- const testSvgFilePath = join ( testSvgDir , svgData . fileName ) ;
204
- await fs . writeFile ( testSvgFilePath , svgData . optimizedSvgContent ) ;
205
- } ) ,
206
- ) ;
223
+
224
+ await writeSVGData ( testSvgDir , srcSvgData ) ;
207
225
208
226
const distCheatsheetFilePath = join ( distDir , 'cheatsheet.html' ) ;
209
227
const testCheatsheetFilePath = join ( testDir , 'cheatsheet.html' ) ;
0 commit comments