Skip to content

Commit 4eb1142

Browse files
committed
fix: add backward compatibility and warning for sourcepath flag
1 parent 5741ce6 commit 4eb1142

File tree

3 files changed

+65
-6
lines changed

3 files changed

+65
-6
lines changed

package-lock.json

Lines changed: 36 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
"@salesforce/sf-plugins-core": "^12.1.3",
99
"chalk": "^5.4.1",
1010
"cosmiconfig": "^9.0.0",
11+
"fs-extra": "^11.3.0",
1112
"glob": "^11.0.1",
1213
"lightning-flow-scanner-core": "4.15.0"
1314
},

src/commands/flow/scan.ts

Lines changed: 28 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { SfCommand, Flags } from "@salesforce/sf-plugins-core";
22
import { Messages, SfError } from "@salesforce/core";
33
import chalk from "chalk";
4+
import * as fse from "fs-extra";
45
import { exec } from "child_process";
56

67
import { loadScannerOptions } from "../../libs/ScannerConfig.js";
@@ -27,7 +28,8 @@ export default class Scan extends SfCommand<ScanResult> {
2728
"sf flow scan -c path/to/config.json",
2829
"sf flow scan -c path/to/config.json --failon warning",
2930
"sf flow scan -d path/to/flows/directory",
30-
"sf flow scan -p path/to/single/file.flow-meta.xml",
31+
"sf flow scan -p path/to/single/file.flow-meta.xml,path/to/another/file.flow-meta.xml",
32+
"sf flow scan --files path/to/single/file.flow-meta.xml path/to/another/file.flow-meta.xml",
3133
];
3234

3335
protected static requiresUsername = false;
@@ -63,13 +65,16 @@ export default class Scan extends SfCommand<ScanResult> {
6365
description: "Force retrieve Flows from org at the start of the command",
6466
default: false,
6567
}),
66-
sourcepath: Flags.file({
68+
sourcepath: Flags.directory({
6769
char: "p",
6870
description: "Comma-separated list of source flow paths to scan",
6971
required: false,
70-
aliases: ["files"],
72+
multiple: false,
73+
}),
74+
files: Flags.file({
7175
multiple: true,
7276
exists: true,
77+
description: "List of source flows paths to scan",
7378
}),
7479
targetusername: Flags.string({
7580
char: "u",
@@ -88,7 +93,10 @@ export default class Scan extends SfCommand<ScanResult> {
8893
if (flags.targetusername) {
8994
await this.retrieveFlowsFromOrg(flags.targetusername);
9095
}
91-
const flowFiles = this.findFlows(flags.directory, flags.sourcepath);
96+
97+
const targets: string | string[] = flags.sourcepath ?? flags.files;
98+
99+
const flowFiles = this.findFlows(flags.directory, targets);
92100
this.spinner.start(`Identified ${flowFiles.length} flows to scan`);
93101
// to
94102
// core.Flow
@@ -186,7 +194,7 @@ export default class Scan extends SfCommand<ScanResult> {
186194
return { summary, status: status, results };
187195
}
188196

189-
private findFlows(directory: string, sourcepath: string[]) {
197+
private findFlows(directory: string, sourcepath: string | string[]) {
190198
// List flows that will be scanned
191199
let flowFiles;
192200
if (directory && sourcepath) {
@@ -197,7 +205,21 @@ export default class Scan extends SfCommand<ScanResult> {
197205
} else if (directory) {
198206
flowFiles = FindFlows(directory);
199207
} else if (sourcepath) {
200-
flowFiles = sourcepath;
208+
if (typeof sourcepath === "string") {
209+
this.log(chalk.cyanBright("********"));
210+
this.log("");
211+
this.log(
212+
chalk.yellowBright(
213+
"WARN: flag --path or -p will be deprecated, please use --files to scan flow source files",
214+
),
215+
);
216+
this.log("");
217+
this.log(chalk.cyanBright("********"));
218+
this.log("");
219+
flowFiles = sourcepath.split(",").filter((f) => fse.exists(f));
220+
} else {
221+
flowFiles = sourcepath;
222+
}
201223
} else {
202224
flowFiles = FindFlows(".");
203225
}

0 commit comments

Comments
 (0)