#!/usr/bin/env node const fs = require('fs') const path = require('path') const slash = require('slash') 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) } // 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(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('-f, --force', 'Overwrite target directory if it exists') .option('-c, --clone', 'Use git clone when fetching remote preset') .action((name, cmd) => { require('../lib/create')(name, cleanArgs(cmd)) }) program .command('add [pluginOptions]') .allowUnknownOption() .description('install a plugin and invoke its generator in an already created project') .action((plugin) => { require('../lib/add')(plugin, minimist(process.argv.slice(3))) }) program .command('invoke [pluginOptions]') .allowUnknownOption() .description('invoke the generator of a plugin in an already created project') .action((plugin) => { require('../lib/invoke')(plugin, minimist(process.argv.slice(3))) }) program .command('inspect [paths...]') .option('--mode ') .description('inspect the webpack config in a project with vue-cli-service') .action((paths, cmd) => { require('../lib/inspect')(paths, cmd.mode) }) program .command('serve [entry]') .description('serve a .js or .vue file in development mode with zero config') .option('-o, --open', 'Open browser') .action((entry, cmd) => { loadCommand('serve', '@vue/cli-service-global').serve(entry, cleanArgs(cmd)) }) program .command('build [entry]') .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)') .description('build a .js or .vue file in production mode with zero config') .action((entry, cmd) => { loadCommand('build', '@vue/cli-service-global').build(entry, cleanArgs(cmd)) }) program .command('init