-
Notifications
You must be signed in to change notification settings - Fork 264
Expand file tree
/
Copy pathbranchTest.ts
More file actions
41 lines (33 loc) · 1.52 KB
/
branchTest.ts
File metadata and controls
41 lines (33 loc) · 1.52 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
import { execSync } from "child_process";
import { existsSync, readFileSync, rmSync, writeFileSync } from "fs";
import path from "path";
import { fileURLToPath } from "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);
}
const repoUrl = match[1];
const branch = match[2];
const envVars = [`PUBLIC_P5_LIBRARY_PATH='/p5.min.js'`, `PUBLIC_P5_WEBGPU_LIBRARY_PATH='/p5.webgpu.js'`, `P5_REPO_URL='${repoUrl}'`, `P5_BRANCH='${branch}'`];
const env = envVars.join(' ');
const envFilePath = path.join(__dirname, '../../.env');
let currentEnv = existsSync(envFilePath) ? readFileSync(envFilePath).toString() : '';
currentEnv = currentEnv
.split('\n')
.filter((line: string) => !line.startsWith('P5_') && !line.startsWith('PUBLIC_P5_'))
.join('\n')
writeFileSync(envFilePath, `${currentEnv }\n${ envVars.join('\n')}`);
// First delete the existing cloned p5 to make sure we clone fresh
const parsedP5Path = path.join(__dirname, "./parsers/in/p5.js/");
if (existsSync(parsedP5Path)) {
rmSync(parsedP5Path, { recursive: true });
}
// Build the reference using the specified environment
execSync(`cross-env ${env} npm run build:reference`, { stdio: "inherit" });
// Run a dev server
execSync(`cross-env ${env} npm run dev`, { stdio: "inherit" });