2021-01-20 14:43:43 +00:00
|
|
|
import { resolve } from 'path'
|
2021-03-18 14:26:41 +00:00
|
|
|
import { loadNuxt } from './core/load'
|
|
|
|
import { build } from './builder'
|
2021-01-20 14:43:43 +00:00
|
|
|
|
|
|
|
async function _main () {
|
2021-01-20 15:44:52 +00:00
|
|
|
const args = process.argv.splice(2)
|
|
|
|
const cmd = args[0]
|
|
|
|
if (!['dev', 'build'].includes(cmd)) {
|
2021-01-22 21:34:23 +00:00
|
|
|
// eslint-disable-next-line no-console
|
2021-01-20 15:44:52 +00:00
|
|
|
console.error('Usage nuxt dev|build [rootDir]')
|
|
|
|
process.exit(1)
|
|
|
|
}
|
|
|
|
const isDev = cmd === 'dev'
|
|
|
|
const rootDir = resolve(process.cwd(), args[1] || '.')
|
|
|
|
const nuxt = await loadNuxt({ for: isDev ? 'dev' : 'build', rootDir })
|
|
|
|
|
|
|
|
if (isDev) {
|
2021-01-22 20:57:09 +00:00
|
|
|
// https://github.com/nuxt-contrib/listhen
|
|
|
|
await nuxt.server.listen(3000, { name: 'Nuxt' })
|
2021-01-20 15:44:52 +00:00
|
|
|
}
|
|
|
|
|
2021-01-20 14:43:43 +00:00
|
|
|
await build(nuxt)
|
|
|
|
}
|
|
|
|
|
|
|
|
export function main () {
|
|
|
|
_main()
|
|
|
|
.catch((error) => {
|
|
|
|
require('consola').fatal(error)
|
|
|
|
require('exit')(2)
|
|
|
|
})
|
|
|
|
}
|