2022-01-24 13:28:47 +00:00
|
|
|
import { buildNuxt } from '@nuxt/kit'
|
|
|
|
import { relative, resolve } from 'pathe'
|
|
|
|
import consola from 'consola'
|
2021-11-15 15:55:32 +00:00
|
|
|
import { clearDir } from '../utils/fs'
|
2021-10-13 10:44:54 +00:00
|
|
|
import { loadKit } from '../utils/kit'
|
2021-10-07 13:53:31 +00:00
|
|
|
import { writeTypes } from '../utils/prepare'
|
2021-07-26 14:46:19 +00:00
|
|
|
import { defineNuxtCommand } from './index'
|
|
|
|
|
|
|
|
export default defineNuxtCommand({
|
|
|
|
meta: {
|
|
|
|
name: 'prepare',
|
2021-08-10 17:37:03 +00:00
|
|
|
usage: 'npx nuxi prepare',
|
2021-07-26 14:46:19 +00:00
|
|
|
description: 'Prepare nuxt for development/build'
|
|
|
|
},
|
|
|
|
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-11-16 16:10:28 +00:00
|
|
|
const nuxt = await loadNuxt({ rootDir, config: { _prepare: true } })
|
2021-11-15 15:55:32 +00:00
|
|
|
await clearDir(nuxt.options.buildDir)
|
2021-07-26 14:46:19 +00:00
|
|
|
|
2022-01-24 13:28:47 +00:00
|
|
|
await buildNuxt(nuxt)
|
2021-10-07 13:53:31 +00:00
|
|
|
await writeTypes(nuxt)
|
2022-01-24 13:28:47 +00:00
|
|
|
consola.success('Types generated in', relative(process.cwd(), nuxt.options.buildDir))
|
2021-07-26 14:46:19 +00:00
|
|
|
}
|
|
|
|
})
|