upgrade.js 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. const inquirer = require('inquirer')
  2. const { error } = require('@vue/cli-shared-utils')
  3. const Upgrader = require('./Upgrader')
  4. const confirmIfGitDirty = require('./util/confirmIfGitDirty')
  5. async function upgrade (packageName, options, context = process.cwd()) {
  6. if (!(await confirmIfGitDirty(context))) {
  7. return
  8. }
  9. const upgrader = new Upgrader(context)
  10. if (!packageName) {
  11. if (options.to) {
  12. error(`Must specify a package name to upgrade to ${options.to}`)
  13. process.exit(1)
  14. }
  15. if (options.all) {
  16. return upgrader.upgradeAll(options.next)
  17. }
  18. const upgradable = await upgrader.checkForUpdates(options.next)
  19. if (upgradable) {
  20. const { ok } = await inquirer.prompt([
  21. {
  22. name: 'ok',
  23. type: 'confirm',
  24. message: 'Continue to upgrade these plugins?',
  25. default: true
  26. }
  27. ])
  28. if (ok) {
  29. return upgrader.upgradeAll(options.next)
  30. }
  31. }
  32. return
  33. }
  34. return upgrader.upgrade(packageName, options)
  35. }
  36. module.exports = (...args) => {
  37. return upgrade(...args).catch(err => {
  38. error(err)
  39. if (!process.env.VUE_CLI_TEST) {
  40. process.exit(1)
  41. }
  42. })
  43. }