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: Add ability to select between nightly and stable version (#55) #465

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
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
40 changes: 38 additions & 2 deletions src/commands/upgrade.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,33 @@ function hasPnpmWorkspaceFile(cwd: string): boolean {
return existsSync(pnpmWorkspaceFilePath)
}

async function getNightlyVersion(): Promise<{ npmVersion: string, nuxtVersion: string }> {
const nuxtVersion = await consola.prompt(
'Which version of nighlty Nuxt do you want to install? (3 or 4)',
{
type: 'select',
options: ['3', '4'],
default: '3',
},
) as '3' | '4'

const versions = {
3: '3.x',
4: 'latest',
}
const npmVersion = `nuxt@npm:nuxt-nightly@${versions[nuxtVersion]}`

return { npmVersion, nuxtVersion }
}

async function getRequiredNewVersion(channel: string): Promise<{ npmVersion: string, nuxtVersion: string }> {
if (channel === 'nightly') {
return getNightlyVersion()
}

return { npmVersion: 'nuxt@latest', nuxtVersion: '3' }
}

export default defineCommand({
meta: {
name: 'upgrade',
Expand All @@ -62,6 +89,12 @@ export default defineCommand({
alias: 'f',
description: 'Force upgrade to recreate lockfile and node_modules',
},
channel: {
type: 'string',
alias: 'ch',
default: 'stable',
description: 'Specify a channel to install from (nightly or stable)',
},
},
async run(ctx) {
const cwd = resolve(ctx.args.cwd || ctx.args.rootDir || '.')
Expand Down Expand Up @@ -109,14 +142,17 @@ export default defineCommand({
}

// Install latest version
consola.info('Installing latest Nuxt 3 release...')
const { npmVersion, nuxtVersion } = await getRequiredNewVersion(ctx.args.channel)

const versionType = ctx.args.channel === 'nightly' ? 'nightly' : 'latest stable'
consola.info(`Installing ${versionType} Nuxt ${nuxtVersion} release...`)

const command = [
packageManager,
packageManager === 'yarn' ? 'add' : 'install',
nuxtDependencyType === 'devDependencies' ? '-D' : '',
packageManager === 'pnpm' && hasPnpmWorkspaceFile(cwd) ? '-w' : '',
'nuxt',
npmVersion,
].filter(Boolean).join(' ')

execSync(command, { stdio: 'inherit', cwd })
Expand Down