@@ -7,7 +7,7 @@ import { createCollectionContent } from './createCollectionContent.js'
77import { setFsRootDir } from './setFsRootDir.js'
88import { createConfigFile } from './createConfigFile.js'
99import { updatePackageFile } from './updatePackageFile.js'
10- import { getConfig } from './getConfig.js'
10+ import { DocsConfig , getConfig } from './getConfig.js'
1111import { symLinkConfig } from './symLinkConfig.js'
1212import { buildPropsData } from './buildPropsData.js'
1313import { hasFile } from './hasFile.js'
@@ -45,6 +45,60 @@ async function generateProps(program: Command, forceProps: boolean = false) {
4545 verbose ,
4646 )
4747}
48+ async function buildProject ( ) : Promise < DocsConfig | undefined > {
49+ updateContent ( program )
50+ await generateProps ( program , true )
51+ const config = await getConfig ( `${ currentDir } /pf-docs.config.mjs` )
52+ if ( ! config ) {
53+ console . error (
54+ 'No config found, please run the `setup` command or manually create a pf-docs.config.mjs file' ,
55+ )
56+ return config ;
57+ }
58+
59+ if ( ! config . outputDir ) {
60+ console . error (
61+ "No outputDir found in config file, an output directory must be defined in your config file e.g. 'dist'" ,
62+ )
63+ return config ;
64+ }
65+
66+ build ( { root : astroRoot , outDir : join ( currentDir , config . outputDir ) } )
67+
68+ return config ;
69+ }
70+
71+ async function deploy ( ) {
72+ const { verbose } = program . opts ( )
73+
74+ if ( verbose ) {
75+ console . log ( 'Starting Cloudflare deployment...' )
76+ }
77+
78+ try {
79+ // First build the project
80+ const config = await buildProject ( ) ;
81+ if ( config ) {
82+ if ( verbose ) {
83+ console . log ( 'Build complete, deploying to Cloudflare...' )
84+ }
85+
86+ // Deploy using Wrangler
87+ const { execSync } = await import ( 'child_process' )
88+ const outputPath = join ( currentDir , config . outputDir )
89+
90+ execSync ( `npx wrangler pages deploy ${ outputPath } ` , {
91+ stdio : 'inherit' ,
92+ cwd : currentDir
93+ } )
94+
95+ console . log ( 'Successfully deployed to Cloudflare Pages!' )
96+ }
97+ } catch ( error ) {
98+ console . error ( 'Deployment failed:' , error )
99+ process . exit ( 1 )
100+ }
101+ }
48102
49103let astroRoot = ''
50104
@@ -99,24 +153,7 @@ program.command('start').action(async () => {
99153} )
100154
101155program . command ( 'build' ) . action ( async ( ) => {
102- updateContent ( program )
103- await generateProps ( program , true )
104- const config = await getConfig ( `${ currentDir } /pf-docs.config.mjs` )
105- if ( ! config ) {
106- console . error (
107- 'No config found, please run the `setup` command or manually create a pf-docs.config.mjs file' ,
108- )
109- return
110- }
111-
112- if ( ! config . outputDir ) {
113- console . error (
114- "No outputDir found in config file, an output directory must be defined in your config file e.g. 'dist'" ,
115- )
116- return
117- }
118-
119- build ( { root : astroRoot , outDir : join ( currentDir , config . outputDir ) } )
156+ await buildProject ( ) ;
120157} )
121158
122159program . command ( 'generate-props' ) . action ( async ( ) => {
@@ -140,4 +177,8 @@ program
140177 await convertToMDX ( globPath )
141178 } )
142179
180+ program . command ( 'deploy' ) . action ( async ( ) => {
181+ await deploy ( )
182+ } )
183+
143184program . parse ( process . argv )
0 commit comments