Skip to content

Commit 34219eb

Browse files
authored
chore: sort cem output by name (#13188)
1 parent b0a425e commit 34219eb

1 file changed

Lines changed: 32 additions & 0 deletions

File tree

packages/tools/lib/cem/custom-elements-manifest.config.mjs

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -576,6 +576,38 @@ export default {
576576
}
577577
}
578578
},
579+
{
580+
name: 'alphabetical-sort-plugin',
581+
packageLinkPhase({ customElementsManifest }) {
582+
const sortByName = (arr) => {
583+
if (Array.isArray(arr)) {
584+
arr.sort((a, b) => {
585+
if (a?.name && b?.name) {
586+
return a.name.localeCompare(b.name);
587+
}
588+
return 0;
589+
});
590+
}
591+
};
592+
593+
const sortArraysInObject = (obj) => {
594+
if (!obj || typeof obj !== 'object') return;
595+
596+
for (const key in obj) {
597+
if (Array.isArray(obj[key])) {
598+
sortByName(obj[key]);
599+
obj[key].forEach(item => sortArraysInObject(item));
600+
} else if (typeof obj[key] === 'object') {
601+
sortArraysInObject(obj[key]);
602+
}
603+
}
604+
};
605+
606+
customElementsManifest.modules?.forEach(moduleDoc => {
607+
sortArraysInObject(moduleDoc);
608+
});
609+
}
610+
},
579611
wrapPluginForQuietMode(generateCustomData({ outdir: "dist", cssFileName: null, cssPropertiesDocs: false })),
580612
wrapPluginForQuietMode(customElementJetBrainsPlugin({ outdir: "dist", cssFileName: null, cssPropertiesDocs: false }))
581613
],

0 commit comments

Comments
 (0)