Skip to content

Commit f89448b

Browse files
committed
Add script
1 parent b37511d commit f89448b

File tree

5 files changed

+53
-18
lines changed

5 files changed

+53
-18
lines changed

.gitignore

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,4 +23,7 @@ pnpm-debug.log*
2323
temp/*
2424
in/
2525
out/
26-
translator/
26+
translator/
27+
28+
# Don't commit custom dev builds
29+
public/p5.min.js

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@
1515
"build:contributors": "tsx ./src/scripts/builders/people.ts",
1616
"build:reference": "tsx ./src/scripts/builders/reference.ts",
1717
"build:search": "tsx ./src/scripts/builders/search.ts",
18-
"build:p5-version": "tsx ./src/scripts/p5-version.ts"
18+
"build:p5-version": "tsx ./src/scripts/p5-version.ts",
19+
"custom:dev": "tsx ./src/scripts/branchTest.ts"
1920
},
2021
"dependencies": {
2122
"@astrojs/check": "^0.5.5",

src/content/reference/config.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@ export const categories = [
2626
const paramSchema = z.object({
2727
name: z.string(),
2828
description: z.string(),
29-
type: z.string(),
30-
optional: z.boolean().optional(),
29+
type: z.string().optional(),
30+
optional: z.coerce.boolean().optional(),
3131
});
3232

3333
const returnSchema = z.object({
@@ -41,15 +41,15 @@ const exampleSchema = z.string();
4141
* Method schema for methods associated with a class in the Reference collection.
4242
*/
4343
const methodSchema = z.object({
44-
description: z.string(),
44+
description: z.string().optional(),
4545
path: z.string(),
4646
});
4747

4848
/**
4949
* Property schema for properties associated with a class in the Reference collection.
5050
*/
5151
const propertySchema = z.object({
52-
description: z.string(),
52+
description: z.string().optional(),
5353
path: z.string(),
5454
});
5555

@@ -78,6 +78,7 @@ export const referenceSchema = z.object({
7878
properties: z.record(propertySchema).optional(),
7979
isConstructor: z
8080
.boolean()
81+
.or(z.number().transform((n: number) => !!n))
8182
.or(z.literal("true").transform(() => true))
8283
.or(z.literal("false").transform(() => false))
8384
.optional(),

src/scripts/branchTest.ts

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import { execSync } from "child_process"
2+
import { existsSync, rmSync } from "fs"
3+
import path from "path"
4+
5+
const url = process.argv[2]
6+
const match = /^(.+)#(.+)$/.exec(url)
7+
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)
10+
}
11+
12+
const repoUrl = match[1]
13+
const branch = match[2]
14+
15+
const env = `P5_LIBRARY_PATH='/p5.min.js' P5_REPO_URL='${repoUrl}' P5_BRANCH='${branch}'`
16+
17+
// First delete the existing cloned p5 to make sure we clone fresh
18+
const parsedP5Path = path.join(__dirname, './parsers/in/p5.js/')
19+
if (existsSync(parsedP5Path)) {
20+
rmSync(parsedP5Path, { recursive: true })
21+
}
22+
23+
// Build the reference using the specified environment
24+
execSync(`${env} npm run build:reference`)
25+
26+
// Run a dev server
27+
execSync(`${env} npm run dev`)

src/scripts/parsers/reference.ts

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
1-
import { cloneLibraryRepo, readFile } from "../utils";
1+
import { cloneLibraryRepo, p5RepoUrl, readFile } from "../utils";
22
import fs from "fs/promises";
33
import { exec, execSync } from "child_process";
44
import path from "path";
55
import { fileURLToPath } from "url";
66
import type { ParsedLibraryReference } from "../../../types/parsers.interface";
7+
import { p5Version } from "@/src/globals/p5-version";
78

89
// Derive the directory name (__dirname equivalent) in ES Module scope
910
const __dirname = path.dirname(fileURLToPath(import.meta.url));
@@ -18,16 +19,18 @@ const yuidocOutputPath = path.join(__dirname, "out")
1819
export const parseLibraryReference =
1920
async (): Promise<ParsedLibraryReference | null> => {
2021
// Clone p5.js
21-
await cloneLibraryRepo(localPath, 'https://github.com/Garima3110/p5.js.git', 'shaders', { shouldFixAbsolutePathInPreprocessor: false });
22-
// TODO(dave): let this happen via `npm run docs` in the p5 repo once we
23-
// merge the 2.0 branch
22+
await cloneLibraryRepo(localPath, process.env.P5_REPO_URL || p5RepoUrl, process.env.P5_BRANCH || p5Version, { shouldFixAbsolutePathInPreprocessor: false });
23+
24+
// Install dependencies and build docs in the p5 repo
2425
await createP5Docs('p5.js', 'data-p5')
25-
// If dev
26-
await createP5Build('p5.js')
27-
/*await saveYuidocOutput('p5.js', 'data-p5', {
28-
flags: `--config ${path.join(__dirname, '../../../yuidoc.json')}`,
29-
inputPath: './src',
30-
});*/
26+
27+
// If we're using a custom build of p5 instead of a public release, create
28+
// a build and copy it to the specified path
29+
if (process.env.P5_LIBRARY_PATH) {
30+
await createP5Build('p5.js', '../../../public' + process.env.P5_LIBRARY_PATH)
31+
}
32+
33+
// Copy the reference output so we can process it
3134
const p5Data = await getYuidocOutput('data-p5');
3235
if (!p5Data) throw new Error('Error generating p5 reference data!');
3336

@@ -146,13 +149,13 @@ export const createP5Docs = async (inDirName: string, outDirName: string) => {
146149
)
147150
}
148151

149-
export const createP5Build = async (inDirName: string) => {
152+
export const createP5Build = async (inDirName: string, outPath: string) => {
150153
execSync('npm run build', {
151154
cwd: path.join(__dirname, 'in', inDirName)
152155
})
153156
await fs.cp(
154157
path.join(__dirname, 'in', inDirName, 'lib', 'p5.min.js'),
155-
path.join(__dirname, '../../../public', 'p5.min.js'),
158+
path.join(__dirname, outPath),
156159
)
157160
}
158161

0 commit comments

Comments
 (0)