@@ -51,7 +51,7 @@ export default class CommandReferenceGenerate extends SfdxCommand {
5151 pluginNames = [ getString ( packageJson , 'name' ) ] ;
5252 } else {
5353 throw new SfdxError (
54- ' No plugins provided. Provide the \ '--plugins\ ' flag or cd into a directory that contains a valid oclif plugin.'
54+ " No plugins provided. Provide the '--plugins' flag or cd into a directory that contains a valid oclif plugin."
5555 ) ;
5656 }
5757 } else {
@@ -73,7 +73,9 @@ export default class CommandReferenceGenerate extends SfdxCommand {
7373 }
7474 return pluginName ;
7575 } ) ;
76- this . ux . log ( `Generating command refernce for the following plugins:${ plugins . map ( name => `${ os . EOL } - ${ name } ` ) } ` ) ;
76+ this . ux . log (
77+ `Generating command reference for the following plugins:${ plugins . map ( name => `${ os . EOL } - ${ name } ` ) } `
78+ ) ;
7779 Ditamap . outputDir = this . flags . outputdir ;
7880
7981 Ditamap . cliVersion = this . config . version . replace ( / - [ 0 - 9 a - z A - Z ] + $ / , '' ) ;
@@ -85,7 +87,7 @@ export default class CommandReferenceGenerate extends SfdxCommand {
8587 return { name, version } ;
8688 } ) ;
8789
88- const docs = new Docs ( Ditamap . outputDir , Ditamap . plugins , this . flags . hidden , this . loadTopicMetadata ( ) ) ;
90+ const docs = new Docs ( Ditamap . outputDir , Ditamap . plugins , this . flags . hidden , await this . loadTopicMetadata ( ) ) ;
8991
9092 events . on ( 'topic' , ( { topic } ) => {
9193 this . log ( chalk . green ( `Generating topic '${ topic } '` ) ) ;
@@ -97,7 +99,7 @@ export default class CommandReferenceGenerate extends SfdxCommand {
9799 warnings . push ( msg ) ;
98100 } ) ;
99101
100- await docs . build ( this . loadCommands ( ) ) ;
102+ await docs . build ( await this . loadCommands ( ) ) ;
101103 this . log ( `\nWrote generated doc to ${ Ditamap . outputDir } ` ) ;
102104
103105 if ( this . flags . erroronwarnings && warnings . length > 0 ) {
@@ -132,14 +134,14 @@ export default class CommandReferenceGenerate extends SfdxCommand {
132134 return this . config . plugins . find ( info => info . name === pluginName ) ;
133135 }
134136
135- private loadTopicMetadata ( ) {
137+ private async loadTopicMetadata ( ) {
136138 const plugins : Dictionary < boolean > = { } ;
137139 const topicsMeta = { } ;
138140
139141 for ( const cmd of this . config . commands ) {
140142 // Only load topics for each plugin once
141143 if ( cmd . pluginName && ! plugins [ cmd . pluginName ] ) {
142- const commandClass = cmd . load ( ) ;
144+ const commandClass = await this . loadCommand ( cmd ) ;
143145
144146 if ( commandClass . plugin && commandClass . plugin . pjson . oclif . topics ) {
145147 mergeDeep ( topicsMeta , commandClass . plugin . pjson . oclif . topics as Dictionary ) ;
@@ -150,10 +152,10 @@ export default class CommandReferenceGenerate extends SfdxCommand {
150152 return topicsMeta ;
151153 }
152154
153- private loadCommands ( ) {
154- return this . config . commands . map ( cmd => {
155+ private async loadCommands ( ) {
156+ const promises = this . config . commands . map ( async cmd => {
155157 try {
156- let commandClass = cmd . load ( ) ;
158+ let commandClass = await this . loadCommand ( cmd ) ;
157159 let obj = Object . assign ( { } as JsonMap , cmd , commandClass , {
158160 flags : Object . assign ( { } , cmd . flags , commandClass . flags )
159161 } ) ;
@@ -171,5 +173,10 @@ export default class CommandReferenceGenerate extends SfdxCommand {
171173 return Object . assign ( { } as JsonMap , cmd ) ;
172174 }
173175 } ) ;
176+ return Promise . all ( promises ) ;
177+ }
178+
179+ private async loadCommand ( command ) {
180+ return command . load . constructor . name === 'AsyncFunction' ? await command . load ( ) : command . load ( ) ;
174181 }
175182}
0 commit comments