Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 13 additions & 47 deletions package-lock.json

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

9 changes: 3 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,14 @@
"dependencies": {
"@oclif/core": "^4.2.4",
"@salesforce/core": "^8.8.2",
"@salesforce/sf-plugins-core": "^12.1.2",
"@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.11.0",
"tslib": "^2",
"xml2js": "^0.6.2"
"lightning-flow-scanner-core": "^4.13.0"
},
"devDependencies": {
"@oclif/plugin-help": "^6.2.22",
"@oclif/plugin-help": "^6.2.23",
"@oclif/test": "^4.1.8",
"@salesforce/dev-config": "^4.3.1",
"@salesforce/ts-sinon": "^1.4.30",
Expand Down
36 changes: 24 additions & 12 deletions src/commands/flow/scan.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,21 @@
import { SfCommand, Flags } from "@salesforce/sf-plugins-core";
import { Messages, SfError } from "@salesforce/core";
import * as core from "lightning-flow-scanner-core";
import * as fse from "fs-extra";
import chalk from "chalk";
import { exec } from "child_process";

import { loadScannerOptions } from "../../libs/ScannerConfig.js";
import { FindFlows } from "../../libs/FindFlows.js";
import { ScanResult } from "../../models/ScanResult.js";

import {
parse,
ParsedFlow,
scan,
RuleResult,
ResultDetails,
ScanResult as scanResults,
} from "lightning-flow-scanner-core";

Messages.importMessagesDirectoryFromMetaUrl(import.meta.url);

const messages = Messages.loadMessages("lightning-flow-scanner", "command");
Expand All @@ -21,6 +28,7 @@ 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",
];

protected static requiresUsername = false;
Expand Down Expand Up @@ -56,10 +64,13 @@ export default class Scan extends SfCommand<ScanResult> {
description: "Force retrieve Flows from org at the start of the command",
default: false,
}),
sourcepath: Flags.directory({
sourcepath: Flags.file({
char: "p",
description: "Comma-separated list of source flow paths to scan",
required: false,
aliases: ["files"],
multiple: true,
exists: true,
}),
targetusername: Flags.string({
char: "u",
Expand All @@ -82,14 +93,15 @@ export default class Scan extends SfCommand<ScanResult> {
this.spinner.start(`Identified ${flowFiles.length} flows to scan`);
// to
// core.Flow
const parsedFlows = await core.parse(flowFiles);
const parsedFlows: ParsedFlow[] = await parse(flowFiles);
this.debug(`parsed flows ${parsedFlows.length}`, ...parsedFlows);

const scanResults: core.ScanResult[] =
const scanResults: scanResults[] =
this.userConfig && Object.keys(this.userConfig).length > 0
? core.scan(parsedFlows, this.userConfig)
: core.scan(parsedFlows);
? scan(parsedFlows, this.userConfig)
: scan(parsedFlows);

this.debug("scan results", ...scanResults);
this.debug(`scan results: ${scanResults.length}`, ...scanResults);
this.spinner.stop(`Scan complete`);
this.log("");

Expand Down Expand Up @@ -175,7 +187,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[]) {
// List flows that will be scanned
let flowFiles;
if (directory && sourcepath) {
Expand All @@ -186,7 +198,7 @@ export default class Scan extends SfCommand<ScanResult> {
} else if (directory) {
flowFiles = FindFlows(directory);
} else if (sourcepath) {
flowFiles = sourcepath.split(",").filter((f) => fse.exists(f));
flowFiles = sourcepath;
} else {
flowFiles = FindFlows(".");
}
Expand Down Expand Up @@ -222,7 +234,7 @@ export default class Scan extends SfCommand<ScanResult> {
for (const scanResult of scanResults) {
const flowName = scanResult.flow.label;
const flowType = scanResult.flow.type[0];
for (const ruleResult of scanResult.ruleResults as core.RuleResult[]) {
for (const ruleResult of scanResult.ruleResults as RuleResult[]) {
const ruleDescription = ruleResult.ruleDefinition.description;
const rule = ruleResult.ruleDefinition.label;
if (
Expand All @@ -231,7 +243,7 @@ export default class Scan extends SfCommand<ScanResult> {
ruleResult.details.length > 0
) {
const severity = ruleResult.severity || "error";
for (const result of ruleResult.details as core.ResultDetails[]) {
for (const result of ruleResult.details as ResultDetails[]) {
const detailObj = Object.assign(result, {
ruleDescription,
rule,
Expand Down
2 changes: 1 addition & 1 deletion src/libs/CoreFixService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import {
scan,
ScanResult as ScanResults,
} from "lightning-flow-scanner-core";
import { IRulesConfig } from "lightning-flow-scanner-core/main/interfaces/IRulesConfig.js";
import IRulesConfig from "lightning-flow-scanner-core/main/interfaces/IRulesConfig.js";
import { writeFileSync } from "node:fs";

import { FindFlows } from "./FindFlows.js";
Expand Down
22 changes: 0 additions & 22 deletions src/libs/XMLParser.ts

This file was deleted.

7 changes: 6 additions & 1 deletion test/commands/flow/scan.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,12 @@ describe("flow:scan", () => {
let output: ScanResult;
try {
const output = await new Scan(
["--directory", "test/", "--sourcepath", "test/"],
[
"--directory",
"test/",
"--sourcepath",
"test/commands/flow/scan.test.ts",
],
config,
).run();
console.log(output);
Expand Down
Loading