Skip to content

Commit

Permalink
feat: support for --registry option in vue add & vue invoke commands
Browse files Browse the repository at this point in the history
closes #1868
  • Loading branch information
sodatea committed Oct 9, 2018
1 parent 7c91a18 commit 57c0033
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 7 deletions.
2 changes: 2 additions & 0 deletions packages/@vue/cli/bin/vue.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ program
program
.command('add <plugin> [pluginOptions]')
.description('install a plugin and invoke its generator in an already created project')
.option('--registry <url>', 'Use specified npm registry when installing dependencies (only for npm)')
.allowUnknownOption()
.action((plugin) => {
require('../lib/add')(plugin, minimist(process.argv.slice(3)))
Expand All @@ -75,6 +76,7 @@ program
program
.command('invoke <plugin> [pluginOptions]')
.description('invoke the generator of a plugin in an already created project')
.option('--registry <url>', 'Use specified npm registry when installing dependencies (only for npm)')
.allowUnknownOption()
.action((plugin) => {
require('../lib/invoke')(plugin, minimist(process.argv.slice(3)))
Expand Down
2 changes: 1 addition & 1 deletion packages/@vue/cli/lib/add.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ async function add (pluginName, options = {}, context = process.cwd()) {
log()

const packageManager = loadOptions().packageManager || (hasProjectYarn(context) ? 'yarn' : 'npm')
await installPackage(context, packageManager, null, packageName)
await installPackage(context, packageManager, options.registry, packageName)

log(`${chalk.green('✔')} Successfully installed plugin: ${chalk.cyan(packageName)}`)
log()
Expand Down
17 changes: 11 additions & 6 deletions packages/@vue/cli/lib/invoke.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,11 @@ async function invoke (pluginName, options = {}, context = process.cwd()) {
throw new Error(`Plugin ${id} does not have a generator.`)
}

// resolve options if no command line options are passed, and the plugin
// contains a prompt module.
if (!Object.keys(options).length) {
// resolve options if no command line options (other than --registry) are passed,
// and the plugin contains a prompt module.
// eslint-disable-next-line prefer-const
let { registry, ...pluginOptions } = options
if (!Object.keys(pluginOptions).length) {
let pluginPrompts = loadModule(`${id}/prompts`, context)
if (pluginPrompts) {
if (typeof pluginPrompts === 'function') {
Expand All @@ -92,14 +94,17 @@ async function invoke (pluginName, options = {}, context = process.cwd()) {
if (typeof pluginPrompts.getPrompts === 'function') {
pluginPrompts = pluginPrompts.getPrompts(pkg)
}
options = await inquirer.prompt(pluginPrompts)
pluginOptions = await inquirer.prompt(pluginPrompts)
}
}

const plugin = {
id,
apply: pluginGenerator,
options
options: {
registry,
...pluginOptions
}
}

await runGenerator(context, plugin, pkg)
Expand Down Expand Up @@ -134,7 +139,7 @@ async function runGenerator (context, plugin, pkg = getPkg(context)) {
log()
const packageManager =
loadOptions().packageManager || (hasProjectYarn(context) ? 'yarn' : 'npm')
await installDeps(context, packageManager)
await installDeps(context, packageManager, plugin.options.registry)
}

if (createCompleteCbs.length) {
Expand Down

0 comments on commit 57c0033

Please sign in to comment.