sf-package-list
Version:
Convert Salesforce package.xml manifests to and from plain-text list format.
36 lines • 1.58 kB
JavaScript
import { readFile, writeFile } from 'node:fs/promises';
import { parseManifestXml } from './parseManifest.js';
export async function packageXmlToList({ xmlPath, listPath, noApiVersion, }) {
const warnings = [];
if (!xmlPath) {
warnings.push('No package.xml file path was provided. Creating empty list file.');
await writeFile(listPath, '');
return { packageList: '', warnings };
}
try {
const xml = await readFile(xmlPath, 'utf-8');
const manifest = parseManifestXml(xml);
if (manifest.types.length === 0) {
warnings.push('The provided package is invalid or has no components. Creating empty list file.');
await writeFile(listPath, '');
return { packageList: '', warnings };
}
const packageList = buildPackageList(manifest, noApiVersion);
await writeFile(listPath, packageList);
return { packageList, warnings };
}
catch (err) {
const errMessage = err instanceof Error ? err.message : String(err);
warnings.push(`The provided package is invalid or could not be read. Creating empty list file. ${errMessage}`);
await writeFile(listPath, '');
return { packageList: '', warnings };
}
}
function buildPackageList(manifest, noApiVersion) {
const lines = manifest.types.map((type) => `${type.name}: ${type.members.join(', ')}`);
if (manifest.version && !noApiVersion) {
lines.push(`Version: ${manifest.version}`);
}
return lines.join('\n');
}
//# sourceMappingURL=packageXmlToList.js.map