mirror of
https://github.com/vuejs/vue-cli.git
synced 2026-05-12 06:48:27 -05:00
feat: support for --registry option in vue add & vue invoke commands (#2698)
closes #1868
This commit is contained in:
@@ -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)))
|
||||
|
||||
@@ -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()
|
||||
|
||||
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user