diff --git a/scripts/build.ts b/scripts/build.ts index 1e55cd70e..fed894281 100644 --- a/scripts/build.ts +++ b/scripts/build.ts @@ -32,8 +32,17 @@ async function build(rootDir: string) { await createCheatsheet(version, rootDir, distDir, svgSymbolsContent, srcSvgData); await createWebTypes(version, rootDir, distDir, srcSvgData); - - await copyToTesting(rootDir, distDir, srcSvgData); + + await Promise.all([ + await copyToTesting(rootDir, distDir, srcSvgData), + /** + * Writes the optimized SVGs back to its source directory. This directory is where + * SVGs are pulled from when previewing Ionicons in the Stencil dev server. + * As a result, we want to ensure that what we are testing is that same as + * what users will see in production. + */ + await writeSVGData(srcSvgDir, srcSvgData) + ]); } catch (e) { console.error(e); process.exit(1); @@ -192,18 +201,27 @@ async function optimizeSvg( await fs.writeFile(svgData.distSvgFilePath, sourceSvg.data); } +/** + * Writes SVG data to a directory. + * @param distDir - The directory to write the SVG files + * @param svgData - An array of SVG data to write + */ +async function writeSVGData(distDir: string, svgData: SvgData[]) { + await Promise.all( + svgData.map(async (svgData) => { + const outPath = join(distDir, svgData.fileName); + await fs.writeFile(outPath, svgData.optimizedSvgContent); + }), + ); +} + async function copyToTesting(rootDir: string, distDir: string, srcSvgData: SvgData[]) { const testDir = join(rootDir, 'www'); const testBuildDir = join(testDir, 'build'); const testSvgDir = join(testBuildDir, 'svg'); await fs.ensureDir(testSvgDir); - - await Promise.all( - srcSvgData.map(async (svgData) => { - const testSvgFilePath = join(testSvgDir, svgData.fileName); - await fs.writeFile(testSvgFilePath, svgData.optimizedSvgContent); - }), - ); + + await writeSVGData(testSvgDir, srcSvgData); const distCheatsheetFilePath = join(distDir, 'cheatsheet.html'); const testCheatsheetFilePath = join(testDir, 'cheatsheet.html');