88import * as os from 'os' ;
99import * as fs from 'fs' ;
1010import * as path from 'path' ;
11- import { Plugin } from '@oclif/core/lib/interfaces' ;
11+ import { Plugin , Command } from '@oclif/core/lib/interfaces' ;
1212import { flags , SfdxCommand } from '@salesforce/command' ;
13- import { Messages , SfdxError } from '@salesforce/core' ;
13+ import { Messages , SfError } from '@salesforce/core' ;
1414import { AnyJson , Dictionary , ensure , getString , JsonMap } from '@salesforce/ts-types' ;
1515import chalk = require( 'chalk' ) ;
1616import { Ditamap } from '../../ditamap/ditamap' ;
@@ -54,7 +54,7 @@ export default class CommandReferenceGenerate extends SfdxCommand {
5454 const packageJson = JSON . parse ( await fs . promises . readFile ( pJsonPath , 'utf8' ) ) ;
5555 pluginNames = [ getString ( packageJson , 'name' ) ] ;
5656 } else {
57- throw new SfdxError (
57+ throw new SfError (
5858 "No plugins provided. Provide the '--plugins' flag or cd into a directory that contains a valid oclif plugin."
5959 ) ;
6060 }
@@ -72,7 +72,7 @@ export default class CommandReferenceGenerate extends SfdxCommand {
7272 pluginName = `@salesforce/plugin-${ pluginName } ` ;
7373 plugin = this . getPlugin ( pluginName ) ;
7474 if ( ! plugin ) {
75- throw new SfdxError ( `Plugin ${ name } or ${ pluginName } not found. Is it installed?` ) ;
75+ throw new SfError ( `Plugin ${ name } or ${ pluginName } not found. Is it installed?` ) ;
7676 }
7777 }
7878 return pluginName ;
@@ -82,18 +82,23 @@ export default class CommandReferenceGenerate extends SfdxCommand {
8282 . map ( ( name ) => `${ os . EOL } - ${ name } ` )
8383 . join ( ', ' ) } `
8484 ) ;
85- Ditamap . outputDir = this . flags . outputdir ;
85+ Ditamap . outputDir = this . flags . outputdir as string ;
8686
8787 Ditamap . cliVersion = this . config . version . replace ( / - [ 0 - 9 a - z A - Z ] + $ / , '' ) ;
8888 Ditamap . plugins = this . pluginMap ( plugins ) ;
8989 Ditamap . pluginVersions = plugins . map ( ( name ) => {
9090 const plugin = this . getPlugin ( name ) ;
91- const version = plugin && plugin . version ;
91+ const version = plugin ? .version ;
9292 if ( ! version ) throw new Error ( `No version found for plugin ${ name } ` ) ;
9393 return { name, version } ;
9494 } ) ;
9595
96- const docs = new Docs ( Ditamap . outputDir , Ditamap . plugins , this . flags . hidden , await this . loadTopicMetadata ( ) ) ;
96+ const docs = new Docs (
97+ Ditamap . outputDir ,
98+ Ditamap . plugins ,
99+ this . flags . hidden as boolean ,
100+ await this . loadTopicMetadata ( )
101+ ) ;
97102
98103 events . on ( 'topic' , ( { topic } ) => {
99104 this . log ( chalk . green ( `Generating topic '${ topic } '` ) ) ;
@@ -105,11 +110,12 @@ export default class CommandReferenceGenerate extends SfdxCommand {
105110 warnings . push ( msg ) ;
106111 } ) ;
107112
113+ // eslint-disable-next-line @typescript-eslint/no-unsafe-argument
108114 await docs . build ( await this . loadCommands ( ) ) ;
109115 this . log ( `\nWrote generated doc to ${ Ditamap . outputDir } ` ) ;
110116
111117 if ( this . flags . erroronwarnings && warnings . length > 0 ) {
112- throw new SfdxError ( `Found ${ warnings . length } warnings.` ) ;
118+ throw new SfError ( `Found ${ warnings . length } warnings.` ) ;
113119 }
114120
115121 return { warnings } ;
@@ -119,7 +125,7 @@ export default class CommandReferenceGenerate extends SfdxCommand {
119125 const pluginToParentPlugin : JsonMap = { } ;
120126
121127 const resolveChildPlugins = ( parentPlugin : Plugin ) => {
122- for ( const childPlugin of parentPlugin . pjson . oclif . plugins || [ ] ) {
128+ for ( const childPlugin of parentPlugin . pjson . oclif . plugins ?? [ ] ) {
123129 pluginToParentPlugin [ childPlugin ] = parentPlugin . name ;
124130 resolveChildPlugins ( ensure ( this . getPlugin ( childPlugin ) ) ) ;
125131 }
@@ -128,15 +134,15 @@ export default class CommandReferenceGenerate extends SfdxCommand {
128134 for ( const plugin of plugins ) {
129135 const masterPlugin = this . getPlugin ( plugin ) ;
130136 if ( ! masterPlugin ) {
131- throw new SfdxError ( `Plugin ${ plugin } not found. Is it installed?` ) ;
137+ throw new SfError ( `Plugin ${ plugin } not found. Is it installed?` ) ;
132138 }
133139 pluginToParentPlugin [ masterPlugin . name ] = masterPlugin . name ;
134140 resolveChildPlugins ( masterPlugin ) ;
135141 }
136142 return pluginToParentPlugin ;
137143 }
138144
139- private getPlugin ( pluginName : string ) {
145+ private getPlugin ( pluginName : string ) : Plugin | undefined {
140146 return this . config . plugins . find ( ( info ) => info . name === pluginName ) ;
141147 }
142148
@@ -147,9 +153,10 @@ export default class CommandReferenceGenerate extends SfdxCommand {
147153 for ( const cmd of this . config . commands ) {
148154 // Only load topics for each plugin once
149155 if ( cmd . pluginName && ! plugins [ cmd . pluginName ] ) {
150- const commandClass = await this . loadCommand ( cmd ) ;
156+ // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment, no-await-in-loop
157+ const commandClass = await loadCommand ( cmd ) ;
151158
152- if ( commandClass . plugin && commandClass . plugin . pjson . oclif . topics ) {
159+ if ( commandClass . plugin ? .pjson . oclif . topics ) {
153160 mergeDeep ( topicsMeta , commandClass . plugin . pjson . oclif . topics as Dictionary ) ;
154161 plugins [ commandClass . plugin . name ] = true ;
155162 }
@@ -161,7 +168,7 @@ export default class CommandReferenceGenerate extends SfdxCommand {
161168 private async loadCommands ( ) {
162169 const promises = this . config . commands . map ( async ( cmd ) => {
163170 try {
164- let commandClass = await this . loadCommand ( cmd ) ;
171+ let commandClass = await loadCommand ( cmd ) ;
165172 let obj = Object . assign ( { } as JsonMap , cmd , commandClass , {
166173 flags : Object . assign ( { } , cmd . flags , commandClass . flags ) ,
167174 } ) ;
@@ -170,7 +177,7 @@ export default class CommandReferenceGenerate extends SfdxCommand {
170177 while ( commandClass !== undefined ) {
171178 commandClass = Object . getPrototypeOf ( commandClass ) || undefined ;
172179 obj = Object . assign ( { } , commandClass , obj , {
173- flags : Object . assign ( { } , commandClass && commandClass . flags , obj . flags ) ,
180+ flags : Object . assign ( { } , commandClass ? .flags , obj . flags ) ,
174181 } ) ;
175182 }
176183
@@ -182,8 +189,7 @@ export default class CommandReferenceGenerate extends SfdxCommand {
182189 const commands = await Promise . all ( promises ) ;
183190 return uniqBy ( commands , 'id' ) ;
184191 }
185-
186- private async loadCommand ( command ) {
187- return command . load . constructor . name === 'AsyncFunction' ? await command . load ( ) : command . load ( ) ;
188- }
189192}
193+
194+ const loadCommand = async ( command : Command . Loadable ) : Promise < Command . Class > =>
195+ command . load . constructor . name === 'AsyncFunction' ? command . load ( ) : command . load ( ) ;
0 commit comments