Skip to content

Commit 4ea66f5

Browse files
committed
Add reset script
1 parent f89448b commit 4ea66f5

File tree

5 files changed

+52
-19
lines changed

5 files changed

+52
-19
lines changed

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@
1616
"build:reference": "tsx ./src/scripts/builders/reference.ts",
1717
"build:search": "tsx ./src/scripts/builders/search.ts",
1818
"build:p5-version": "tsx ./src/scripts/p5-version.ts",
19-
"custom:dev": "tsx ./src/scripts/branchTest.ts"
19+
"custom:dev": "tsx ./src/scripts/branchTest.ts",
20+
"custom:cleanup": "tsx ./src/scripts/resetBranchTest.ts"
2021
},
2122
"dependencies": {
2223
"@astrojs/check": "^0.5.5",

src/scripts/branchTest.ts

Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,32 @@
1-
import { execSync } from "child_process"
2-
import { existsSync, rmSync } from "fs"
3-
import path from "path"
1+
import { execSync } from "child_process";
2+
import { existsSync, rmSync } from "fs";
3+
import path from "path";
4+
import { fileURLToPath } from "url";
45

5-
const url = process.argv[2]
6-
const match = /^(.+)#(.+)$/.exec(url)
6+
const __dirname = path.dirname(fileURLToPath(import.meta.url));
7+
8+
const url = process.argv[2];
9+
const match = /^(.+)#(.+)$/.exec(url);
710
if (!match) {
8-
console.error(`Please pass a git URL followed by a # and then a branch name, tag, or commit as the parameter to this script, e.g. https://github.com/processing/p5.js.git#main`)
9-
process.exit(1)
11+
console.error(
12+
`Please pass a git URL followed by a # and then a branch name, tag, or commit as the parameter to this script, e.g. https://github.com/processing/p5.js.git#main`,
13+
);
14+
process.exit(1);
1015
}
1116

12-
const repoUrl = match[1]
13-
const branch = match[2]
17+
const repoUrl = match[1];
18+
const branch = match[2];
1419

15-
const env = `P5_LIBRARY_PATH='/p5.min.js' P5_REPO_URL='${repoUrl}' P5_BRANCH='${branch}'`
20+
const env = `P5_LIBRARY_PATH='/p5.min.js' P5_REPO_URL='${repoUrl}' P5_BRANCH='${branch}'`;
1621

1722
// First delete the existing cloned p5 to make sure we clone fresh
18-
const parsedP5Path = path.join(__dirname, './parsers/in/p5.js/')
23+
const parsedP5Path = path.join(__dirname, "./parsers/in/p5.js/");
1924
if (existsSync(parsedP5Path)) {
20-
rmSync(parsedP5Path, { recursive: true })
25+
rmSync(parsedP5Path, { recursive: true });
2126
}
2227

2328
// Build the reference using the specified environment
24-
execSync(`${env} npm run build:reference`)
29+
execSync(`${env} npm run build:reference`, { stdio: "inherit" });
2530

2631
// Run a dev server
27-
execSync(`${env} npm run dev`)
32+
execSync(`${env} npm run dev`, { stdio: "inherit" });

src/scripts/parsers/reference.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,12 @@ const yuidocOutputPath = path.join(__dirname, "out")
1919
export const parseLibraryReference =
2020
async (): Promise<ParsedLibraryReference | null> => {
2121
// Clone p5.js
22-
await cloneLibraryRepo(localPath, process.env.P5_REPO_URL || p5RepoUrl, process.env.P5_BRANCH || p5Version, { shouldFixAbsolutePathInPreprocessor: false });
22+
await cloneLibraryRepo(
23+
localPath,
24+
process.env.P5_REPO_URL || p5RepoUrl,
25+
process.env.P5_BRANCH || p5Version,
26+
{ shouldFixAbsolutePathInPreprocessor: false },
27+
);
2328

2429
// Install dependencies and build docs in the p5 repo
2530
await createP5Docs('p5.js', 'data-p5')

src/scripts/resetBranchTest.ts

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import { fileURLToPath } from "url";
2+
import path from "path";
3+
import { existsSync, rmSync } from "fs";
4+
import simpleGit from "simple-git";
5+
6+
async function main() {
7+
const __dirname = path.dirname(fileURLToPath(import.meta.url));
8+
9+
const referencePath = path.join(__dirname, '../content/reference/');
10+
const dataPath = path.join(__dirname, '../../public/reference/data.json')
11+
rmSync(referencePath, { recursive: true });
12+
13+
const git = simpleGit();
14+
await git.checkout('HEAD', [referencePath, dataPath]);
15+
16+
const p5BuildPath = path.join(__dirname, '../../public/p5.min.js');
17+
if (existsSync(p5BuildPath)) {
18+
rmSync(p5BuildPath);
19+
}
20+
}
21+
22+
main().then(() => process.exit(0))

src/scripts/utils.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,13 @@ export const repoRootPath = path.join(
2424
/**
2525
* Clone the library repo if it doesn't exist or if it's not recent
2626
* @param localSavePath The path to save the library repo to
27-
* @param [repoUrl] The URL of the library repo to clone, default to p5.js library
27+
* @param repoUrl The URL of the library repo to clone, default to p5.js library
2828
* @returns void
2929
*/
3030
export const cloneLibraryRepo = async (
3131
localSavePath: string,
32-
repoUrl: string = p5RepoUrl,
33-
branch: string = latestRelease,
32+
repoUrl: string,
33+
branch: string,
3434
{ shouldFixAbsolutePathInPreprocessor = true }: {
3535
shouldFixAbsolutePathInPreprocessor?: boolean
3636
} = {}

0 commit comments

Comments
 (0)