#!/usr/bin/env node // Check node version before requiring/doing anything else // The user may be on a very old node version const { chalk, semver } = require('@vue/cli-shared-utils') const requiredVersion = require('../package.json').engines.node const didYouMean = require('didyoumean') // Setting edit distance to 60% of the input string's length didYouMean.threshold = 0.6 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') if (semver.satisfies(process.version, '9.x')) { console.log(chalk.red( `You are using Node ${process.version}.\n` + `Node.js 9.x has already reached end-of-life and will not be supported in future major releases.\n` + `It's strongly recommended to use an active LTS version instead.` )) } 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 && ( fs.existsSync(path.resolve(process.cwd(), '../@vue')) || fs.existsSync(path.resolve(process.cwd(), '../../@vue')) ) ) { process.env.VUE_CLI_DEBUG = true } const program = require('commander') const loadCommand = require('../lib/util/loadCommand') program .version(`@vue/cli ${require('../package').version}`) .usage(' [options]') program .command('create ') .description('create a new project powered by vue-cli-service') .option('-p, --preset ', 'Skip prompts and use saved or remote preset') .option('-d, --default', 'Skip prompts and use default preset') .option('-i, --inlinePreset ', 'Skip prompts and use inline JSON string as preset') .option('-m, --packageManager ', 'Use specified npm client when installing dependencies') .option('-r, --registry ', 'Use specified npm registry when installing dependencies (only for npm)') .option('-g, --git [message]', 'Force git initialization with initial commit message') .option('-n, --no-git', 'Skip git initialization') .option('-f, --force', 'Overwrite target directory if it exists') .option('--merge', 'Merge target directory if it exists') .option('-c, --clone', 'Use git clone when fetching remote preset') .option('-x, --proxy', 'Use specified proxy when creating project') .option('-b, --bare', 'Scaffold project without beginner instructions') .option('--skipGetStarted', 'Skip displaying "Get started" instructions') .action((name, cmd) => { const options = cleanArgs(cmd) if (minimist(process.argv.slice(3))._.length > 1) { console.log(chalk.yellow('\n Info: You provided more than one argument. The first one will be used as the app\'s name, the rest are ignored.')) } // --git makes commander to default git to true if (process.argv.includes('-g') || process.argv.includes('--git')) { options.forceGit = true } require('../lib/create')(name, options) }) program .command('add [pluginOptions]') .description('install a plugin and invoke its generator in an already created project') .option('--registry ', 'Use specified npm registry when installing dependencies (only for npm)') .allowUnknownOption() .action((plugin) => { require('../lib/add')(plugin, minimist(process.argv.slice(3))) }) program .command('invoke [pluginOptions]') .description('invoke the generator of a plugin in an already created project') .option('--registry ', 'Use specified npm registry when installing dependencies (only for npm)') .allowUnknownOption() .action((plugin) => { require('../lib/invoke')(plugin, minimist(process.argv.slice(3))) }) program .command('inspect [paths...]') .description('inspect the webpack config in a project with vue-cli-service') .option('--mode ') .option('--rule ', 'inspect a specific module rule') .option('--plugin ', 'inspect a specific plugin') .option('--rules', 'list all module rule names') .option('--plugins', 'list all plugin names') .option('-v --verbose', 'Show full function definitions in output') .action((paths, cmd) => { require('../lib/inspect')(paths, cleanArgs(cmd)) }) program .command('serve [entry]') .description('serve a .js or .vue file in development mode with zero config') .option('-o, --open', 'Open browser') .option('-c, --copy', 'Copy local url to clipboard') .option('-p, --port ', 'Port used by the server (default: 8080 or next available port)') .action((entry, cmd) => { loadCommand('serve', '@vue/cli-service-global').serve(entry, cleanArgs(cmd)) }) program .command('build [entry]') .description('build a .js or .vue file in production mode with zero config') .option('-t, --target ', 'Build target (app | lib | wc | wc-async, default: app)') .option('-n, --name ', 'name for lib or web-component mode (default: entry filename)') .option('-d, --dest ', 'output directory (default: dist)') .action((entry, cmd) => { loadCommand('build', '@vue/cli-service-global').build(entry, cleanArgs(cmd)) }) program .command('ui') .description('start and open the vue-cli ui') .option('-H, --host ', 'Host used for the UI server (default: localhost)') .option('-p, --port ', 'Port used for the UI server (by default search for available port)') .option('-D, --dev', 'Run in dev mode') .option('--quiet', `Don't output starting messages`) .option('--headless', `Don't open browser on start and output port`) .action((cmd) => { checkNodeVersion('>=8.6', 'vue ui') require('../lib/ui')(cleanArgs(cmd)) }) program .command('init