build(docs-infra): sort NgModule exports by id (#26051)
PR Close #26051
This commit is contained in:

committed by
Kara Erickson

parent
56c86c7e79
commit
7f1cace2a2
@ -2,22 +2,12 @@ module.exports = function processNgModuleDocs(getDocFromAlias, createDocMessage,
|
||||
return {
|
||||
$runAfter: ['extractDecoratedClassesProcessor', 'computeIdsProcessor'],
|
||||
$runBefore: ['createSitemap'],
|
||||
exportDocTypes: ['directive', 'pipe'],
|
||||
$process(docs) {
|
||||
docs.forEach(doc => {
|
||||
if (doc.docType === 'ngmodule') {
|
||||
Object.keys(doc.ngmoduleOptions).forEach(key => {
|
||||
const value = doc.ngmoduleOptions[key];
|
||||
if (value && !Array.isArray(value)) {
|
||||
doc.ngmoduleOptions[key] = [value];
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
// Match all the directives/pipes to their module
|
||||
const errors = [];
|
||||
docs.forEach(doc => {
|
||||
if (['directive', 'pipe'].indexOf(doc.docType) !== -1) {
|
||||
if (this.exportDocTypes.indexOf(doc.docType) !== -1) {
|
||||
if (!doc.ngModules || doc.ngModules.length === 0) {
|
||||
errors.push(createDocMessage(`"${doc.id}" has no @ngModule tag. Docs of type "${doc.docType}" must have this tag.`, doc));
|
||||
return;
|
||||
@ -38,7 +28,8 @@ module.exports = function processNgModuleDocs(getDocFromAlias, createDocMessage,
|
||||
}
|
||||
|
||||
const ngModuleDoc = ngModuleDocs[0];
|
||||
const container = ngModuleDoc[doc.docType + 's'] = ngModuleDoc[doc.docType + 's'] || [];
|
||||
const containerName = getContainerName(doc.docType);
|
||||
const container = ngModuleDoc[containerName] = ngModuleDoc[containerName] || [];
|
||||
container.push(doc);
|
||||
|
||||
doc.ngModules[index] = ngModuleDoc;
|
||||
@ -50,6 +41,32 @@ module.exports = function processNgModuleDocs(getDocFromAlias, createDocMessage,
|
||||
errors.forEach(error => log.error(error));
|
||||
throw new Error('Failed to process NgModule relationships.');
|
||||
}
|
||||
|
||||
docs.forEach(doc => {
|
||||
if (doc.docType === 'ngmodule') {
|
||||
Object.keys(doc.ngmoduleOptions).forEach(key => {
|
||||
const value = doc.ngmoduleOptions[key];
|
||||
if (value && !Array.isArray(value)) {
|
||||
doc.ngmoduleOptions[key] = [value];
|
||||
}
|
||||
});
|
||||
this.exportDocTypes.forEach(type => {
|
||||
const containerName = getContainerName(type);
|
||||
const container = doc[containerName];
|
||||
if (container) {
|
||||
container.sort(byId);
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
function getContainerName(docType) {
|
||||
return docType + 's';
|
||||
}
|
||||
|
||||
function byId(a, b) {
|
||||
return a.id > b.id ? 1 : -1;
|
||||
}
|
||||
|
Reference in New Issue
Block a user