forked from dai-shi/waku
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: output cloudflare (dai-shi#267)
* add hacky output cloudflare * wip: readme * fix for undefined * fix typo * oh this is hard.. * fix readme * update README
- Loading branch information
Showing
5 changed files
with
111 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
import path from 'node:path'; | ||
import { existsSync, writeFileSync } from 'node:fs'; | ||
|
||
import type { ResolvedConfig } from '../config.js'; | ||
|
||
// XXX this can be very limited. FIXME if anyone has better knowledge. | ||
export const emitCloudflareOutput = async ( | ||
rootDir: string, | ||
config: ResolvedConfig, | ||
ssr: boolean, | ||
) => { | ||
const outputDir = path.resolve('.'); | ||
const relativeRootDir = path.relative(outputDir, rootDir); | ||
const entriesFile = path.join( | ||
relativeRootDir, | ||
config.distDir, | ||
config.entriesJs, | ||
); | ||
const publicDir = path.join( | ||
relativeRootDir, | ||
config.distDir, | ||
config.publicDir, | ||
); | ||
if (!existsSync(path.join(outputDir, 'serve.js'))) { | ||
writeFileSync( | ||
path.join(outputDir, 'serve.js'), | ||
` | ||
import { honoMiddleware } from 'waku'; | ||
import { Hono } from 'hono'; | ||
import { serveStatic } from 'hono/cloudflare-workers'; | ||
const entries = import('./${entriesFile}'); | ||
const app = new Hono(); | ||
app.use('*', honoMiddleware({ entries, ssr: ${ssr} })); | ||
app.use('*', serveStatic({ root: './' })); | ||
export default app; | ||
`, | ||
); | ||
} | ||
if (!existsSync(path.join(outputDir, 'wrangler.toml'))) { | ||
writeFileSync( | ||
path.join(outputDir, 'wrangler.toml'), | ||
` | ||
name = "waku-project" | ||
main = "serve.js" | ||
compatibility_date = "2023-12-06" | ||
[site] | ||
bucket = "./${publicDir}" | ||
`, | ||
); | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters