sf-decomposer
Version:
Split large Salesforce metadata files into version-control-friendly pieces and rebuild deployment-ready files.
36 lines • 1.75 kB
JavaScript
/* eslint-disable no-await-in-loop */
;
import { join } from 'node:path';
import { readdir, stat, rm, rename } from 'node:fs/promises';
import { CUSTOM_LABELS_FILE, CONCURRENCY_LIMITS } from '../../helpers/constants.js';
import { pLimit } from '../../helpers/pLimit.js';
import { moveFiles } from '../core/moveFiles.js';
export async function prePurgeLabels(metadataPath) {
const subFiles = await readdir(metadataPath);
for (const subFile of subFiles) {
const subfilePath = join(metadataPath, subFile);
if ((await stat(subfilePath)).isFile() && subFile !== CUSTOM_LABELS_FILE) {
await rm(subfilePath, { recursive: true });
}
}
}
export async function moveAndRenameLabels(metadataPath) {
const sourceDirectory = join(metadataPath, 'CustomLabels', 'labels');
const destinationDirectory = metadataPath;
const labelFiles = await readdir(sourceDirectory);
// Limit concurrent file operations to prevent file system overload
const limit = pLimit(CONCURRENCY_LIMITS.FILE_OPERATIONS);
const tasks = labelFiles
.filter((file) => file.includes('.labels-meta'))
.map((file) => limit(async () => {
const oldFilePath = join(sourceDirectory, file);
const newFileName = file.replace('.labels-meta', '.label-meta');
const newFilePath = join(destinationDirectory, newFileName);
await rename(oldFilePath, newFilePath);
}));
await Promise.all(tasks);
// istanbul ignore next -- callback only invoked if non-label files exist after rename
await moveFiles(sourceDirectory, destinationDirectory, () => true);
await rm(join(metadataPath, 'CustomLabels'), { recursive: true });
}
//# sourceMappingURL=customLabels.js.map