Skip to content

Commit a51b2f8

Browse files
ensure all directories exist
1 parent 1e50470 commit a51b2f8

1 file changed

Lines changed: 30 additions & 8 deletions

File tree

scripts/build.ts

Lines changed: 30 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,18 @@ async function build(rootDir: string) {
1818
const distSvgDir = path.join(distDir, 'svg');
1919
const optimizedSvgDir = path.join(distIoniconsDir, 'svg');
2020

21+
/**
22+
* Create the directories first, then empty them
23+
* This ensures they exist before we try to write files to them
24+
*/
25+
await Promise.all([
26+
fs.ensureDir(iconDir),
27+
fs.ensureDir(distDir),
28+
fs.ensureDir(distSvgDir),
29+
fs.ensureDir(optimizedSvgDir),
30+
fs.ensureDir(distIoniconsDir),
31+
]);
32+
2133
/**
2234
* Empty the directories
2335
*/
@@ -32,7 +44,6 @@ async function build(rootDir: string) {
3244
const version = pkgData.version as string;
3345
const srcSvgData = await getSvgs(srcSvgDir, distSvgDir, optimizedSvgDir);
3446
await optimizeSvgs(srcSvgData);
35-
3647
await Promise.all([
3748
createDataJson(version, srcDir, distDir, srcSvgData),
3849
createIconPackage(version, iconDir, srcSvgData),
@@ -41,9 +52,7 @@ async function build(rootDir: string) {
4152
const svgSymbolsContent = await createSvgSymbols(version, distDir, srcSvgData);
4253

4354
await createCheatsheet(version, rootDir, distDir, svgSymbolsContent, srcSvgData);
44-
4555
await createWebTypes(version, rootDir, distDir, srcSvgData);
46-
4756
await copyToTesting(rootDir, distDir, srcSvgData);
4857
} catch (e) {
4958
console.error(e);
@@ -72,16 +81,30 @@ async function optimizeSvg(svgData: SvgData) {
7281
plugins: sourcePassPlugins,
7382
});
7483

84+
// Ensure directories exist before writing files
85+
await Promise.all([
86+
fs.ensureDir(path.dirname(svgData.optimizedFilePath)),
87+
fs.ensureDir(path.dirname(svgData.distSvgFilePath)),
88+
]);
89+
7590
svgData.optimizedSvgContent = webComponentSvg.data;
76-
await fs.writeFile(svgData.optimizedFilePath, svgData.optimizedSvgContent);
77-
await fs.writeFile(svgData.distSvgFilePath, sourceSvg.data);
91+
await Promise.all([
92+
fs.writeFile(svgData.optimizedFilePath, svgData.optimizedSvgContent),
93+
fs.writeFile(svgData.distSvgFilePath, sourceSvg.data),
94+
]);
7895
}
7996

8097
async function copyToTesting(rootDir: string, distDir: string, srcSvgData: SvgData[]) {
8198
const testDir = path.join(rootDir, 'www');
8299
const testBuildDir = path.join(testDir, 'build');
83100
const testSvgDir = path.join(testBuildDir, 'svg');
84-
await fs.ensureDir(testSvgDir);
101+
102+
// Ensure all directories exist
103+
await Promise.all([
104+
fs.ensureDir(testDir),
105+
fs.ensureDir(testBuildDir),
106+
fs.ensureDir(testSvgDir)
107+
]);
85108

86109
await Promise.all(
87110
srcSvgData
@@ -163,10 +186,9 @@ async function createCheatsheet(
163186
await fs.writeFile(distCheatsheetFilePath, html);
164187
}
165188

166-
async function createWebTypes(version: string, rootDir: string, distDir: any, srcSvgData: SvgData[]) {
189+
async function createWebTypes(version: string, rootDir: string, distDir: string, srcSvgData: SvgData[]) {
167190
const srcWebTypeFilePath = path.join(rootDir, 'src/ionicons.web-types.json');
168191
const distWebTypesFilePath = path.join(distDir, 'ionicons.web-types.json');
169-
170192
const webTypes = JSON.parse(await fs.readFile(srcWebTypeFilePath, 'utf8'));
171193

172194
webTypes.version = version;

0 commit comments

Comments
 (0)