Skip to content

Commit 65cc27d

Browse files
committed
feat: tweak invoke command
1 parent 563636c commit 65cc27d

File tree

3 files changed

+16
-16
lines changed

3 files changed

+16
-16
lines changed

packages/@vue/cli/__tests__/invoke.spec.js

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
require('../lib/invoke') // so that jest registers the file for this test
12
const create = require('@vue/cli-test-utils/createTestProject')
23

34
test('invoke single generator', async () => {

packages/@vue/cli/bin/vue

+1-1
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ program
5050
program
5151
.command('invoke <plugin>')
5252
.allowUnknownOption()
53-
.description('invoke the generator of an installed plugin in an already created project')
53+
.description('invoke the generator of a plugin in an already created project')
5454
.action((plugin) => {
5555
require('../lib/invoke')(plugin, minimist(process.argv.slice(3)))
5656
})

packages/@vue/cli/lib/invoke.js

+14-15
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ const resolve = require('resolve')
55
const Generator = require('./Generator')
66
const { loadOptions } = require('./options')
77
const installDeps = require('./util/installDeps')
8-
const clearConsole = require('./util/clearConsole')
98
const {
109
log,
1110
error,
@@ -30,26 +29,26 @@ async function invoke (pluginName, options) {
3029
const findPlugin = deps => {
3130
if (!deps) return
3231
let name
33-
if (deps[name = pluginName] ||
34-
deps[name = `@vue/cli-plugin-${pluginName}`] ||
35-
deps[name = `vue-cli-plugin-${pluginName}`]) {
32+
if (deps[name = `@vue/cli-plugin-${pluginName}`] ||
33+
deps[name = `vue-cli-plugin-${pluginName}`] ||
34+
deps[name = pluginName]) {
3635
return name
3736
}
3837
}
39-
const resolvedPluginName = (
40-
findPlugin(pkg.devDependencies) ||
41-
findPlugin(pkg.dependencies)
42-
)
4338

44-
if (!resolvedPluginName) {
45-
error(`Cannot resolve plugin ${chalk.yellow(pluginName)} from package.json.`)
39+
const id = findPlugin(pkg.devDependencies) || findPlugin(pkg.dependencies)
40+
if (!id) {
41+
error(
42+
`Cannot resolve plugin ${chalk.yellow(pluginName)} from package.json. ` +
43+
`Did you forget to install it?`
44+
)
4645
process.exit(1)
4746
}
4847

49-
const generatorURI = `${resolvedPluginName}/generator`
48+
const generatorURI = `${id}/generator`
5049
const generatorPath = resolve.sync(generatorURI, { basedir: context })
5150
const plugin = {
52-
id: resolvedPluginName,
51+
id,
5352
apply: require(generatorPath),
5453
options
5554
}
@@ -62,8 +61,8 @@ async function invoke (pluginName, options) {
6261
createCompleteCbs
6362
)
6463

65-
clearConsole()
66-
logWithSpinner('🚀', `Invoking generator for ${resolvedPluginName}...`)
64+
log()
65+
logWithSpinner('🚀', `Invoking generator for ${id}...`)
6766
await generator.generate()
6867

6968
const isTestOrDebug = process.env.VUE_CLI_TEST || process.env.VUE_CLI_DEBUG
@@ -89,7 +88,7 @@ async function invoke (pluginName, options) {
8988

9089
stopSpinner()
9190
log()
92-
log(` Successfully invoked generator for plugin: ${chalk.cyan(resolvedPluginName)}`)
91+
log(` Successfully invoked generator for plugin: ${chalk.cyan(id)}`)
9392
log(` You should review and commit the changes.`)
9493
log()
9594
}

0 commit comments

Comments
 (0)