Skip to content

chore: better upgrade messages #3926

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

Merged
merged 3 commits into from
Oct 11, 2019
Merged
Show file tree
Hide file tree
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
53 changes: 47 additions & 6 deletions packages/@vue/cli/lib/util/clearConsole.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,29 @@
const chalk = require('chalk')
const execa = require('execa')
const semver = require('semver')
const getVersions = require('./getVersions')
const { clearConsole } = require('@vue/cli-shared-utils')
const { clearConsole, hasYarn, hasPnpm3OrLater } = require('@vue/cli-shared-utils')

async function getInstallationCommand () {
if (hasYarn()) {
const { stdout: yarnGlobalDir } = await execa('yarn', ['global', 'dir'])
if (__dirname.includes(yarnGlobalDir)) {
return 'yarn global add'
}
}

if (hasPnpm3OrLater()) {
const { stdout: pnpmGlobalPrefix } = await execa('pnpm', ['config', 'get', 'prefix'])
if (__dirname.includes(pnpmGlobalPrefix) && __dirname.includes('pnpm-global')) {
return `pnpm i -g`
}
}

const { stdout: npmGlobalPrefix } = await execa('npm', ['config', 'get', 'prefix'])
if (__dirname.includes(npmGlobalPrefix)) {
return `npm i -g`
}
}

exports.generateTitle = async function (checkUpdate) {
const { current, latest } = await getVersions()
Expand All @@ -16,12 +38,31 @@ exports.generateTitle = async function (checkUpdate) {
}
if (checkUpdate && semver.gt(latest, current)) {
if (process.env.VUE_CLI_API_MODE) {
title += chalk.green(` 🌟️ Update available: ${latest}`)
title += chalk.green(` 🌟️ New version available: ${latest}`)
} else {
title += chalk.green(`
┌────────────────────${`─`.repeat(latest.length)}──┐
│ Update available: ${latest} │
└────────────────────${`─`.repeat(latest.length)}──┘`)
let upgradeMessage = `New version available ${chalk.magenta(current)} → ${chalk.green(latest)}`

try {
const command = await getInstallationCommand()
let name = require('../../package.json').name
if (semver.prerelease(latest)) {
name += '@next'
}

if (command) {
upgradeMessage +=
`\nRun ${chalk.yellow(`${command} ${name}`)} to update!`
}
} catch (e) {}

const upgradeBox = require('boxen')(upgradeMessage, {
align: 'center',
borderColor: 'green',
dimBorder: true,
padding: 1
})

title += `\n${upgradeBox}\n`
}
}

Expand Down
1 change: 1 addition & 0 deletions packages/@vue/cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
"@vue/cli-ui": "^4.0.0-rc.7",
"@vue/cli-ui-addon-webpack": "^4.0.0-rc.7",
"@vue/cli-ui-addon-widgets": "^4.0.0-rc.7",
"boxen": "^4.1.0",
"chalk": "^2.4.1",
"cmd-shim": "^2.0.2",
"commander": "^2.20.0",
Expand Down