Skip to content

Commit

Permalink
feat: sorted labels when recomposed
Browse files Browse the repository at this point in the history
  • Loading branch information
mshanemc committed Aug 8, 2024
1 parent e8676fb commit 99ceb9e
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 9 deletions.
8 changes: 7 additions & 1 deletion src/convert/convertContext/decomposedCustomLabelFinalizer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import { join } from 'node:path';
import { ensure, JsonMap } from '@salesforce/ts-types';
import type { CustomLabel } from '@jsforce/jsforce-node/lib/api/metadata';
import { customLabelHasFullName } from '../../utils/metadata';
import { MetadataType } from '../../registry';
import { XML_NS_KEY, XML_NS_URL } from '../../common/constants';
import { JsToXml } from '../streams';
Expand Down Expand Up @@ -65,6 +66,11 @@ const generateXml = (children: Map<string, CustomLabel>): JsonMap => ({
['CustomLabels']: {
[XML_NS_KEY]: XML_NS_URL,
// for CustomLabels, that's `labels`
labels: Array.from(children.values()),
labels: Array.from(children.values()).filter(customLabelHasFullName).sort(sortLabelsByFullName),
},
});

type CustomLabelWithFullName = CustomLabel & { fullName: string };

const sortLabelsByFullName = (a: CustomLabelWithFullName, b: CustomLabelWithFullName): number =>
a.fullName.localeCompare(b.fullName);
9 changes: 1 addition & 8 deletions src/convert/transformers/decomposeLabelsTransformer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
*/

import type { CustomLabel } from '@jsforce/jsforce-node/lib/api/metadata';
import { SfError } from '@salesforce/core/sfError';
import { customLabelHasFullName } from '../../utils/metadata';
import { calculateRelativePath } from '../../utils/path';
import { SourceComponent } from '../../resolve/sourceComponent';
import { ToSourceFormatInput, WriteInfo } from '../types';
Expand Down Expand Up @@ -48,10 +48,3 @@ export class LabelMetadataTransformer extends DefaultMetadataTransformer {

// toSourceFormat uses the default (merge them with the existing label)
}

const customLabelHasFullName = (label: CustomLabel): label is CustomLabel & { fullName: string } => {
if (label.fullName === undefined) {
throw SfError.create({ message: 'Label does not have a fullName', data: label });
}
return true;
};
9 changes: 9 additions & 0 deletions src/utils/metadata.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
* For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause
*/

import type { CustomLabel } from '@jsforce/jsforce-node/lib/api/metadata';
import { SfError } from '@salesforce/core';
import { META_XML_SUFFIX } from '../common';

export function generateMetaXML(typeName: string, apiVersion: string, status: string): string {
Expand All @@ -25,3 +27,10 @@ export function generateMetaXMLPath(sourcePath: string): string {
export function trimMetaXmlSuffix(sourcePath: string): string {
return sourcePath.endsWith(META_XML_SUFFIX) ? sourcePath.replace(META_XML_SUFFIX, '') : sourcePath;
}

export const customLabelHasFullName = (label: CustomLabel): label is CustomLabel & { fullName: string } => {
if (label.fullName === undefined) {
throw SfError.create({ message: 'Label does not have a fullName', data: label });
}
return true;
};

0 comments on commit 99ceb9e

Please sign in to comment.