mirror of
https://github.com/vuejs/vue-cli.git
synced 2026-01-17 21:00:03 -06:00
46 lines
1.2 KiB
JavaScript
46 lines
1.2 KiB
JavaScript
const chalk = require('chalk')
|
|
const invoke = require('./invoke')
|
|
const { loadOptions } = require('./options')
|
|
const { installPackage } = require('./util/installDeps')
|
|
const { resolveModule } = require('./util/module')
|
|
const {
|
|
log,
|
|
error,
|
|
hasYarn,
|
|
stopSpinner,
|
|
resolvePluginId
|
|
} = require('@vue/cli-shared-utils')
|
|
|
|
async function add (pluginName, options = {}, context = process.cwd()) {
|
|
const packageName = resolvePluginId(pluginName)
|
|
|
|
log()
|
|
log(`📦 Installing ${chalk.cyan(packageName)}...`)
|
|
log()
|
|
|
|
const packageManager = loadOptions().packageManager || (hasYarn() ? 'yarn' : 'npm')
|
|
await installPackage(context, packageManager, null, packageName)
|
|
|
|
stopSpinner()
|
|
|
|
log()
|
|
log(`${chalk.green('✔')} Successfully installed plugin: ${chalk.cyan(packageName)}`)
|
|
log()
|
|
|
|
const generatorPath = resolveModule(`${packageName}/generator`, context)
|
|
if (generatorPath) {
|
|
invoke(pluginName, options, context)
|
|
} else {
|
|
log(`Plugin ${packageName} does not have a generator to invoke`)
|
|
}
|
|
}
|
|
|
|
module.exports = (...args) => {
|
|
return add(...args).catch(err => {
|
|
error(err)
|
|
if (!process.env.VUE_CLI_TEST) {
|
|
process.exit(1)
|
|
}
|
|
})
|
|
}
|