Skip to content

Commit

Permalink
feat(cli): add ability to add vuex and vue-router internal plugins (v…
Browse files Browse the repository at this point in the history
  • Loading branch information
test committed May 1, 2018
1 parent a6e47ce commit a4df112
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions packages/@vue/cli/lib/add.js
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand All @@ -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`)
}
Expand Down

0 comments on commit a4df112

Please sign in to comment.