UNPKG

@salesforce/source-deploy-retrieve

Version:

JavaScript library to run Salesforce metadata deploys and retrieves

60 lines 2.74 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.DecomposedLabelsFinalizer = void 0; /* * Copyright (c) 2023, salesforce.com, inc. * All rights reserved. * Licensed under the BSD 3-Clause license. * For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause */ const node_path_1 = require("node:path"); const ts_types_1 = require("@salesforce/ts-types"); const metadata_1 = require("../../utils/metadata"); const constants_1 = require("../../common/constants"); const streams_1 = require("../streams"); const transactionFinalizer_1 = require("./transactionFinalizer"); /** * Merges child components that share the same parent in the conversion pipeline * into a single file. * * Inserts unclaimed child components into the parent that belongs to the default package */ class DecomposedLabelsFinalizer extends transactionFinalizer_1.ConvertTransactionFinalizer { transactionState = { customLabelByFullName: new Map(), }; /** to support custom presets (the only way this code should get hit at all pass in the type from a transformer that has registry access */ customLabelsType; // have to maintain the existing interface // eslint-disable-next-line @typescript-eslint/require-await, @typescript-eslint/no-unused-vars async finalize(defaultDirectory) { if (this.transactionState.customLabelByFullName.size === 0) { return []; } return [ { component: { type: (0, ts_types_1.ensure)(this.customLabelsType, 'DecomposedCustomLabelsFinalizer should have set customLabelsType'), fullName: 'CustomLabels', }, writeInfos: [ { output: (0, node_path_1.join)((0, ts_types_1.ensure)(this.customLabelsType?.directoryName, 'directoryName missing from customLabels type'), 'CustomLabels.labels'), source: new streams_1.JsToXml(generateXml(this.transactionState.customLabelByFullName)), }, ], }, ]; } } exports.DecomposedLabelsFinalizer = DecomposedLabelsFinalizer; /** Return a json object that's built up from the mergeMap children */ const generateXml = (children) => ({ ['CustomLabels']: { [constants_1.XML_NS_KEY]: constants_1.XML_NS_URL, // for CustomLabels, that's `labels` labels: Array.from(children.values()).filter(metadata_1.customLabelHasFullName).sort(sortLabelsByFullName), }, }); const sortLabelsByFullName = (a, b) => a.fullName.localeCompare(b.fullName); //# sourceMappingURL=decomposedLabelsFinalizer.js.map