From 8d6a61f6c47299e8f58fda7750c56e4f85482f87 Mon Sep 17 00:00:00 2001 From: Matt Carvin <90224411+mcarvin8@users.noreply.github.com> Date: Mon, 4 Nov 2024 13:52:25 -0500 Subject: [PATCH] feat: rename decomposed workflows for sfdx-git-delta detection --- src/helpers/constants.ts | 9 +++++++++ src/service/decomposeFileHandler.ts | 21 ++++++++++++++++++++- 2 files changed, 29 insertions(+), 1 deletion(-) diff --git a/src/helpers/constants.ts b/src/helpers/constants.ts index dbaed51..a35a17f 100644 --- a/src/helpers/constants.ts +++ b/src/helpers/constants.ts @@ -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', +}; diff --git a/src/service/decomposeFileHandler.ts b/src/service/decomposeFileHandler.ts index c035c26..4569bac 100644 --- a/src/service/decomposeFileHandler.ts +++ b/src/service/decomposeFileHandler.ts @@ -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( @@ -41,6 +41,9 @@ export async function decomposeFileHandler( } else { await disassembleHandler(metadataPath, uniqueIdElements, prepurge, postpurge, format, ignorePath); } + if (metaSuffix === 'workflow') { + await renameWorkflows(metadataPath); + } } } @@ -111,3 +114,19 @@ async function subDirectoryHandler( } } } + +async function renameWorkflows(directory: string): Promise { + 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; + } + } + } +}