@@ -96,12 +96,14 @@ async function updateTsConfigOutputDirPath(program: Command) {
9696 const tsConfig = JSON . parse ( tsConfigFile )
9797 const formattedOutputDir = join ( absoluteOutputDir , '*' )
9898
99- tsConfig . compilerOptions . paths [ " outputDir/*" ] = [ formattedOutputDir ]
99+ tsConfig . compilerOptions . paths [ ' outputDir/*' ] = [ formattedOutputDir ]
100100
101101 await writeFile ( tsConfigPath , JSON . stringify ( tsConfig , null , 2 ) )
102102
103103 if ( verbose ) {
104- console . log ( `Updated tsconfig.json with outputDir path: ${ formattedOutputDir } ` )
104+ console . log (
105+ `Updated tsconfig.json with outputDir path: ${ formattedOutputDir } ` ,
106+ )
105107 }
106108 } catch ( e : any ) {
107109 console . error ( 'Error updating tsconfig.json with outputDir path:' , e )
@@ -132,7 +134,9 @@ async function initializeApiIndex(program: Command) {
132134 }
133135}
134136
135- async function buildProject ( ) : Promise < DocsConfig | undefined > {
137+ async function buildProject ( program : Command ) : Promise < DocsConfig | undefined > {
138+ const { verbose } = program . opts ( )
139+
136140 if ( ! config ) {
137141 console . error (
138142 'No config found, please run the `setup` command or manually create a pf-docs.config.mjs file' ,
@@ -159,35 +163,40 @@ async function buildProject(): Promise<DocsConfig | undefined> {
159163 outDir : docsOutputDir ,
160164 } )
161165
166+ // copy the apiIndex.json file to the docs directory so it can be served as a static asset
167+ const apiIndexPath = join ( absoluteOutputDir , 'apiIndex.json' )
168+ const docsApiIndexPath = join ( absoluteOutputDir , 'docs' , 'apiIndex.json' )
169+ await copyFile ( apiIndexPath , docsApiIndexPath )
170+
171+ if ( verbose ) {
172+ console . log ( 'Copied apiIndex.json to docs directory' )
173+ }
174+
162175 return config
163176}
164177
165- async function deploy ( ) {
166- const { verbose } = program . opts ( )
178+ async function deploy ( program : Command ) {
179+ const { verbose, dryRun } = program . opts ( )
167180
168181 if ( verbose ) {
169182 console . log ( 'Starting Cloudflare deployment...' )
170183 }
171184
185+ if ( dryRun ) {
186+ console . log ( 'Dry run mode enabled, skipping deployment' )
187+ return
188+ }
189+
172190 try {
173- // First build the project
174- const config = await buildProject ( )
175- if ( config ) {
176- if ( verbose ) {
177- console . log ( 'Build complete, deploying to Cloudflare...' )
178- }
179-
180- // Deploy using Wrangler
181- const { execSync } = await import ( 'child_process' )
182- const outputPath = join ( absoluteOutputDir , 'docs' )
183-
184- execSync ( `npx wrangler pages deploy ${ outputPath } ` , {
185- stdio : 'inherit' ,
186- cwd : currentDir ,
187- } )
188-
189- console . log ( 'Successfully deployed to Cloudflare Pages!' )
190- }
191+ // Deploy using Wrangler
192+ const { execSync } = await import ( 'child_process' )
193+
194+ execSync ( `wrangler pages deploy` , {
195+ stdio : 'inherit' ,
196+ cwd : currentDir ,
197+ } )
198+
199+ console . log ( 'Successfully deployed to Cloudflare Pages!' )
191200 } catch ( error ) {
192201 console . error ( 'Deployment failed:' , error )
193202 process . exit ( 1 )
@@ -199,6 +208,7 @@ program.name('pf-doc-core')
199208
200209program . option ( '--verbose' , 'verbose mode' , false )
201210program . option ( '--props' , 'generate props data' , false )
211+ program . option ( '--dry-run' , 'dry run mode' , false )
202212
203213program . command ( 'setup' ) . action ( async ( ) => {
204214 await Promise . all ( [
@@ -232,7 +242,7 @@ program.command('start').action(async () => {
232242} )
233243
234244program . command ( 'build' ) . action ( async ( ) => {
235- await buildProject ( )
245+ await buildProject ( program )
236246} )
237247
238248program . command ( 'generate-props' ) . action ( async ( ) => {
@@ -257,7 +267,7 @@ program
257267 } )
258268
259269program . command ( 'deploy' ) . action ( async ( ) => {
260- await deploy ( )
270+ await deploy ( program )
261271} )
262272
263273program . parse ( process . argv )
0 commit comments