Skip to content

Commit

Permalink
Add reset script
Browse files Browse the repository at this point in the history
  • Loading branch information
davepagurek committed Nov 1, 2024
1 parent f89448b commit 4ea66f5
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 19 deletions.
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@
"build:reference": "tsx ./src/scripts/builders/reference.ts",
"build:search": "tsx ./src/scripts/builders/search.ts",
"build:p5-version": "tsx ./src/scripts/p5-version.ts",
"custom:dev": "tsx ./src/scripts/branchTest.ts"
"custom:dev": "tsx ./src/scripts/branchTest.ts",
"custom:cleanup": "tsx ./src/scripts/resetBranchTest.ts"
},
"dependencies": {
"@astrojs/check": "^0.5.5",
Expand Down
33 changes: 19 additions & 14 deletions src/scripts/branchTest.ts
Original file line number Diff line number Diff line change
@@ -1,27 +1,32 @@
import { execSync } from "child_process"
import { existsSync, rmSync } from "fs"
import path from "path"
import { execSync } from "child_process";
import { existsSync, rmSync } from "fs";
import path from "path";
import { fileURLToPath } from "url";

const url = process.argv[2]
const match = /^(.+)#(.+)$/.exec(url)
const __dirname = path.dirname(fileURLToPath(import.meta.url));

const url = process.argv[2];
const match = /^(.+)#(.+)$/.exec(url);
if (!match) {
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`)
process.exit(1)
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`,
);
process.exit(1);
}

const repoUrl = match[1]
const branch = match[2]
const repoUrl = match[1];
const branch = match[2];

const env = `P5_LIBRARY_PATH='/p5.min.js' P5_REPO_URL='${repoUrl}' P5_BRANCH='${branch}'`
const env = `P5_LIBRARY_PATH='/p5.min.js' P5_REPO_URL='${repoUrl}' P5_BRANCH='${branch}'`;

// First delete the existing cloned p5 to make sure we clone fresh
const parsedP5Path = path.join(__dirname, './parsers/in/p5.js/')
const parsedP5Path = path.join(__dirname, "./parsers/in/p5.js/");
if (existsSync(parsedP5Path)) {
rmSync(parsedP5Path, { recursive: true })
rmSync(parsedP5Path, { recursive: true });
}

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

// Run a dev server
execSync(`${env} npm run dev`)
execSync(`${env} npm run dev`, { stdio: "inherit" });
7 changes: 6 additions & 1 deletion src/scripts/parsers/reference.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,12 @@ const yuidocOutputPath = path.join(__dirname, "out")
export const parseLibraryReference =
async (): Promise<ParsedLibraryReference | null> => {
// Clone p5.js
await cloneLibraryRepo(localPath, process.env.P5_REPO_URL || p5RepoUrl, process.env.P5_BRANCH || p5Version, { shouldFixAbsolutePathInPreprocessor: false });
await cloneLibraryRepo(
localPath,
process.env.P5_REPO_URL || p5RepoUrl,
process.env.P5_BRANCH || p5Version,
{ shouldFixAbsolutePathInPreprocessor: false },
);

// Install dependencies and build docs in the p5 repo
await createP5Docs('p5.js', 'data-p5')
Expand Down
22 changes: 22 additions & 0 deletions src/scripts/resetBranchTest.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { fileURLToPath } from "url";
import path from "path";
import { existsSync, rmSync } from "fs";
import simpleGit from "simple-git";

async function main() {
const __dirname = path.dirname(fileURLToPath(import.meta.url));

const referencePath = path.join(__dirname, '../content/reference/');
const dataPath = path.join(__dirname, '../../public/reference/data.json')
rmSync(referencePath, { recursive: true });

const git = simpleGit();
await git.checkout('HEAD', [referencePath, dataPath]);

const p5BuildPath = path.join(__dirname, '../../public/p5.min.js');
if (existsSync(p5BuildPath)) {
rmSync(p5BuildPath);
}
}

main().then(() => process.exit(0))
6 changes: 3 additions & 3 deletions src/scripts/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,13 @@ export const repoRootPath = path.join(
/**
* Clone the library repo if it doesn't exist or if it's not recent
* @param localSavePath The path to save the library repo to
* @param [repoUrl] The URL of the library repo to clone, default to p5.js library
* @param repoUrl The URL of the library repo to clone, default to p5.js library
* @returns void
*/
export const cloneLibraryRepo = async (
localSavePath: string,
repoUrl: string = p5RepoUrl,
branch: string = latestRelease,
repoUrl: string,
branch: string,
{ shouldFixAbsolutePathInPreprocessor = true }: {
shouldFixAbsolutePathInPreprocessor?: boolean
} = {}
Expand Down

0 comments on commit 4ea66f5

Please sign in to comment.