Skip to content

Commit 364dbc0

Browse files
dlabajDonald Labaj
andauthored
feat: Added code to allow deployment to cloudflare. (#93)
* feat: Added code to allow deployment to cloudflare. * fix: Updated for cloudflare deployment. * feat: Updated the cli to support deploying to cloud flare. --------- Co-authored-by: Donald Labaj <[email protected]>
1 parent c54b585 commit 364dbc0

File tree

7 files changed

+1830
-1417
lines changed

7 files changed

+1830
-1417
lines changed

astro.config.mjs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,15 @@ import { defineConfig } from 'astro/config';
33
import react from '@astrojs/react';
44
import mdx from '@astrojs/mdx';
55

6-
import node from '@astrojs/node';
6+
import cloudflare from '@astrojs/cloudflare';
77

88
// https://astro.build/config
99
export default defineConfig({
1010
integrations: [react(), mdx()],
1111
vite: {
1212
ssr: {
1313
noExternal: ["@patternfly/*", "react-dropzone"],
14+
external: ["node:fs", "node:path"]
1415
},
1516
server: {
1617
fs: {
@@ -19,7 +20,5 @@ export default defineConfig({
1920
}
2021
},
2122

22-
adapter: node({
23-
mode: 'standalone'
24-
})
23+
adapter: cloudflare()
2524
});

cli/cli.ts

Lines changed: 60 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import { createCollectionContent } from './createCollectionContent.js'
77
import { setFsRootDir } from './setFsRootDir.js'
88
import { createConfigFile } from './createConfigFile.js'
99
import { updatePackageFile } from './updatePackageFile.js'
10-
import { getConfig } from './getConfig.js'
10+
import { DocsConfig, getConfig } from './getConfig.js'
1111
import { symLinkConfig } from './symLinkConfig.js'
1212
import { buildPropsData } from './buildPropsData.js'
1313
import { 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

49103
let astroRoot = ''
50104

@@ -99,24 +153,7 @@ program.command('start').action(async () => {
99153
})
100154

101155
program.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

122159
program.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+
143184
program.parse(process.argv)

0 commit comments

Comments
 (0)