Skip to content

Commit

Permalink
feat(upgrade): allow upgrading to nightly release channel (#465)
Browse files Browse the repository at this point in the history
  • Loading branch information
martin-mastermind authored Oct 22, 2024
1 parent 579cbdb commit c028656
Showing 1 changed file with 38 additions and 2 deletions.
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 nightly Nuxt release channel do you want to install? (3.x or 4.x)',
{
type: 'select',
options: ['3.x', '4.x'],
default: '3.x',
},
) as '3.x' | '4.x'

const versions = {
'3.x': '3x',
'4.x': '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

0 comments on commit c028656

Please sign in to comment.