Skip to content

Commit

Permalink
feat: rename decomposed workflows for sfdx-git-delta detection
Browse files Browse the repository at this point in the history
  • Loading branch information
mcarvin8 committed Nov 4, 2024
1 parent c34fbd4 commit 8d6a61f
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 1 deletion.
9 changes: 9 additions & 0 deletions src/helpers/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,12 @@ export const DEFAULT_UNIQUE_ID_ELEMENTS: string = 'fullName,name';
export const LOG_FILE = 'disassemble.log';
export const DECOMPOSED_FILE_TYPES: string[] = ['xml', 'json', 'yaml'];
export const IGNORE_FILE = '.sfdecomposerignore';
export const WORKFLOW_SUFFIX_MAPPING: { [key: string]: string } = {
'alerts-meta.xml': 'workflowAlert-meta.xml',
'fieldUpdates-meta.xml': 'workflowFieldUpdate-meta.xml',
'flowActions-meta.xml': 'workflowFlowAction-meta.xml',
'knowledgePublishes-meta.xml': 'workflowKnowledgePublish-meta.xml',
'outboundMessages-meta.xml': 'workflowOutboundMessage-meta.xml',
'rules-meta.xml': 'workflowRule-meta.xml',
'tasks-meta.xml': 'workflowTask-meta.xml',
};
21 changes: 20 additions & 1 deletion src/service/decomposeFileHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { DisassembleXMLFileHandler, setLogLevel } from 'xml-disassembler';
import { XmlToYamlDisassembler } from 'xml2yaml-disassembler';
import { XmlToJsonDisassembler } from 'xml2json-disassembler';

import { CUSTOM_LABELS_FILE } from '../helpers/constants.js';
import { CUSTOM_LABELS_FILE, WORKFLOW_SUFFIX_MAPPING } from '../helpers/constants.js';
import { moveFiles } from './moveFiles.js';

export async function decomposeFileHandler(
Expand Down Expand Up @@ -41,6 +41,9 @@ export async function decomposeFileHandler(
} else {
await disassembleHandler(metadataPath, uniqueIdElements, prepurge, postpurge, format, ignorePath);
}
if (metaSuffix === 'workflow') {
await renameWorkflows(metadataPath);
}
}
}

Expand Down Expand Up @@ -111,3 +114,19 @@ async function subDirectoryHandler(
}
}
}

async function renameWorkflows(directory: string): Promise<void> {
const files = await readdir(directory, { recursive: true });

for (const file of files) {
// Check if the file matches any suffix in WORKFLOW_SUFFIX_MAPPING
for (const [suffix, newSuffix] of Object.entries(WORKFLOW_SUFFIX_MAPPING)) {
if (file.endsWith(suffix)) {
const oldFilePath = join(directory, file);
const newFilePath = join(directory, file.replace(suffix, newSuffix));
await rename(oldFilePath, newFilePath);
break;
}
}
}
}

0 comments on commit 8d6a61f

Please sign in to comment.