55 * For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause
66 */
77
8+ import * as fs from 'fs/promises' ;
89import * as os from 'os' ;
910import * as path from 'path' ;
10- import { pathExists , readJSON } from 'fs-extra' ;
1111import { SfCommand } from '@salesforce/sf-plugins-core' ;
1212import { Command , Flags , Interfaces } from '@oclif/core' ;
1313import { Messages , SfError } from '@salesforce/core' ;
14- import { AnyJson , Dictionary , ensure , ensureString , JsonMap } from '@salesforce/ts-types' ;
14+ import { AnyJson , ensure , ensureString , JsonMap } from '@salesforce/ts-types' ;
1515import chalk = require( 'chalk' ) ;
16+ import { parseJsonMap } from '@salesforce/kit' ;
1617import { Ditamap } from '../../ditamap/ditamap' ;
1718import { Docs } from '../../docs' ;
18- import { CommandClass , events , mergeDeep } from '../../utils' ;
19+ import { CommandClass , events } from '../../utils' ;
1920
2021// Initialize Messages with the current plugin directory
2122Messages . importMessagesDirectory ( __dirname ) ;
2223const messages = Messages . loadMessages ( '@salesforce/plugin-command-reference' , 'main' ) ;
2324
25+ const fileExists = async ( filePath : string ) : Promise < boolean > =>
26+ fs
27+ . stat ( filePath )
28+ . then ( ( ) => true )
29+ . catch ( ( ) => false ) ;
30+
2431export default class CommandReferenceGenerate extends SfCommand < AnyJson > {
2532 public static description = messages . getMessage ( 'commandDescription' ) ;
2633
@@ -58,8 +65,8 @@ export default class CommandReferenceGenerate extends SfCommand<AnyJson> {
5865 let pluginNames : string [ ] ;
5966 if ( ! flags . plugins && ! flags . all ) {
6067 const pJsonPath = path . join ( process . cwd ( ) , 'package.json' ) ;
61- if ( await pathExists ( pJsonPath ) ) {
62- const packageJson = ( await readJSON ( pJsonPath ) ) as JsonMap ;
68+ if ( await fileExists ( pJsonPath ) ) {
69+ const packageJson = parseJsonMap ( await fs . readFile ( pJsonPath , 'utf-8' ) ) ;
6370 pluginNames = [ ensureString ( packageJson . name ) ] ;
6471 } else {
6572 throw new SfError (
@@ -177,7 +184,7 @@ export default class CommandReferenceGenerate extends SfCommand<AnyJson> {
177184 const commandClass = await this . loadCommand ( cmd ) ;
178185
179186 if ( commandClass . plugin ?. pjson . oclif . topics ) {
180- mergeDeep ( topicsMeta , commandClass . plugin . pjson . oclif . topics as Dictionary ) ;
187+ Object . assign ( topicsMeta , commandClass . plugin . pjson . oclif . topics ) ;
181188 plugins [ commandClass . plugin . name ] = true ;
182189 }
183190 }
@@ -203,10 +210,10 @@ export default class CommandReferenceGenerate extends SfCommand<AnyJson> {
203210
204211 return obj as unknown as CommandClass ;
205212 } catch ( error ) {
206- return Object . assign ( { } , cmd ) as unknown as CommandClass ;
213+ return cmd as unknown as CommandClass ;
207214 }
208215 } ) ;
209- const commands = ( await Promise . all ( promises ) ) as CommandClass [ ] ;
216+ const commands = await Promise . all ( promises ) ;
210217 return Array . from (
211218 commands
212219 . reduce ( ( acc : Map < string , CommandClass > , cmd : CommandClass ) => {
0 commit comments