Skip to content

Commit

Permalink
fix: better version check, closes #1564
Browse files Browse the repository at this point in the history
  • Loading branch information
Guillaume Chau committed Jun 17, 2018
1 parent e6d68ca commit 8b9477f
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 21 deletions.
41 changes: 20 additions & 21 deletions packages/@vue/cli/bin/vue.js
Original file line number Diff line number Diff line change
@@ -1,21 +1,29 @@
#!/usr/bin/env node

const fs = require('fs')
const path = require('path')
const slash = require('slash')
// Check node version before requiring/doing anything else
// The user may be on a very old node version

const chalk = require('chalk')
const semver = require('semver')
const minimist = require('minimist')
const requiredVersion = require('../package.json').engines.node

if (!semver.satisfies(process.version, requiredVersion)) {
console.log(chalk.red(
`You are using Node ${process.version}, but this version of vue-cli ` +
`requires Node ${requiredVersion}.\nPlease upgrade your Node version.`
))
process.exit(1)
function checkNodeVersion (wanted, id) {
if (!semver.satisfies(process.version, wanted)) {
console.log(chalk.red(
'You are using Node ' + process.version + ', but this version of ' + id +
'requires Node ' + wanted + '.\nPlease upgrade your Node version.'
))
process.exit(1)
}
}

checkNodeVersion(requiredVersion, 'vue-cli')

const fs = require('fs')
const path = require('path')
const slash = require('slash')
const minimist = require('minimist')

// enter debug mode when creating test repo
if (
slash(process.cwd()).indexOf('/packages/test') > 0 && (
Expand Down Expand Up @@ -105,6 +113,7 @@ program
.option('--headless', `Don't open browser on start and output port`)
.description('start and open the vue-cli ui')
.action((cmd) => {
checkNodeVersion('>=8.6', 'vue ui')
require('../lib/ui')(cleanArgs(cmd))
})

Expand Down Expand Up @@ -135,17 +144,7 @@ program.on('--help', () => {
program.commands.forEach(c => c.on('--help', () => console.log()))

// enhance common error messages
const enhanceErrorMessages = (methodName, log) => {
program.Command.prototype[methodName] = function (...args) {
if (methodName === 'unknownOption' && this._allowUnknownOption) {
return
}
this.outputHelp()
console.log(` ` + chalk.red(log(...args)))
console.log()
process.exit(1)
}
}
const enhanceErrorMessages = require('../lib/util/enhanceErrorMessages')

enhanceErrorMessages('missingArgument', argName => {
return `Missing required argument ${chalk.yellow(`<${argName}>`)}.`
Expand Down
14 changes: 14 additions & 0 deletions packages/@vue/cli/lib/util/enhanceErrorMessages.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
const program = require('commander')
const chalk = require('chalk')

module.exports = (methodName, log) => {
program.Command.prototype[methodName] = function (...args) {
if (methodName === 'unknownOption' && this._allowUnknownOption) {
return
}
this.outputHelp()
console.log(` ` + chalk.red(log(...args)))
console.log()
process.exit(1)
}
}

0 comments on commit 8b9477f

Please sign in to comment.