Skip to content

Commit

Permalink
fix delta for static resources
Browse files Browse the repository at this point in the history
  • Loading branch information
benahm committed Sep 2, 2021
1 parent 8f47d3b commit caf21e3
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 4 deletions.
15 changes: 11 additions & 4 deletions src/commands/mdt/git/delta.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {
mkdirRecursive,
writeFile,
copyFile,
copyFolderRecursive,
} from "../../../utils/utilities";
import {
gitShow,
Expand Down Expand Up @@ -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 + "/",
""
Expand All @@ -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, "/"),
Expand All @@ -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`:
Expand Down
30 changes: 30 additions & 0 deletions src/utils/utilities.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import * as fs from "fs";
import * as path from "path";

/**
* compare profile access file names
Expand Down Expand Up @@ -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,
Expand All @@ -199,4 +228,5 @@ export {
writeFile,
writeXMLFile,
copyFile,
copyFolderRecursive,
};

0 comments on commit caf21e3

Please sign in to comment.