From a4df1125f7aa75de240114b21420321062280bc6 Mon Sep 17 00:00:00 2001 From: test Date: Tue, 1 May 2018 15:05:49 -0500 Subject: [PATCH] feat(cli): add ability to `add` vuex and vue-router internal plugins (#1202) --- packages/@vue/cli/lib/add.js | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/packages/@vue/cli/lib/add.js b/packages/@vue/cli/lib/add.js index 918932a196..998bebbcf5 100644 --- a/packages/@vue/cli/lib/add.js +++ b/packages/@vue/cli/lib/add.js @@ -6,20 +6,30 @@ const { resolveModule } = require('./util/module') const { log, error, + warn, hasYarn, stopSpinner, resolvePluginId } = require('@vue/cli-shared-utils') +// vuex and vue-router are internally added via cli-service so they need to be handled differently +const internalPluginRE = /^(vuex|router)$/ + async function add (pluginName, options = {}, context = process.cwd()) { - const packageName = resolvePluginId(pluginName) + let packageName + const internalPlugin = internalPluginRE.test(pluginName) + if (internalPlugin) { + packageName = pluginName.replace(/router/, 'vue-router') + } else { + packageName = resolvePluginId(pluginName) + } log() log(`📦 Installing ${chalk.cyan(packageName)}...`) log() const packageManager = loadOptions().packageManager || (hasYarn() ? 'yarn' : 'npm') - await installPackage(context, packageManager, null, packageName) + await installPackage(context, packageManager, null, packageName, !internalPlugin) stopSpinner() @@ -30,6 +40,10 @@ async function add (pluginName, options = {}, context = process.cwd()) { const generatorPath = resolveModule(`${packageName}/generator`, context) if (generatorPath) { invoke(pluginName, options, context) + } else if (internalPlugin) { + log() + warn(`Internal Plugin: ${packageName} cannot modify files post creation. See https://${pluginName}.vuejs.org for instructions to add ${packageName} to your code`) + log() } else { log(`Plugin ${packageName} does not have a generator to invoke`) }