1- import { cloneLibraryRepo , readFile } from "../utils" ;
1+ import { cloneLibraryRepo , p5RepoUrl , readFile } from "../utils" ;
22import fs from "fs/promises" ;
33import { exec , execSync } from "child_process" ;
44import path from "path" ;
55import { fileURLToPath } from "url" ;
66import 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
910const __dirname = path . dirname ( fileURLToPath ( import . meta. url ) ) ;
@@ -18,16 +19,18 @@ const yuidocOutputPath = path.join(__dirname, "out")
1819export 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