build(docs-infra): sort package exports by id (#26051)

Closes #26046

PR Close #26051
This commit is contained in:
Pete Bacon Darwin 2018-09-21 09:08:58 +01:00 committed by Kara Erickson
parent 82a14dc107
commit 56c86c7e79
2 changed files with 17 additions and 12 deletions

View File

@ -26,14 +26,14 @@ module.exports = function processPackages() {
// Partition the exports into groups by type
if (doc.exports) {
doc.ngmodules = doc.exports.filter(doc => doc.docType === 'ngmodule');
doc.classes = doc.exports.filter(doc => doc.docType === 'class');
doc.decorators = doc.exports.filter(doc => doc.docType === 'decorator');
doc.functions = doc.exports.filter(doc => doc.docType === 'function');
doc.structures = doc.exports.filter(doc => doc.docType === 'enum' || doc.docType === 'interface');
doc.directives = doc.exports.filter(doc => doc.docType === 'directive');
doc.pipes = doc.exports.filter(doc => doc.docType === 'pipe');
doc.types = doc.exports.filter(doc => doc.docType === 'type-alias' || doc.docType === 'const');
doc.ngmodules = doc.exports.filter(doc => doc.docType === 'ngmodule').sort(byId);
doc.classes = doc.exports.filter(doc => doc.docType === 'class').sort(byId);
doc.decorators = doc.exports.filter(doc => doc.docType === 'decorator').sort(byId);
doc.functions = doc.exports.filter(doc => doc.docType === 'function').sort(byId);
doc.structures = doc.exports.filter(doc => doc.docType === 'enum' || doc.docType === 'interface').sort(byId);
doc.directives = doc.exports.filter(doc => doc.docType === 'directive').sort(byId);
doc.pipes = doc.exports.filter(doc => doc.docType === 'pipe').sort(byId);
doc.types = doc.exports.filter(doc => doc.docType === 'type-alias' || doc.docType === 'const').sort(byId);
if (doc.exports.every(doc => !!doc.deprecated)) {
doc.deprecated = 'all exports of this entry point are deprecated.';
}
@ -71,3 +71,8 @@ module.exports = function processPackages() {
}
};
};
function byId(a, b) {
return a.id > b.id ? 1 : -1;
}

View File

@ -127,26 +127,26 @@ describe('processPackages processor', () => {
expect(newDocs[2].packageInfo.secondary).toEqual([newDocs[1], newDocs[2]]);
});
it('should partition the exports of packages into groups', () => {
it('should partition the exports of packages into groups, sorted by id', () => {
const docs = [
{
fileInfo: { filePath: 'some/x' },
docType: 'module',
id: 'x',
exports: [
{ docType: 'directive', id: 'directive-1' },
{ docType: 'function', id: 'function-1' },
{ docType: 'directive', id: 'directive-2' },
{ docType: 'decorator', id: 'decorator-1' },
{ docType: 'class', id: 'class-1' },
{ docType: 'directive', id: 'directive-1' },
{ docType: 'type-alias', id: 'type-alias-1' },
{ docType: 'class', id: 'class-2' },
{ docType: 'pipe', id: 'pipe-1' },
{ docType: 'const', id: 'const-1' },
{ docType: 'interface', id: 'interface-2' },
{ docType: 'const', id: 'const-2' },
{ docType: 'enum', id: 'enum-1' },
{ docType: 'interface', id: 'interface-1' },
{ docType: 'interface', id: 'interface-2' },
]
},
];
@ -172,9 +172,9 @@ describe('processPackages processor', () => {
{ docType: 'pipe', id: 'pipe-1' },
]);
expect(newDocs[0].types).toEqual([
{ docType: 'type-alias', id: 'type-alias-1' },
{ docType: 'const', id: 'const-1' },
{ docType: 'const', id: 'const-2' },
{ docType: 'type-alias', id: 'type-alias-1' },
]);
});