Skip to content

Commit d856e8c

Browse files
committed
Added scripts to clear parsers/in and parsers/out after build:reference
1 parent fcf9ba8 commit d856e8c

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed

src/scripts/parsers/reference.ts

+9-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { cloneLibraryRepo, p5RepoUrl, readFile } from "../utils";
1+
import { cloneLibraryRepo,cleanUpDirectory, p5RepoUrl, readFile } from "../utils";
22
import fs from "fs/promises";
33
import { exec, execSync } from "child_process";
44
import path from "path";
@@ -13,6 +13,10 @@ const localPath = path.join(__dirname, "in", "p5.js");
1313
const localSoundPath = path.join(__dirname, "in", "p5.sound.js");
1414
const yuidocOutputPath = path.join(__dirname, "out")
1515

16+
//Directory to clean after cloning the libraries
17+
const parsersInPath = path.join(__dirname, "in");
18+
const parsersOutPath = path.join(__dirname, "out");
19+
1620
/**
1721
* Main function to clone the p5.js library and save the YUIDoc output to a file
1822
*/
@@ -77,6 +81,10 @@ export const parseLibraryReference =
7781
);
7882

7983
await serveYuidocOutput('data');
84+
85+
//delete the cloned directories
86+
await cleanUpDirectory(parsersInPath );
87+
await cleanUpDirectory(parsersOutPath );
8088
return combined;
8189
};
8290

src/scripts/utils.ts

+12
Original file line numberDiff line numberDiff line change
@@ -304,3 +304,15 @@ export const rewriteRelativeMdLinks = (markdownText: string): string => {
304304
return `[${linkText}](${updatedUrl})`;
305305
});
306306
};
307+
/**
308+
* Deletes the contents of the given directory.
309+
* @param dirPath Path to the directory to clean up.
310+
*/
311+
export const cleanUpDirectory = async (dirPath: string) => {
312+
try {
313+
await fs.rm(dirPath, { recursive: true, force: true });
314+
console.log(`Cleaned up directory: ${dirPath}`);
315+
} catch (err) {
316+
console.error(`Error cleaning up directory ${dirPath}: ${err}`);
317+
}
318+
};

0 commit comments

Comments
 (0)