diff --git a/src/commands/init.ts b/src/commands/init.ts index 1baf9ef1..ae200ca1 100644 --- a/src/commands/init.ts +++ b/src/commands/init.ts @@ -2,13 +2,13 @@ import type { DownloadTemplateResult } from 'giget' import type { PackageManagerName } from 'nypm' import process from 'node:process' - import { defineCommand } from 'citty' import { downloadTemplate, startShell } from 'giget' import { installDependencies } from 'nypm' -import { relative, resolve } from 'pathe' -import { x } from 'tinyexec' +import { join, relative, resolve } from 'pathe' +import { readPackageJSON, writePackageJSON } from 'pkg-types' +import { x } from 'tinyexec' import { logger } from '../utils/logger' import { cwdArgs } from './_shared' @@ -63,6 +63,10 @@ export default defineCommand({ type: 'string', description: 'Package manager choice (npm, pnpm, yarn, bun)', }, + nightly: { + type: 'boolean', + description: 'Use nightly release channel instead of stable', + }, }, async run(ctx) { const cwd = resolve(ctx.args.cwd) @@ -96,6 +100,22 @@ export default defineCommand({ process.exit(1) } + if (ctx.args.nightly) { + const nightlyNuxtVersion = 'npm:nuxt-nightly@latest' + const packageJsonPath = resolve(cwd, ctx.args.dir) + + const packageJson = await readPackageJSON(packageJsonPath) + + if (packageJson.dependencies && 'nuxt' in packageJson.dependencies) { + packageJson.dependencies.nuxt = nightlyNuxtVersion + } + else if (packageJson.devDependencies && 'nuxt' in packageJson.devDependencies) { + packageJson.devDependencies.nuxt = nightlyNuxtVersion + } + + await writePackageJSON(join(packageJsonPath, 'package.json'), packageJson) + } + // Resolve package manager const packageManagerOptions: PackageManagerName[] = [ 'npm',