@@ -36,16 +36,17 @@ async function readFiles (context) {
3636 return res
3737}
3838
39- async function invoke ( pluginName , options = { } , context = process . cwd ( ) ) {
40- delete options . _
39+ function getPkg ( context ) {
4140 const pkgPath = path . resolve ( context , 'package.json' )
42- const isTestOrDebug = process . env . VUE_CLI_TEST || process . env . VUE_CLI_DEBUG
43-
4441 if ( ! fs . existsSync ( pkgPath ) ) {
4542 throw new Error ( `package.json not found in ${ chalk . yellow ( context ) } ` )
4643 }
44+ return require ( pkgPath )
45+ }
4746
48- const pkg = require ( pkgPath )
47+ async function invoke ( pluginName , options = { } , context = process . cwd ( ) ) {
48+ delete options . _
49+ const pkg = getPkg ( context )
4950
5051 // attempt to locate the plugin in package.json
5152 const findPlugin = deps => {
@@ -89,6 +90,11 @@ async function invoke (pluginName, options = {}, context = process.cwd()) {
8990 options
9091 }
9192
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
9298 const createCompleteCbs = [ ]
9399 const generator = new Generator ( context , {
94100 pkg,
@@ -98,7 +104,7 @@ async function invoke (pluginName, options = {}, context = process.cwd()) {
98104 } )
99105
100106 log ( )
101- logWithSpinner ( '🚀' , `Invoking generator for ${ id } ...` )
107+ logWithSpinner ( '🚀' , `Invoking generator for ${ plugin . id } ...` )
102108 await generator . generate ( {
103109 extractConfigFiles : true ,
104110 checkExisting : true
@@ -127,7 +133,7 @@ async function invoke (pluginName, options = {}, context = process.cwd()) {
127133 stopSpinner ( )
128134
129135 log ( )
130- log ( ` Successfully invoked generator for plugin: ${ chalk . cyan ( id ) } ` )
136+ log ( ` Successfully invoked generator for plugin: ${ chalk . cyan ( plugin . id ) } ` )
131137 if ( ! process . env . VUE_CLI_TEST && hasGit ( ) ) {
132138 const { stdout } = await execa ( 'git' , [
133139 'ls-files' ,
@@ -166,3 +172,5 @@ module.exports = (...args) => {
166172 }
167173 } )
168174}
175+
176+ module . exports . runGenerator = runGenerator
0 commit comments