From fbd592ef8eb703ecb5cd9e4dca64aa080d0ebd98 Mon Sep 17 00:00:00 2001 From: Haoqun Jiang Date: Mon, 2 Sep 2019 17:05:03 +0800 Subject: [PATCH] feat: add `vue outdated` command & make `vue upgrade` interactive (#4497) --- packages/@vue/cli/bin/vue.js | 8 ++++++++ packages/@vue/cli/lib/Upgrader.js | 2 -- packages/@vue/cli/lib/outdated.js | 17 +++++++++++++++++ packages/@vue/cli/lib/upgrade.js | 19 ++++++++++++++++++- 4 files changed, 43 insertions(+), 3 deletions(-) create mode 100644 packages/@vue/cli/lib/outdated.js diff --git a/packages/@vue/cli/bin/vue.js b/packages/@vue/cli/bin/vue.js index c9a73e6cc8..c85fe3c00b 100755 --- a/packages/@vue/cli/bin/vue.js +++ b/packages/@vue/cli/bin/vue.js @@ -166,6 +166,14 @@ program require('../lib/config')(value, cleanArgs(cmd)) }) +program + .command('outdated') + .description('(experimental) check for outdated vue cli service / plugins') + .option('--next', 'Also check for alpha / beta / rc versions when upgrading') + .action((cmd) => { + require('../lib/outdated')(cleanArgs(cmd)) + }) + program .command('upgrade [plugin-name]') .description('(experimental) upgrade vue cli service / plugins') diff --git a/packages/@vue/cli/lib/Upgrader.js b/packages/@vue/cli/lib/Upgrader.js index 5a9cd7577d..3c63829966 100644 --- a/packages/@vue/cli/lib/Upgrader.js +++ b/packages/@vue/cli/lib/Upgrader.js @@ -257,8 +257,6 @@ module.exports = class Upgrader { console.log(' ' + fields.map((x, i) => x.padEnd(pads[i])).join('')) } - console.log(`Run ${chalk.yellow('vue upgrade --all')} to upgrade all the above plugins`) - return upgradable } } diff --git a/packages/@vue/cli/lib/outdated.js b/packages/@vue/cli/lib/outdated.js new file mode 100644 index 0000000000..b315c5fde0 --- /dev/null +++ b/packages/@vue/cli/lib/outdated.js @@ -0,0 +1,17 @@ +const { error } = require('@vue/cli-shared-utils') + +const Upgrader = require('./Upgrader') + +async function outdated (options, context = process.cwd()) { + const upgrader = new Upgrader(context) + return upgrader.checkForUpdates(options.next) +} + +module.exports = (...args) => { + return outdated(...args).catch(err => { + error(err) + if (!process.env.VUE_CLI_TEST) { + process.exit(1) + } + }) +} diff --git a/packages/@vue/cli/lib/upgrade.js b/packages/@vue/cli/lib/upgrade.js index 4ba6725c71..541beb9926 100644 --- a/packages/@vue/cli/lib/upgrade.js +++ b/packages/@vue/cli/lib/upgrade.js @@ -1,3 +1,4 @@ +const inquirer = require('inquirer') const { error } = require('@vue/cli-shared-utils') const Upgrader = require('./Upgrader') @@ -20,7 +21,23 @@ async function upgrade (packageName, options, context = process.cwd()) { return upgrader.upgradeAll(options.next) } - return upgrader.checkForUpdates(options.next) + const upgradable = await upgrader.checkForUpdates(options.next) + if (upgradable) { + const { ok } = await inquirer.prompt([ + { + name: 'ok', + type: 'confirm', + message: 'Continue to upgrade these plugins?', + default: true + } + ]) + + if (ok) { + return upgrader.upgradeAll(options.next) + } + } + + return } return upgrader.upgrade(packageName, options)