11import { cloneLibraryRepo , readFile } from "../utils" ;
22import fs from "fs/promises" ;
3- import { exec } from "child_process" ;
3+ import { exec , execSync } from "child_process" ;
44import path from "path" ;
55import { fileURLToPath } from "url" ;
66import type { ParsedLibraryReference } from "../../../types/parsers.interface" ;
@@ -18,13 +18,16 @@ const yuidocOutputPath = path.join(__dirname, "out")
1818export const parseLibraryReference =
1919 async ( ) : Promise < ParsedLibraryReference | null > => {
2020 // Clone p5.js
21- await cloneLibraryRepo ( localPath ) ;
21+ await cloneLibraryRepo ( localPath , 'https://github.com/Garima3110/p5.js.git' , 'shaders' , { shouldFixAbsolutePathInPreprocessor : false } ) ;
2222 // TODO(dave): let this happen via `npm run docs` in the p5 repo once we
2323 // merge the 2.0 branch
24- await saveYuidocOutput ( 'p5.js' , 'data-p5' , {
24+ await createP5Docs ( 'p5.js' , 'data-p5' )
25+ // If dev
26+ await createP5Build ( 'p5.js' )
27+ /*await saveYuidocOutput('p5.js', 'data-p5', {
2528 flags: `--config ${path.join(__dirname, '../../../yuidoc.json')}`,
2629 inputPath: './src',
27- } ) ;
30+ });*/
2831 const p5Data = await getYuidocOutput ( 'data-p5' ) ;
2932 if ( ! p5Data ) throw new Error ( 'Error generating p5 reference data!' ) ;
3033
@@ -128,6 +131,31 @@ export const saveYuidocOutput = async (
128131 }
129132} ;
130133
134+ export const createP5Docs = async ( inDirName : string , outDirName : string ) => {
135+ execSync ( 'npm install' , {
136+ cwd : path . join ( __dirname , 'in' , inDirName ) ,
137+ } )
138+ execSync ( 'npm run docs' , {
139+ cwd : path . join ( __dirname , 'in' , inDirName ) ,
140+ } )
141+ const outputFilePath = path . join ( yuidocOutputPath , outDirName ) ;
142+ await fs . mkdir ( outputFilePath , { recursive : true } )
143+ await fs . cp (
144+ path . join ( __dirname , 'in' , inDirName , 'docs' , 'reference' , 'data.json' ) ,
145+ path . join ( outputFilePath , 'data.json' ) ,
146+ )
147+ }
148+
149+ export const createP5Build = async ( inDirName : string ) => {
150+ execSync ( 'npm run build' , {
151+ cwd : path . join ( __dirname , 'in' , inDirName )
152+ } )
153+ await fs . cp (
154+ path . join ( __dirname , 'in' , inDirName , 'lib' , 'p5.min.js' ) ,
155+ path . join ( __dirname , '../../../public' , 'p5.min.js' ) ,
156+ )
157+ }
158+
131159export async function combineYuidocData (
132160 inputData : ParsedLibraryReference [ ] ,
133161 outDirName : string
0 commit comments