@@ -5,6 +5,16 @@ const GeneratorAPI = require('./GeneratorAPI')
55const sortObject = require ( './util/sortObject' )
66const writeFileTree = require ( './util/writeFileTree' )
77const configTransforms = require ( './util/configTransforms' )
8+ const logger = require ( '@vue/cli-shared-utils/lib/logger' )
9+ const { toShortId } = require ( './util/pluginResolution' )
10+
11+ const logTypes = {
12+ log : logger . log ,
13+ info : logger . info ,
14+ done : logger . done ,
15+ warn : logger . warn ,
16+ error : logger . error
17+ }
818
919module . exports = class Generator {
1020 constructor ( context , pkg , plugins , completeCbs = [ ] ) {
@@ -20,6 +30,8 @@ module.exports = class Generator {
2030 this . files = { }
2131 this . fileMiddlewares = [ ]
2232 this . postProcessFilesCbs = [ ]
33+ // exit messages
34+ this . exitLogs = [ ]
2335
2436 const cliService = plugins . find ( p => p . id === '@vue/cli-service' )
2537 const rootOptions = cliService && cliService . options
@@ -135,4 +147,19 @@ module.exports = class Generator {
135147 return id === _id || id . replace ( prefixRE , '' ) === _id
136148 } )
137149 }
150+
151+ printExitLogs ( ) {
152+ if ( this . exitLogs . length ) {
153+ this . exitLogs . forEach ( ( { id, msg, type } ) => {
154+ const shortId = toShortId ( id )
155+ const logFn = logTypes [ type ]
156+ if ( ! logFn ) {
157+ logger . error ( `Invalid api.exitLog type '${ type } '.` , shortId )
158+ } else {
159+ logFn ( msg , msg && shortId )
160+ }
161+ } )
162+ logger . log ( )
163+ }
164+ }
138165}
0 commit comments