Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(cli): add ability to add vuex and vue-router internal plugins (#1202) #1204

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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