Skip to content

Commit d87d150

Browse files
committed
Sort LWC metadata targets and configurations
1 parent c2d90de commit d87d150

File tree

3 files changed

+50
-9
lines changed

3 files changed

+50
-9
lines changed

examples/markdown/docs/index.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,20 +12,20 @@ Represents an event that people can register for.
1212

1313
### [Price_Component__c](custom-objects/Price_Component__c.md)
1414

15-
### [Product_Price_Component__c](custom-objects/Product_Price_Component__c.md)
16-
1715
### [Product__c](custom-objects/Product__c.md)
1816

1917
Product that is sold or available for sale.
2018

21-
### [Sales_Order_Line__c](custom-objects/Sales_Order_Line__c.md)
22-
23-
Represents a line item on a sales order.
19+
### [Product_Price_Component__c](custom-objects/Product_Price_Component__c.md)
2420

2521
### [Sales_Order__c](custom-objects/Sales_Order__c.md)
2622

2723
Custom object for tracking sales orders.
2824

25+
### [Sales_Order_Line__c](custom-objects/Sales_Order_Line__c.md)
26+
27+
Represents a line item on a sales order.
28+
2929
### [Speaker__c](custom-objects/Speaker__c.md)
3030

3131
Represents a speaker at an event.

examples/markdown/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
"apexdocs": {
1616
"sourceDir": "force-app",
1717
"scope": ["global", "public", "protected", "private", "namespaceaccessible"],
18-
"namespace": "ns"
18+
"namespace": "ns",
19+
"sortAlphabetically": true
1920
}
2021
}

src/core/reflection/sort-types-and-members.ts

Lines changed: 43 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
import { ClassMirror, EnumMirror, InterfaceMirror, Type } from '@cparra/apex-reflection';
22
import { ParsedFile, TopLevelType } from '../shared/types';
3-
import { isApexType, isObjectType } from '../shared/utils';
3+
import { isApexType, isLwcType, isObjectType } from '../shared/utils';
44
import { CustomObjectMetadata } from './sobject/reflect-custom-object-sources';
5+
import { LwcMetadata } from './lwc/reflect-lwc-source';
56

67
type Named = { name: string };
78

@@ -23,10 +24,15 @@ export function sortTypesAndMembers(
2324
type: sortCustomObjectFields(parsedFile.type, shouldSort),
2425
};
2526
}
27+
if (isLwcType(parsedFile.type)) {
28+
return {
29+
...parsedFile,
30+
type: sortLwcMetadata(parsedFile.type, shouldSort),
31+
};
32+
}
33+
2634
// For TriggerMetadata or any other types, return the original parsedFile unchanged
2735
return parsedFile;
28-
29-
// TODO: Parsed LWC members (properties and methods)
3036
})
3137
.sort((a, b) => sortByNames(shouldSort, a.type, b.type));
3238
}
@@ -85,3 +91,37 @@ function sortClassMembers(shouldSort: boolean, classType: ClassMirror): ClassMir
8591
properties: sortNamed(shouldSort, classType.properties),
8692
};
8793
}
94+
95+
function sortLwcMetadata(type: LwcMetadata, shouldSort: boolean): LwcMetadata {
96+
if (!shouldSort) {
97+
return type;
98+
}
99+
100+
const sortedType = { ...type };
101+
102+
// Sort targets.
103+
if (sortedType.targets?.target) {
104+
sortedType.targets = {
105+
...sortedType.targets,
106+
target: [...sortedType.targets.target].sort(),
107+
};
108+
}
109+
110+
// Sort targetConfigs.
111+
if (sortedType.targetConfigs?.targetConfig) {
112+
sortedType.targetConfigs = {
113+
...sortedType.targetConfigs,
114+
targetConfig: sortedType.targetConfigs.targetConfig.map((config) => {
115+
if (config.property) {
116+
return {
117+
...config,
118+
property: [...config.property].sort((a, b) => a['@_name'].localeCompare(b['@_name'])),
119+
};
120+
}
121+
return config;
122+
}),
123+
};
124+
}
125+
126+
return sortedType;
127+
}

0 commit comments

Comments
 (0)