@@ -51,7 +51,7 @@ export default class CommandReferenceGenerate extends SfdxCommand {
51
51
pluginNames = [ getString ( packageJson , 'name' ) ] ;
52
52
} else {
53
53
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."
55
55
) ;
56
56
}
57
57
} else {
@@ -73,7 +73,9 @@ export default class CommandReferenceGenerate extends SfdxCommand {
73
73
}
74
74
return pluginName ;
75
75
} ) ;
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
+ ) ;
77
79
Ditamap . outputDir = this . flags . outputdir ;
78
80
79
81
Ditamap . cliVersion = this . config . version . replace ( / - [ 0 - 9 a - z A - Z ] + $ / , '' ) ;
@@ -85,7 +87,7 @@ export default class CommandReferenceGenerate extends SfdxCommand {
85
87
return { name, version } ;
86
88
} ) ;
87
89
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 ( ) ) ;
89
91
90
92
events . on ( 'topic' , ( { topic } ) => {
91
93
this . log ( chalk . green ( `Generating topic '${ topic } '` ) ) ;
@@ -97,7 +99,7 @@ export default class CommandReferenceGenerate extends SfdxCommand {
97
99
warnings . push ( msg ) ;
98
100
} ) ;
99
101
100
- await docs . build ( this . loadCommands ( ) ) ;
102
+ await docs . build ( await this . loadCommands ( ) ) ;
101
103
this . log ( `\nWrote generated doc to ${ Ditamap . outputDir } ` ) ;
102
104
103
105
if ( this . flags . erroronwarnings && warnings . length > 0 ) {
@@ -132,14 +134,14 @@ export default class CommandReferenceGenerate extends SfdxCommand {
132
134
return this . config . plugins . find ( info => info . name === pluginName ) ;
133
135
}
134
136
135
- private loadTopicMetadata ( ) {
137
+ private async loadTopicMetadata ( ) {
136
138
const plugins : Dictionary < boolean > = { } ;
137
139
const topicsMeta = { } ;
138
140
139
141
for ( const cmd of this . config . commands ) {
140
142
// Only load topics for each plugin once
141
143
if ( cmd . pluginName && ! plugins [ cmd . pluginName ] ) {
142
- const commandClass = cmd . load ( ) ;
144
+ const commandClass = await this . loadCommand ( cmd ) ;
143
145
144
146
if ( commandClass . plugin && commandClass . plugin . pjson . oclif . topics ) {
145
147
mergeDeep ( topicsMeta , commandClass . plugin . pjson . oclif . topics as Dictionary ) ;
@@ -150,10 +152,10 @@ export default class CommandReferenceGenerate extends SfdxCommand {
150
152
return topicsMeta ;
151
153
}
152
154
153
- private loadCommands ( ) {
154
- return this . config . commands . map ( cmd => {
155
+ private async loadCommands ( ) {
156
+ const promises = this . config . commands . map ( async cmd => {
155
157
try {
156
- let commandClass = cmd . load ( ) ;
158
+ let commandClass = await this . loadCommand ( cmd ) ;
157
159
let obj = Object . assign ( { } as JsonMap , cmd , commandClass , {
158
160
flags : Object . assign ( { } , cmd . flags , commandClass . flags )
159
161
} ) ;
@@ -171,5 +173,10 @@ export default class CommandReferenceGenerate extends SfdxCommand {
171
173
return Object . assign ( { } as JsonMap , cmd ) ;
172
174
}
173
175
} ) ;
176
+ return Promise . all ( promises ) ;
177
+ }
178
+
179
+ private async loadCommand ( command ) {
180
+ return command . load . constructor . name === 'AsyncFunction' ? await command . load ( ) : command . load ( ) ;
174
181
}
175
182
}
0 commit comments