3434 . replace ( 'file://' , '' )
3535} catch ( e : any ) {
3636 if ( e . code === 'ERR_MODULE_NOT_FOUND' ) {
37+ console . log ( '@patternfly/patternfly-doc-core not found, using current directory as astroRoot' )
3738 astroRoot = process . cwd ( )
3839 } else {
3940 console . error ( 'Error resolving astroRoot' , e )
@@ -87,29 +88,33 @@ async function transformMDContentToMDX() {
8788 }
8889}
8990
90- async function initializeApiIndex ( ) {
91+ async function initializeApiIndex ( program : Command ) {
92+ const { verbose } = program . opts ( )
9193 const templateIndexPath = join ( astroRoot , 'cli' , 'templates' , 'apiIndex.json' )
92- const targetIndexPath = join ( astroRoot , 'src' , 'apiIndex.json' )
93-
94+ const targetIndexPath = join ( absoluteOutputDir , 'apiIndex.json' )
9495 const indexExists = await fileExists ( targetIndexPath )
9596
9697 // early return if the file exists from a previous build
9798 if ( indexExists ) {
98- console . log ( 'apiIndex.json already exists, skipping initialization' )
99+ if ( verbose ) {
100+ console . log ( 'apiIndex.json already exists, skipping initialization' )
101+ }
99102 return
100103 }
101104
102105 try {
103106 await copyFile ( templateIndexPath , targetIndexPath )
104- console . log ( 'Initialized apiIndex.json' )
107+ if ( verbose ) {
108+ console . log ( 'Initialized apiIndex.json' )
109+ }
105110 } catch ( e : any ) {
106111 console . error ( 'Error copying apiIndex.json template:' , e )
107112 }
108113}
109114
110- async function buildProject ( ) : Promise < DocsConfig | undefined > {
111- await updateContent ( program )
112- await generateProps ( program , true )
115+ async function buildProject ( program : Command ) : Promise < DocsConfig | undefined > {
116+ const { verbose } = program . opts ( )
117+
113118 if ( ! config ) {
114119 console . error (
115120 'No config found, please run the `setup` command or manually create a pf-docs.config.mjs file' ,
@@ -123,44 +128,57 @@ async function buildProject(): Promise<DocsConfig | undefined> {
123128 )
124129 return config
125130 }
126-
127- await initializeApiIndex ( )
131+ await updateContent ( program )
132+ await generateProps ( program , true )
133+ await initializeApiIndex ( program )
128134 await transformMDContentToMDX ( )
129135
130- build ( {
136+ const docsOutputDir = join ( absoluteOutputDir , 'docs' )
137+
138+ await build ( {
131139 root : astroRoot ,
132- outDir : join ( absoluteOutputDir , 'docs' ) ,
140+ outDir : docsOutputDir ,
133141 } )
134142
143+ // copy the apiIndex.json file to the docs directory so it can be served as a static asset
144+ try {
145+ const apiIndexPath = join ( absoluteOutputDir , 'apiIndex.json' )
146+ const docsApiIndexPath = join ( absoluteOutputDir , 'docs' , 'apiIndex.json' )
147+ await copyFile ( apiIndexPath , docsApiIndexPath )
148+
149+ if ( verbose ) {
150+ console . log ( 'Copied apiIndex.json to docs directory' )
151+ }
152+ } catch ( error ) {
153+ console . error ( 'Failed to copy apiIndex.json to docs directory:' , error )
154+ throw error
155+ }
156+
135157 return config
136158}
137159
138- async function deploy ( ) {
139- const { verbose } = program . opts ( )
160+ async function deploy ( program : Command ) {
161+ const { verbose, dryRun } = program . opts ( )
140162
141163 if ( verbose ) {
142164 console . log ( 'Starting Cloudflare deployment...' )
143165 }
144166
167+ if ( dryRun ) {
168+ console . log ( 'Dry run mode enabled, skipping deployment' )
169+ return
170+ }
171+
145172 try {
146- // First build the project
147- const config = await buildProject ( )
148- if ( config ) {
149- if ( verbose ) {
150- console . log ( 'Build complete, deploying to Cloudflare...' )
151- }
152-
153- // Deploy using Wrangler
154- const { execSync } = await import ( 'child_process' )
155- const outputPath = join ( absoluteOutputDir , 'docs' )
156-
157- execSync ( `npx wrangler pages deploy ${ outputPath } ` , {
158- stdio : 'inherit' ,
159- cwd : currentDir ,
160- } )
161-
162- console . log ( 'Successfully deployed to Cloudflare Pages!' )
163- }
173+ // Deploy using Wrangler
174+ const { execSync } = await import ( 'child_process' )
175+
176+ execSync ( `wrangler pages deploy` , {
177+ stdio : 'inherit' ,
178+ cwd : currentDir ,
179+ } )
180+
181+ console . log ( 'Successfully deployed to Cloudflare Pages!' )
164182 } catch ( error ) {
165183 console . error ( 'Deployment failed:' , error )
166184 process . exit ( 1 )
@@ -172,6 +190,7 @@ program.name('pf-doc-core')
172190
173191program . option ( '--verbose' , 'verbose mode' , false )
174192program . option ( '--props' , 'generate props data' , false )
193+ program . option ( '--dry-run' , 'dry run mode' , false )
175194
176195program . command ( 'setup' ) . action ( async ( ) => {
177196 await Promise . all ( [
@@ -194,7 +213,7 @@ program.command('init').action(async () => {
194213
195214program . command ( 'start' ) . action ( async ( ) => {
196215 await updateContent ( program )
197- await initializeApiIndex ( )
216+ await initializeApiIndex ( program )
198217
199218 // if a props file hasn't been generated yet, but the consumer has propsData, it will cause a runtime error so to
200219 // prevent that we're just creating a props file regardless of what they say if one doesn't exist yet
@@ -204,7 +223,7 @@ program.command('start').action(async () => {
204223} )
205224
206225program . command ( 'build' ) . action ( async ( ) => {
207- await buildProject ( )
226+ await buildProject ( program )
208227} )
209228
210229program . command ( 'generate-props' ) . action ( async ( ) => {
@@ -229,7 +248,7 @@ program
229248 } )
230249
231250program . command ( 'deploy' ) . action ( async ( ) => {
232- await deploy ( )
251+ await deploy ( program )
233252} )
234253
235254program . parse ( process . argv )
0 commit comments