diff --git a/src/commands/mdt/git/delta.ts b/src/commands/mdt/git/delta.ts index dc3ba55..145b6bd 100644 --- a/src/commands/mdt/git/delta.ts +++ b/src/commands/mdt/git/delta.ts @@ -11,6 +11,7 @@ import { mkdirRecursive, writeFile, copyFile, + copyFolderRecursive, } from "../../../utils/utilities"; import { gitShow, @@ -204,6 +205,7 @@ export default class Differ extends SfdxCommand { case `${FMD_FOLDER}/staticresources`: const staticResourceFolder = `${FMD_FOLDER}/staticresources`; if (folderPath !== staticResourceFolder) { + // static resource of type folder const subFolderPath = folderPath.replace( staticResourceFolder + "/", "" @@ -216,7 +218,12 @@ export default class Differ extends SfdxCommand { `${staticResourceFolder}/${resourceFolderName}.resource-meta.xml`, `${packagedir}/${staticResourceFolder}/${resourceFolderName}.resource-meta.xml` ); + await copyFolderRecursive( + `${staticResourceFolder}/${resourceFolderName}`, + `${packagedir}/${staticResourceFolder}` + ); } else { + // static resource of type file if (!metadataFilePath.endsWith(".resource-meta.xml")) { const resourceName = substringBeforeLast( substringAfterLast(metadataFilePath, "/"), @@ -227,11 +234,11 @@ export default class Differ extends SfdxCommand { `${packagedir}/${folderPath}/${resourceName}.resource-meta.xml` ); } + await copyFile( + `${metadataFilePath}`, + `${packagedir}/${metadataFilePath}` + ); } - await copyFile( - `${metadataFilePath}`, - `${packagedir}/${metadataFilePath}` - ); break; /** handle custom labels */ case `${FMD_FOLDER}/labels`: diff --git a/src/utils/utilities.ts b/src/utils/utilities.ts index 1b7073f..e96c64b 100644 --- a/src/utils/utilities.ts +++ b/src/utils/utilities.ts @@ -1,4 +1,5 @@ import * as fs from "fs"; +import * as path from "path"; /** * compare profile access file names @@ -187,6 +188,34 @@ const copyFile = async ( } }; +/** + * copy folder source recusively to folder target + * @param source + * @param target + */ +const copyFolderRecursive = async (source, target) => { + let files = []; + + // Check if folder needs to be created or integrated + const targetFolder = path.join(target, path.basename(source)); + if (!fs.existsSync(targetFolder)) { + fs.mkdirSync(targetFolder); + } + + // Copy + if (fs.lstatSync(source).isDirectory()) { + files = fs.readdirSync(source); + for (const file of files) { + const curSource = path.join(source, file); + if (fs.lstatSync(curSource).isDirectory()) { + await copyFolderRecursive(curSource, targetFolder); + } else { + await copyFile(curSource, targetFolder + "/" + file); + } + } + } +}; + export { substringBefore, substringBeforeLast, @@ -199,4 +228,5 @@ export { writeFile, writeXMLFile, copyFile, + copyFolderRecursive, };