2021-10-29 10:42:55 +00:00
|
|
|
import execa from 'execa'
|
2021-10-12 08:52:28 +00:00
|
|
|
import { resolve } from 'pathe'
|
|
|
|
import { isNuxt3 } from '@nuxt/kit'
|
|
|
|
|
2021-10-13 10:44:54 +00:00
|
|
|
import { loadKit } from '../utils/kit'
|
2021-10-12 08:52:28 +00:00
|
|
|
import { defineNuxtCommand } from './index'
|
|
|
|
|
|
|
|
export default defineNuxtCommand({
|
|
|
|
meta: {
|
|
|
|
name: 'generate',
|
|
|
|
usage: 'npx nuxi generate [rootDir]',
|
|
|
|
description: ''
|
|
|
|
},
|
|
|
|
async invoke (args) {
|
|
|
|
process.env.NODE_ENV = process.env.NODE_ENV || 'production'
|
|
|
|
const rootDir = resolve(args._[0] || '.')
|
|
|
|
|
2021-10-13 10:44:54 +00:00
|
|
|
const { loadNuxt } = await loadKit(rootDir)
|
2021-10-12 08:52:28 +00:00
|
|
|
const nuxt = await loadNuxt({ rootDir })
|
|
|
|
|
|
|
|
if (isNuxt3(nuxt)) {
|
|
|
|
throw new Error('`nuxt generate` is not supported in Nuxt 3. Please follow this RFC: https://git.io/JKfvx')
|
|
|
|
} else {
|
2021-10-29 10:42:55 +00:00
|
|
|
// Forwards argv to `nuxt generate`
|
|
|
|
await execa('npx nuxt', process.argv.slice(2), { stdio: 'inherit' })
|
2021-10-12 08:52:28 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|