2021-09-27 12:49:36 +00:00
|
|
|
import { resolve } from 'pathe'
|
2020-11-20 00:16:31 +00:00
|
|
|
import consola from 'consola'
|
2021-09-28 11:30:54 +00:00
|
|
|
import { extendPreset, writeFile, prettyPath, hl } from '../utils'
|
2021-01-22 19:55:59 +00:00
|
|
|
import { NitroContext, NitroPreset } from '../context'
|
2020-11-20 00:16:31 +00:00
|
|
|
import { worker } from './worker'
|
|
|
|
|
2021-01-22 19:55:59 +00:00
|
|
|
export const cloudflare: NitroPreset = extendPreset(worker, {
|
2020-11-20 00:16:31 +00:00
|
|
|
entry: '{{ _internal.runtimeDir }}/entries/cloudflare',
|
|
|
|
ignore: [
|
|
|
|
'wrangler.toml'
|
|
|
|
],
|
|
|
|
hooks: {
|
2021-01-22 19:55:59 +00:00
|
|
|
async 'nitro:compiled' ({ output, _nuxt }: NitroContext) {
|
2021-07-15 09:38:06 +00:00
|
|
|
await writeFile(resolve(output.dir, 'package.json'), JSON.stringify({ private: true, main: './server/index.mjs' }, null, 2))
|
2020-11-20 00:16:31 +00:00
|
|
|
await writeFile(resolve(output.dir, 'package-lock.json'), JSON.stringify({ lockfileVersion: 1 }, null, 2))
|
2020-11-20 12:14:16 +00:00
|
|
|
let inDir = prettyPath(_nuxt.rootDir)
|
|
|
|
if (inDir) {
|
|
|
|
inDir = 'in ' + inDir
|
|
|
|
}
|
2021-09-28 11:30:54 +00:00
|
|
|
consola.success('Ready to run', hl('npx wrangler publish ' + inDir), 'or', hl('npx miniflare ' + prettyPath(output.serverDir) + '/index.mjs --site ' + prettyPath(output.publicDir)), 'for local testing')
|
2020-11-20 00:16:31 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|