build(docs-infra): ensure that CLI options are included in search (#35801)
PR Close #35801
This commit is contained in:
parent
c1b5daf5a8
commit
603ab40e85
|
@ -19,7 +19,9 @@ module.exports = function processCliCommands(createDocMessage) {
|
|||
doc.names = collectNames(doc.name, doc.commandAliases);
|
||||
|
||||
// Recursively process the options
|
||||
processOptions(doc, doc.options);
|
||||
const optionKeywords = new Set();
|
||||
processOptions(doc, doc.options, optionKeywords);
|
||||
doc.optionKeywords = Array.from(optionKeywords).join(' ');
|
||||
|
||||
// Add to navigation doc
|
||||
navigationNode.children.push({url: doc.path, title: `ng ${doc.name}`});
|
||||
|
@ -29,7 +31,7 @@ module.exports = function processCliCommands(createDocMessage) {
|
|||
};
|
||||
};
|
||||
|
||||
function processOptions(container, options) {
|
||||
function processOptions(container, options, optionKeywords) {
|
||||
container.positionalOptions = [];
|
||||
container.namedOptions = [];
|
||||
|
||||
|
@ -41,6 +43,7 @@ function processOptions(container, options) {
|
|||
|
||||
option.types = option.types || [option.type];
|
||||
option.names = collectNames(option.name, option.aliases);
|
||||
option.names.forEach(name => optionKeywords.add(name));
|
||||
|
||||
// Now work out what kind of option it is: positional/named
|
||||
if (option.positional !== undefined) {
|
||||
|
@ -54,7 +57,8 @@ function processOptions(container, options) {
|
|||
option.subcommands = getValues(option.subcommands);
|
||||
option.subcommands.forEach(subcommand => {
|
||||
subcommand.names = collectNames(subcommand.name, subcommand.aliases);
|
||||
processOptions(subcommand, subcommand.options);
|
||||
subcommand.names.forEach(name => optionKeywords.add(name));
|
||||
processOptions(subcommand, subcommand.options, optionKeywords);
|
||||
});
|
||||
}
|
||||
});
|
||||
|
@ -63,7 +67,7 @@ function processOptions(container, options) {
|
|||
}
|
||||
|
||||
function collectNames(name, aliases) {
|
||||
return [name].concat(aliases);
|
||||
return [name].concat(aliases || []);
|
||||
}
|
||||
|
||||
function getValues(obj) {
|
||||
|
|
|
@ -95,6 +95,22 @@ describe('processCliCommands processor', () => {
|
|||
jasmine.objectContaining({name: 'c'}),
|
||||
]);
|
||||
});
|
||||
|
||||
it('should collect potential search terms from options for indexing', () => {
|
||||
const doc = {
|
||||
docType: 'cli-command',
|
||||
name: 'name',
|
||||
commandAliases: [],
|
||||
options: [
|
||||
{name: 'named1'},
|
||||
{name: 'positional1', positional: 0},
|
||||
{name: 'named2', hidden: true},
|
||||
{name: 'positional2', hidden: true, positional: 1},
|
||||
],
|
||||
};
|
||||
processor.$process([doc, navigationStub]);
|
||||
expect(doc.optionKeywords).toEqual('named1 positional1');
|
||||
});
|
||||
});
|
||||
|
||||
describe('subcommands', () => {
|
||||
|
@ -285,4 +301,36 @@ describe('processCliCommands processor', () => {
|
|||
'Missing `cli` url - CLI Commands must include a first child node with url set at `cli`',
|
||||
navigation));
|
||||
});
|
||||
|
||||
it('should collect potential search terms from options for indexing', () => {
|
||||
const doc = {
|
||||
docType: 'cli-command',
|
||||
name: 'name',
|
||||
commandAliases: [],
|
||||
options: [{
|
||||
name: 'supercommand',
|
||||
subcommands: {
|
||||
subcommand1: {
|
||||
name: 'subcommand1',
|
||||
options: [
|
||||
{name: 'subcommand1-option1'},
|
||||
{name: 'subcommand1-option2'},
|
||||
],
|
||||
},
|
||||
subcommand2: {
|
||||
name: 'subcommand2',
|
||||
options: [
|
||||
{name: 'subcommand2-option1'},
|
||||
{name: 'subcommand2-option2'},
|
||||
],
|
||||
}
|
||||
},
|
||||
}],
|
||||
};
|
||||
processor.$process([doc, navigationStub]);
|
||||
expect(doc.optionKeywords)
|
||||
.toEqual(
|
||||
'supercommand subcommand1 subcommand1-option1 subcommand1-option2 subcommand2 subcommand2-option1 subcommand2-option2');
|
||||
});
|
||||
|
||||
});
|
||||
|
|
Loading…
Reference in New Issue