|
|
|
|
@ -1,4 +1,4 @@
|
|
|
|
|
import { getContainer, getFileAbosluteDir, getFileName } from '../../../../FlowHelpers/1.0.0/fileUtils';
|
|
|
|
|
import { getContainer, getFileName } from '../../../../FlowHelpers/1.0.0/fileUtils';
|
|
|
|
|
import {
|
|
|
|
|
IpluginDetails,
|
|
|
|
|
IpluginInputArgs,
|
|
|
|
|
@ -68,19 +68,30 @@ const plugin = (args: IpluginInputArgs): IpluginOutputArgs => {
|
|
|
|
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars,no-param-reassign
|
|
|
|
|
args.inputs = lib.loadDefaultValues(args.inputs, details);
|
|
|
|
|
|
|
|
|
|
const buildArrayInput = (arrayInput: unknown): string[] => String(arrayInput)?.trim().split(',') ?? [];
|
|
|
|
|
const terms = String(args.inputs.terms);
|
|
|
|
|
const pattern = String(args.inputs.pattern);
|
|
|
|
|
const { includeFileDirectory } = args.inputs;
|
|
|
|
|
|
|
|
|
|
const fileName = `${(args.inputs.includeFileDirectory ? `${getFileAbosluteDir(args.inputFileObj._id)}/` : '')
|
|
|
|
|
+ getFileName(args.inputFileObj._id)
|
|
|
|
|
}.${getContainer(args.inputFileObj._id)}`;
|
|
|
|
|
const searchCriteriasArray = buildArrayInput(args.inputs.terms)
|
|
|
|
|
const fileName = includeFileDirectory
|
|
|
|
|
? args.inputFileObj._id
|
|
|
|
|
: `${getFileName(args.inputFileObj._id)}.${getContainer(args.inputFileObj._id)}`;
|
|
|
|
|
|
|
|
|
|
const searchCriteriasArray = terms.trim().split(',')
|
|
|
|
|
.map((term) => term.replace(/[\\^$*+?.()|[\]{}]/g, '\\$&')); // https://github.com/tc39/proposal-regex-escaping
|
|
|
|
|
if (args.inputs.pattern) searchCriteriasArray.push(String(args.inputs.pattern));
|
|
|
|
|
|
|
|
|
|
if (pattern) {
|
|
|
|
|
searchCriteriasArray.push(pattern);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const searchCriteriaMatched = searchCriteriasArray
|
|
|
|
|
.find((searchCriteria) => new RegExp(searchCriteria).test(fileName));
|
|
|
|
|
const isAMatch = searchCriteriaMatched !== undefined;
|
|
|
|
|
if (isAMatch) args.jobLog(`'${fileName}' includes '${searchCriteriaMatched}'`);
|
|
|
|
|
|
|
|
|
|
if (isAMatch) {
|
|
|
|
|
args.jobLog(`'${fileName}' includes '${searchCriteriaMatched}'`);
|
|
|
|
|
} else {
|
|
|
|
|
args.jobLog(`'${fileName}' does not include any of the terms or patterns`);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return {
|
|
|
|
|
outputFileObj: args.inputFileObj,
|
|
|
|
|
|