11import { SfCommand , Flags } from "@salesforce/sf-plugins-core" ;
22import { Messages , SfError } from "@salesforce/core" ;
3- import * as core from "lightning-flow-scanner-core" ;
4- import * as fse from "fs-extra" ;
53import chalk from "chalk" ;
64import { exec } from "child_process" ;
75
86import { loadScannerOptions } from "../../libs/ScannerConfig.js" ;
97import { FindFlows } from "../../libs/FindFlows.js" ;
108import { ScanResult } from "../../models/ScanResult.js" ;
119
10+ import {
11+ parse ,
12+ ParsedFlow ,
13+ scan ,
14+ RuleResult ,
15+ ResultDetails ,
16+ ScanResult as scanResults ,
17+ } from "lightning-flow-scanner-core" ;
18+
1219Messages . importMessagesDirectoryFromMetaUrl ( import . meta. url ) ;
1320
1421const messages = Messages . loadMessages ( "lightning-flow-scanner" , "command" ) ;
@@ -21,6 +28,7 @@ export default class Scan extends SfCommand<ScanResult> {
2128 "sf flow scan -c path/to/config.json" ,
2229 "sf flow scan -c path/to/config.json --failon warning" ,
2330 "sf flow scan -d path/to/flows/directory" ,
31+ "sf flow scan -p path/to/single/file.flow-meta.xml" ,
2432 ] ;
2533
2634 protected static requiresUsername = false ;
@@ -56,10 +64,13 @@ export default class Scan extends SfCommand<ScanResult> {
5664 description : "Force retrieve Flows from org at the start of the command" ,
5765 default : false ,
5866 } ) ,
59- sourcepath : Flags . directory ( {
67+ sourcepath : Flags . file ( {
6068 char : "p" ,
6169 description : "Comma-separated list of source flow paths to scan" ,
6270 required : false ,
71+ aliases : [ "files" ] ,
72+ multiple : true ,
73+ exists : true ,
6374 } ) ,
6475 targetusername : Flags . string ( {
6576 char : "u" ,
@@ -82,14 +93,15 @@ export default class Scan extends SfCommand<ScanResult> {
8293 this . spinner . start ( `Identified ${ flowFiles . length } flows to scan` ) ;
8394 // to
8495 // core.Flow
85- const parsedFlows = await core . parse ( flowFiles ) ;
96+ const parsedFlows : ParsedFlow [ ] = await parse ( flowFiles ) ;
97+ this . debug ( `parsed flows ${ parsedFlows . length } ` , ...parsedFlows ) ;
8698
87- const scanResults : core . ScanResult [ ] =
99+ const scanResults : scanResults [ ] =
88100 this . userConfig && Object . keys ( this . userConfig ) . length > 0
89- ? core . scan ( parsedFlows , this . userConfig )
90- : core . scan ( parsedFlows ) ;
101+ ? scan ( parsedFlows , this . userConfig )
102+ : scan ( parsedFlows ) ;
91103
92- this . debug ( " scan results" , ...scanResults ) ;
104+ this . debug ( ` scan results: ${ scanResults . length } ` , ...scanResults ) ;
93105 this . spinner . stop ( `Scan complete` ) ;
94106 this . log ( "" ) ;
95107
@@ -175,7 +187,7 @@ export default class Scan extends SfCommand<ScanResult> {
175187 return { summary, status : status , results } ;
176188 }
177189
178- private findFlows ( directory : string , sourcepath : string ) {
190+ private findFlows ( directory : string , sourcepath : string [ ] ) {
179191 // List flows that will be scanned
180192 let flowFiles ;
181193 if ( directory && sourcepath ) {
@@ -186,7 +198,7 @@ export default class Scan extends SfCommand<ScanResult> {
186198 } else if ( directory ) {
187199 flowFiles = FindFlows ( directory ) ;
188200 } else if ( sourcepath ) {
189- flowFiles = sourcepath . split ( "," ) . filter ( ( f ) => fse . exists ( f ) ) ;
201+ flowFiles = sourcepath ;
190202 } else {
191203 flowFiles = FindFlows ( "." ) ;
192204 }
@@ -222,7 +234,7 @@ export default class Scan extends SfCommand<ScanResult> {
222234 for ( const scanResult of scanResults ) {
223235 const flowName = scanResult . flow . label ;
224236 const flowType = scanResult . flow . type [ 0 ] ;
225- for ( const ruleResult of scanResult . ruleResults as core . RuleResult [ ] ) {
237+ for ( const ruleResult of scanResult . ruleResults as RuleResult [ ] ) {
226238 const ruleDescription = ruleResult . ruleDefinition . description ;
227239 const rule = ruleResult . ruleDefinition . label ;
228240 if (
@@ -231,7 +243,7 @@ export default class Scan extends SfCommand<ScanResult> {
231243 ruleResult . details . length > 0
232244 ) {
233245 const severity = ruleResult . severity || "error" ;
234- for ( const result of ruleResult . details as core . ResultDetails [ ] ) {
246+ for ( const result of ruleResult . details as ResultDetails [ ] ) {
235247 const detailObj = Object . assign ( result , {
236248 ruleDescription,
237249 rule,
0 commit comments