feat: support for --registry option in vue add & vue invoke commands (#2698)

closes #1868
This commit is contained in:
Haoqun Jiang
2018-10-29 00:07:15 +08:00
committed by GitHub
parent 78c7c129dd
commit b0f6ed8218
3 changed files with 14 additions and 7 deletions
+2
View File
@@ -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)))
@@ -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)))
+1 -1
View File
@@ -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()
+11 -6
View File
@@ -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') {
@@ -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)
@@ -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) {