sf-decomposer
Version:
Break down large Salesforce metadata files into smaller, more manageable files for version control and then recreate deployment-compatible files.
27 lines • 944 B
JavaScript
import { writeFile } from 'node:fs/promises';
import { parseXML, buildXMLString } from 'xml-disassembler';
export async function stripRootAndDisassemble(fullPath, handler, format) {
const parsed = await parseXML(fullPath);
const contents = parsed?.LoyaltyProgramSetup;
// Remove the root and build XML with just the inner nodes (programProcesses)
const stripped = {
'?xml': {
'@_version': '1.0',
'@_encoding': 'UTF-8',
},
};
for (const [key, value] of Object.entries(contents)) {
stripped[key] = value;
}
const newXml = buildXMLString(stripped);
await writeFile(fullPath, newXml, 'utf-8');
await handler.disassemble({
filePath: fullPath,
format,
strategy: 'unique-id',
prePurge: false,
postPurge: true,
uniqueIdElements: 'parameterName,ruleName',
});
}
//# sourceMappingURL=stripRootAndDisassemble.js.map