feat(bin): adds version flag

adds --version / -v support for the nuxt binary; will always output version and exit(0)
This commit is contained in:
Eric McCormick 2017-10-12 22:48:20 -05:00 committed by Pooya Parsa
parent cf693d04a3
commit a5e16d2fe6

View File

@ -10,7 +10,9 @@ const fs = require('fs')
const parseArgs = require('minimist') const parseArgs = require('minimist')
const { Nuxt, Builder } = require('../') const { Nuxt, Builder } = require('../')
const chokidar = require('chokidar') const chokidar = require('chokidar')
const resolve = require('path').resolve const path = require('path')
const resolve = path.resolve
const pkg = require(path.join('..','package.json'))
const argv = parseArgs(process.argv.slice(2), { const argv = parseArgs(process.argv.slice(2), {
alias: { alias: {
@ -19,15 +21,21 @@ const argv = parseArgs(process.argv.slice(2), {
p: 'port', p: 'port',
c: 'config-file', c: 'config-file',
s: 'spa', s: 'spa',
u: 'universal' u: 'universal',
v: 'version'
}, },
boolean: ['h', 's', 'u'], boolean: ['h', 's', 'u', 'v'],
string: ['H', 'c'], string: ['H', 'c'],
default: { default: {
c: 'nuxt.config.js' c: 'nuxt.config.js'
} }
}) })
if(argv.version){
console.log(pkg.version)
process.exit(0)
}
if (argv.hostname === '') { if (argv.hostname === '') {
console.error(`> Provided hostname argument has no value`) console.error(`> Provided hostname argument has no value`)
process.exit(1) process.exit(1)