mirror of
https://github.com/vuejs/vue-cli.git
synced 2026-03-20 18:11:07 -05:00
feat: tweak invoke command
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
require('../lib/invoke') // so that jest registers the file for this test
|
||||
const create = require('@vue/cli-test-utils/createTestProject')
|
||||
|
||||
test('invoke single generator', async () => {
|
||||
|
||||
@@ -50,7 +50,7 @@ program
|
||||
program
|
||||
.command('invoke <plugin>')
|
||||
.allowUnknownOption()
|
||||
.description('invoke the generator of an installed plugin in an already created project')
|
||||
.description('invoke the generator of a plugin in an already created project')
|
||||
.action((plugin) => {
|
||||
require('../lib/invoke')(plugin, minimist(process.argv.slice(3)))
|
||||
})
|
||||
|
||||
@@ -5,7 +5,6 @@ const resolve = require('resolve')
|
||||
const Generator = require('./Generator')
|
||||
const { loadOptions } = require('./options')
|
||||
const installDeps = require('./util/installDeps')
|
||||
const clearConsole = require('./util/clearConsole')
|
||||
const {
|
||||
log,
|
||||
error,
|
||||
@@ -30,26 +29,26 @@ async function invoke (pluginName, options) {
|
||||
const findPlugin = deps => {
|
||||
if (!deps) return
|
||||
let name
|
||||
if (deps[name = pluginName] ||
|
||||
deps[name = `@vue/cli-plugin-${pluginName}`] ||
|
||||
deps[name = `vue-cli-plugin-${pluginName}`]) {
|
||||
if (deps[name = `@vue/cli-plugin-${pluginName}`] ||
|
||||
deps[name = `vue-cli-plugin-${pluginName}`] ||
|
||||
deps[name = pluginName]) {
|
||||
return name
|
||||
}
|
||||
}
|
||||
const resolvedPluginName = (
|
||||
findPlugin(pkg.devDependencies) ||
|
||||
findPlugin(pkg.dependencies)
|
||||
)
|
||||
|
||||
if (!resolvedPluginName) {
|
||||
error(`Cannot resolve plugin ${chalk.yellow(pluginName)} from package.json.`)
|
||||
const id = findPlugin(pkg.devDependencies) || findPlugin(pkg.dependencies)
|
||||
if (!id) {
|
||||
error(
|
||||
`Cannot resolve plugin ${chalk.yellow(pluginName)} from package.json. ` +
|
||||
`Did you forget to install it?`
|
||||
)
|
||||
process.exit(1)
|
||||
}
|
||||
|
||||
const generatorURI = `${resolvedPluginName}/generator`
|
||||
const generatorURI = `${id}/generator`
|
||||
const generatorPath = resolve.sync(generatorURI, { basedir: context })
|
||||
const plugin = {
|
||||
id: resolvedPluginName,
|
||||
id,
|
||||
apply: require(generatorPath),
|
||||
options
|
||||
}
|
||||
@@ -62,8 +61,8 @@ async function invoke (pluginName, options) {
|
||||
createCompleteCbs
|
||||
)
|
||||
|
||||
clearConsole()
|
||||
logWithSpinner('🚀', `Invoking generator for ${resolvedPluginName}...`)
|
||||
log()
|
||||
logWithSpinner('🚀', `Invoking generator for ${id}...`)
|
||||
await generator.generate()
|
||||
|
||||
const isTestOrDebug = process.env.VUE_CLI_TEST || process.env.VUE_CLI_DEBUG
|
||||
@@ -89,7 +88,7 @@ async function invoke (pluginName, options) {
|
||||
|
||||
stopSpinner()
|
||||
log()
|
||||
log(` Successfully invoked generator for plugin: ${chalk.cyan(resolvedPluginName)}`)
|
||||
log(` Successfully invoked generator for plugin: ${chalk.cyan(id)}`)
|
||||
log(` You should review and commit the changes.`)
|
||||
log()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user