Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(init): add --nightly flag #650

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 23 additions & 3 deletions src/commands/init.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'

Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -96,6 +100,22 @@ export default defineCommand({
process.exit(1)
}

if (ctx.args.nightly) {
const nightlyNuxtVersion = 'npm:nuxt-nightly@latest'
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what about fetching the latest version from npm? latest is often poorly updated (i.e. not updated) by package managers

also, there are currently two nightly channels - the 3x and latest (4x) ones. would it be worth using --channel for this purpose, and maybe also --nightly which defaults to the latest 3x tag?

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',
Expand Down
Loading