style(docs-infra): format files (#35801)

PR Close #35801
This commit is contained in:
Pete Bacon Darwin 2020-03-02 17:47:06 +00:00 committed by atscott
parent c296bfcaf9
commit c1b5daf5a8
2 changed files with 94 additions and 104 deletions

View File

@ -4,10 +4,14 @@ module.exports = function processCliCommands(createDocMessage) {
$runBefore: ['rendering-docs'], $runBefore: ['rendering-docs'],
$process(docs) { $process(docs) {
const navigationDoc = docs.find(doc => doc.docType === 'navigation-json'); const navigationDoc = docs.find(doc => doc.docType === 'navigation-json');
const navigationNode = navigationDoc && navigationDoc.data['SideNav'].find(node => node.children && node.children.length && node.children[0].url === 'cli'); const navigationNode = navigationDoc &&
navigationDoc.data['SideNav'].find(
node => node.children && node.children.length && node.children[0].url === 'cli');
if (!navigationNode) { if (!navigationNode) {
throw new Error(createDocMessage('Missing `cli` url - CLI Commands must include a first child node with url set at `cli`', navigationDoc)); throw new Error(createDocMessage(
'Missing `cli` url - CLI Commands must include a first child node with url set at `cli`',
navigationDoc));
} }
docs.forEach(doc => { docs.forEach(doc => {
@ -18,7 +22,7 @@ module.exports = function processCliCommands(createDocMessage) {
processOptions(doc, doc.options); processOptions(doc, doc.options);
// Add to navigation doc // Add to navigation doc
navigationNode.children.push({ url: doc.path, title: `ng ${doc.name}` }); navigationNode.children.push({url: doc.path, title: `ng ${doc.name}`});
} }
}); });
} }
@ -31,7 +35,9 @@ function processOptions(container, options) {
options.forEach(option => { options.forEach(option => {
// Ignore any hidden options // Ignore any hidden options
if (option.hidden) { return; } if (option.hidden) {
return;
}
option.types = option.types || [option.type]; option.types = option.types || [option.type];
option.names = collectNames(option.name, option.aliases); option.names = collectNames(option.name, option.aliases);

View File

@ -7,11 +7,7 @@ describe('processCliCommands processor', () => {
const navigationStub = { const navigationStub = {
docType: 'navigation-json', docType: 'navigation-json',
data: { data: {SideNav: [{children: [{'url': 'cli'}]}]}
SideNav: [{
children: [{'url': 'cli'}]
}]
}
}; };
beforeEach(() => { beforeEach(() => {
@ -21,17 +17,13 @@ describe('processCliCommands processor', () => {
createDocMessage = injector.get('createDocMessage'); createDocMessage = injector.get('createDocMessage');
}); });
it('should be available on the injector', () => { it('should be available on the injector', () => { expect(processor.$process).toBeDefined(); });
expect(processor.$process).toBeDefined();
});
it('should run after the correct processor', () => { it('should run after the correct processor',
expect(processor.$runAfter).toEqual(['extra-docs-added']); () => { expect(processor.$runAfter).toEqual(['extra-docs-added']); });
});
it('should run before the correct processor', () => { it('should run before the correct processor',
expect(processor.$runBefore).toEqual(['rendering-docs']); () => { expect(processor.$runBefore).toEqual(['rendering-docs']); });
});
it('should collect the names (name + aliases)', () => { it('should collect the names (name + aliases)', () => {
const doc = { const doc = {
@ -51,16 +43,16 @@ describe('processCliCommands processor', () => {
name: 'name', name: 'name',
commandAliases: [], commandAliases: [],
options: [ options: [
{ name: 'option1' }, {name: 'option1'},
{ name: 'option2', hidden: true }, {name: 'option2', hidden: true},
{ name: 'option3' }, {name: 'option3'},
{ name: 'option4', hidden: true }, {name: 'option4', hidden: true},
], ],
}; };
processor.$process([doc, navigationStub]); processor.$process([doc, navigationStub]);
expect(doc.namedOptions).toEqual([ expect(doc.namedOptions).toEqual([
jasmine.objectContaining({ name: 'option1' }), jasmine.objectContaining({name: 'option1'}),
jasmine.objectContaining({ name: 'option3' }), jasmine.objectContaining({name: 'option3'}),
]); ]);
}); });
@ -70,18 +62,18 @@ describe('processCliCommands processor', () => {
name: 'name', name: 'name',
commandAliases: [], commandAliases: [],
options: [ options: [
{ name: 'named1' }, {name: 'named1'},
{ name: 'positional1', positional: 0}, {name: 'positional1', positional: 0},
{ name: 'named2', hidden: true }, {name: 'named2', hidden: true},
{ name: 'positional2', hidden: true, positional: 1}, {name: 'positional2', hidden: true, positional: 1},
], ],
}; };
processor.$process([doc, navigationStub]); processor.$process([doc, navigationStub]);
expect(doc.positionalOptions).toEqual([ expect(doc.positionalOptions).toEqual([
jasmine.objectContaining({ name: 'positional1', positional: 0}), jasmine.objectContaining({name: 'positional1', positional: 0}),
]); ]);
expect(doc.namedOptions).toEqual([ expect(doc.namedOptions).toEqual([
jasmine.objectContaining({ name: 'named1' }), jasmine.objectContaining({name: 'named1'}),
]); ]);
}); });
@ -91,16 +83,16 @@ describe('processCliCommands processor', () => {
name: 'name', name: 'name',
commandAliases: [], commandAliases: [],
options: [ options: [
{ name: 'c' }, {name: 'c'},
{ name: 'a' }, {name: 'a'},
{ name: 'b' }, {name: 'b'},
], ],
}; };
processor.$process([doc, navigationStub]); processor.$process([doc, navigationStub]);
expect(doc.namedOptions).toEqual([ expect(doc.namedOptions).toEqual([
jasmine.objectContaining({ name: 'a' }), jasmine.objectContaining({name: 'a'}),
jasmine.objectContaining({ name: 'b' }), jasmine.objectContaining({name: 'b'}),
jasmine.objectContaining({ name: 'c' }), jasmine.objectContaining({name: 'c'}),
]); ]);
}); });
}); });
@ -117,15 +109,15 @@ describe('processCliCommands processor', () => {
subcommand1: { subcommand1: {
name: 'subcommand1', name: 'subcommand1',
options: [ options: [
{ name: 'subcommand1-option1' }, {name: 'subcommand1-option1'},
{ name: 'subcommand1-option2' }, {name: 'subcommand1-option2'},
], ],
}, },
subcommand2: { subcommand2: {
name: 'subcommand2', name: 'subcommand2',
options: [ options: [
{ name: 'subcommand2-option1' }, {name: 'subcommand2-option1'},
{ name: 'subcommand2-option2' }, {name: 'subcommand2-option2'},
], ],
} }
}, },
@ -133,8 +125,8 @@ describe('processCliCommands processor', () => {
}; };
processor.$process([doc, navigationStub]); processor.$process([doc, navigationStub]);
expect(doc.options[0].subcommands).toEqual([ expect(doc.options[0].subcommands).toEqual([
jasmine.objectContaining({ name: 'subcommand1' }), jasmine.objectContaining({name: 'subcommand1'}),
jasmine.objectContaining({ name: 'subcommand2' }), jasmine.objectContaining({name: 'subcommand2'}),
]); ]);
}); });
@ -149,15 +141,15 @@ describe('processCliCommands processor', () => {
subcommand1: { subcommand1: {
name: 'subcommand1', name: 'subcommand1',
options: [ options: [
{ name: 'subcommand1-option1' }, {name: 'subcommand1-option1'},
{ name: 'subcommand1-option2', hidden: true }, {name: 'subcommand1-option2', hidden: true},
], ],
}, },
subcommand2: { subcommand2: {
name: 'subcommand2', name: 'subcommand2',
options: [ options: [
{ name: 'subcommand2-option1', hidden: true }, {name: 'subcommand2-option1', hidden: true},
{ name: 'subcommand2-option2' }, {name: 'subcommand2-option2'},
], ],
} }
}, },
@ -165,10 +157,10 @@ describe('processCliCommands processor', () => {
}; };
processor.$process([doc, navigationStub]); processor.$process([doc, navigationStub]);
expect(doc.options[0].subcommands[0].namedOptions).toEqual([ expect(doc.options[0].subcommands[0].namedOptions).toEqual([
jasmine.objectContaining({ name: 'subcommand1-option1' }), jasmine.objectContaining({name: 'subcommand1-option1'}),
]); ]);
expect(doc.options[0].subcommands[1].namedOptions).toEqual([ expect(doc.options[0].subcommands[1].namedOptions).toEqual([
jasmine.objectContaining({ name: 'subcommand2-option2' }), jasmine.objectContaining({name: 'subcommand2-option2'}),
]); ]);
}); });
@ -183,15 +175,15 @@ describe('processCliCommands processor', () => {
subcommand1: { subcommand1: {
name: 'subcommand1', name: 'subcommand1',
options: [ options: [
{ name: 'subcommand1-option1' }, {name: 'subcommand1-option1'},
{ name: 'subcommand1-option2', positional: 0 }, {name: 'subcommand1-option2', positional: 0},
], ],
}, },
subcommand2: { subcommand2: {
name: 'subcommand2', name: 'subcommand2',
options: [ options: [
{ name: 'subcommand2-option1', hidden: true }, {name: 'subcommand2-option1', hidden: true},
{ name: 'subcommand2-option2', hidden: true, positional: 1 }, {name: 'subcommand2-option2', hidden: true, positional: 1},
], ],
} }
}, },
@ -199,10 +191,10 @@ describe('processCliCommands processor', () => {
}; };
processor.$process([doc, navigationStub]); processor.$process([doc, navigationStub]);
expect(doc.options[0].subcommands[0].positionalOptions).toEqual([ expect(doc.options[0].subcommands[0].positionalOptions).toEqual([
jasmine.objectContaining({ name: 'subcommand1-option2', positional: 0}), jasmine.objectContaining({name: 'subcommand1-option2', positional: 0}),
]); ]);
expect(doc.options[0].subcommands[0].namedOptions).toEqual([ expect(doc.options[0].subcommands[0].namedOptions).toEqual([
jasmine.objectContaining({ name: 'subcommand1-option1' }), jasmine.objectContaining({name: 'subcommand1-option1'}),
]); ]);
expect(doc.options[0].subcommands[1].positionalOptions).toEqual([]); expect(doc.options[0].subcommands[1].positionalOptions).toEqual([]);
@ -220,9 +212,9 @@ describe('processCliCommands processor', () => {
subcommand1: { subcommand1: {
name: 'subcommand1', name: 'subcommand1',
options: [ options: [
{ name: 'c' }, {name: 'c'},
{ name: 'a' }, {name: 'a'},
{ name: 'b' }, {name: 'b'},
] ]
} }
} }
@ -230,14 +222,15 @@ describe('processCliCommands processor', () => {
}; };
processor.$process([doc, navigationStub]); processor.$process([doc, navigationStub]);
expect(doc.options[0].subcommands[0].namedOptions).toEqual([ expect(doc.options[0].subcommands[0].namedOptions).toEqual([
jasmine.objectContaining({ name: 'a' }), jasmine.objectContaining({name: 'a'}),
jasmine.objectContaining({ name: 'b' }), jasmine.objectContaining({name: 'b'}),
jasmine.objectContaining({ name: 'c' }), jasmine.objectContaining({name: 'c'}),
]); ]);
}); });
}); });
it('should add the command to the CLI node in the navigation doc if there is a first child node with a `cli` url', () => { it('should add the command to the CLI node in the navigation doc if there is a first child node with a `cli` url',
() => {
const command = { const command = {
docType: 'cli-command', docType: 'cli-command',
name: 'command1', name: 'command1',
@ -249,26 +242,20 @@ describe('processCliCommands processor', () => {
docType: 'navigation-json', docType: 'navigation-json',
data: { data: {
SideNav: [ SideNav: [
{ url: 'some/page', title: 'Some Page' }, {url: 'some/page', title: 'Some Page'}, {
{
title: 'CLI Commands', title: 'CLI Commands',
tooltip: 'Angular CLI command reference', tooltip: 'Angular CLI command reference',
children: [ children: [{'title': 'Overview', 'url': 'cli'}]
{
'title': 'Overview',
'url': 'cli'
}
]
}, },
{ url: 'other/page', title: 'Other Page' } {url: 'other/page', title: 'Other Page'}
] ]
} }
}; };
processor.$process([command, navigation]); processor.$process([command, navigation]);
expect(navigation.data.SideNav[1].title).toEqual('CLI Commands'); expect(navigation.data.SideNav[1].title).toEqual('CLI Commands');
expect(navigation.data.SideNav[1].children).toEqual([ expect(navigation.data.SideNav[1].children).toEqual([
{ url: 'cli', title: 'Overview' }, {url: 'cli', title: 'Overview'},
{ url: 'cli/command1', title: 'ng command1' }, {url: 'cli/command1', title: 'ng command1'},
]); ]);
}); });
@ -284,21 +271,18 @@ describe('processCliCommands processor', () => {
docType: 'navigation-json', docType: 'navigation-json',
data: { data: {
SideNav: [ SideNav: [
{ url: 'some/page', title: 'Some Page' }, {url: 'some/page', title: 'Some Page'}, {
{
title: 'CLI Commands', title: 'CLI Commands',
tooltip: 'Angular CLI command reference', tooltip: 'Angular CLI command reference',
children: [ children: [{'title': 'Overview', 'url': 'client'}]
{
'title': 'Overview',
'url': 'client'
}
]
}, },
{ url: 'other/page', title: 'Other Page' } {url: 'other/page', title: 'Other Page'}
] ]
} }
}; };
expect(() => processor.$process([command, navigation])).toThrowError(createDocMessage('Missing `cli` url - CLI Commands must include a first child node with url set at `cli`', navigation)); expect(() => processor.$process([command, navigation]))
.toThrowError(createDocMessage(
'Missing `cli` url - CLI Commands must include a first child node with url set at `cli`',
navigation));
}); });
}); });