Skip to content

Commit 10ac9f2

Browse files
committed
chore: build script persists optimized SVGs
1 parent b63d12b commit 10ac9f2

File tree

1 file changed

+27
-9
lines changed

1 file changed

+27
-9
lines changed

scripts/build.ts

+27-9
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,17 @@ async function build(rootDir: string) {
3232
await createCheatsheet(version, rootDir, distDir, svgSymbolsContent, srcSvgData);
3333

3434
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+
]);
3746
} catch (e) {
3847
console.error(e);
3948
process.exit(1);
@@ -192,18 +201,27 @@ async function optimizeSvg(
192201
await fs.writeFile(svgData.distSvgFilePath, sourceSvg.data);
193202
}
194203

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+
195218
async function copyToTesting(rootDir: string, distDir: string, srcSvgData: SvgData[]) {
196219
const testDir = join(rootDir, 'www');
197220
const testBuildDir = join(testDir, 'build');
198221
const testSvgDir = join(testBuildDir, 'svg');
199222
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);
207225

208226
const distCheatsheetFilePath = join(distDir, 'cheatsheet.html');
209227
const testCheatsheetFilePath = join(testDir, 'cheatsheet.html');

0 commit comments

Comments
 (0)