Skip to content

Commit

Permalink
Merge pull request #139 from Lightning-Flow-Scanner/backward-compatib…
Browse files Browse the repository at this point in the history
…ility-on-scan

fix: add backward compatibility and warning for sourcepath flag
  • Loading branch information
junners authored Jan 27, 2025
2 parents 5741ce6 + 4eb1142 commit 52bf104
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 6 deletions.
36 changes: 36 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
"@salesforce/sf-plugins-core": "^12.1.3",
"chalk": "^5.4.1",
"cosmiconfig": "^9.0.0",
"fs-extra": "^11.3.0",
"glob": "^11.0.1",
"lightning-flow-scanner-core": "4.15.0"
},
Expand Down
34 changes: 28 additions & 6 deletions src/commands/flow/scan.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { SfCommand, Flags } from "@salesforce/sf-plugins-core";
import { Messages, SfError } from "@salesforce/core";
import chalk from "chalk";
import * as fse from "fs-extra";
import { exec } from "child_process";

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

protected static requiresUsername = false;
Expand Down Expand Up @@ -63,13 +65,16 @@ export default class Scan extends SfCommand<ScanResult> {
description: "Force retrieve Flows from org at the start of the command",
default: false,
}),
sourcepath: Flags.file({
sourcepath: Flags.directory({
char: "p",
description: "Comma-separated list of source flow paths to scan",
required: false,
aliases: ["files"],
multiple: false,
}),
files: Flags.file({
multiple: true,
exists: true,
description: "List of source flows paths to scan",
}),
targetusername: Flags.string({
char: "u",
Expand All @@ -88,7 +93,10 @@ export default class Scan extends SfCommand<ScanResult> {
if (flags.targetusername) {
await this.retrieveFlowsFromOrg(flags.targetusername);
}
const flowFiles = this.findFlows(flags.directory, flags.sourcepath);

const targets: string | string[] = flags.sourcepath ?? flags.files;

const flowFiles = this.findFlows(flags.directory, targets);
this.spinner.start(`Identified ${flowFiles.length} flows to scan`);
// to
// core.Flow
Expand Down Expand Up @@ -186,7 +194,7 @@ export default class Scan extends SfCommand<ScanResult> {
return { summary, status: status, results };
}

private findFlows(directory: string, sourcepath: string[]) {
private findFlows(directory: string, sourcepath: string | string[]) {
// List flows that will be scanned
let flowFiles;
if (directory && sourcepath) {
Expand All @@ -197,7 +205,21 @@ export default class Scan extends SfCommand<ScanResult> {
} else if (directory) {
flowFiles = FindFlows(directory);
} else if (sourcepath) {
flowFiles = sourcepath;
if (typeof sourcepath === "string") {
this.log(chalk.cyanBright("********"));
this.log("");
this.log(
chalk.yellowBright(
"WARN: flag --path or -p will be deprecated, please use --files to scan flow source files",
),
);
this.log("");
this.log(chalk.cyanBright("********"));
this.log("");
flowFiles = sourcepath.split(",").filter((f) => fse.exists(f));
} else {
flowFiles = sourcepath;
}
} else {
flowFiles = FindFlows(".");
}
Expand Down

0 comments on commit 52bf104

Please sign in to comment.