@@ -36,16 +36,17 @@ async function readFiles (context) {
36
36
return res
37
37
}
38
38
39
- async function invoke ( pluginName , options = { } , context = process . cwd ( ) ) {
40
- delete options . _
39
+ function getPkg ( context ) {
41
40
const pkgPath = path . resolve ( context , 'package.json' )
42
- const isTestOrDebug = process . env . VUE_CLI_TEST || process . env . VUE_CLI_DEBUG
43
-
44
41
if ( ! fs . existsSync ( pkgPath ) ) {
45
42
throw new Error ( `package.json not found in ${ chalk . yellow ( context ) } ` )
46
43
}
44
+ return require ( pkgPath )
45
+ }
47
46
48
- const pkg = require ( pkgPath )
47
+ async function invoke ( pluginName , options = { } , context = process . cwd ( ) ) {
48
+ delete options . _
49
+ const pkg = getPkg ( context )
49
50
50
51
// attempt to locate the plugin in package.json
51
52
const findPlugin = deps => {
@@ -89,6 +90,11 @@ async function invoke (pluginName, options = {}, context = process.cwd()) {
89
90
options
90
91
}
91
92
93
+ await runGenerator ( context , plugin , pkg )
94
+ }
95
+
96
+ async function runGenerator ( context , plugin , pkg = getPkg ( context ) ) {
97
+ const isTestOrDebug = process . env . VUE_CLI_TEST || process . env . VUE_CLI_DEBUG
92
98
const createCompleteCbs = [ ]
93
99
const generator = new Generator ( context , {
94
100
pkg,
@@ -98,7 +104,7 @@ async function invoke (pluginName, options = {}, context = process.cwd()) {
98
104
} )
99
105
100
106
log ( )
101
- logWithSpinner ( '🚀' , `Invoking generator for ${ id } ...` )
107
+ logWithSpinner ( '🚀' , `Invoking generator for ${ plugin . id } ...` )
102
108
await generator . generate ( {
103
109
extractConfigFiles : true ,
104
110
checkExisting : true
@@ -127,7 +133,7 @@ async function invoke (pluginName, options = {}, context = process.cwd()) {
127
133
stopSpinner ( )
128
134
129
135
log ( )
130
- log ( ` Successfully invoked generator for plugin: ${ chalk . cyan ( id ) } ` )
136
+ log ( ` Successfully invoked generator for plugin: ${ chalk . cyan ( plugin . id ) } ` )
131
137
if ( ! process . env . VUE_CLI_TEST && hasGit ( ) ) {
132
138
const { stdout } = await execa ( 'git' , [
133
139
'ls-files' ,
@@ -166,3 +172,5 @@ module.exports = (...args) => {
166
172
}
167
173
} )
168
174
}
175
+
176
+ module . exports . runGenerator = runGenerator
0 commit comments