build(aio): add metadata aliases for directives, components and pipes (#19317)
This change will enable people to link to the API docs via their selectors or names, as used in a template. Since the selectors can be quite complex we are not able to get 100% accuracy. Closes #16787
This commit is contained in:

committed by
Victor Berchet

parent
97e02c2fa0
commit
adb0b761f1
40
aio/tools/transforms/angular-api-package/processors/addMetadataAliases.js
vendored
Normal file
40
aio/tools/transforms/angular-api-package/processors/addMetadataAliases.js
vendored
Normal file
@ -0,0 +1,40 @@
|
||||
/**
|
||||
* @dgProcessor addMetadataAliases
|
||||
*
|
||||
* Directives and components can also be referenced by their selectors,
|
||||
* and Pipes can be referenced by their name.
|
||||
* So let's add each selector as an alias to this doc.
|
||||
*/
|
||||
module.exports = function addMetadataAliasesProcessor() {
|
||||
return {
|
||||
$runAfter: ['extractDecoratedClassesProcessor'],
|
||||
$runBefore: ['computing-ids'],
|
||||
$process: function(docs) {
|
||||
docs.forEach(doc => {
|
||||
switch(doc.docType) {
|
||||
case 'directive':
|
||||
case 'component':
|
||||
doc.aliases = doc.aliases.concat(extractSelectors(doc[doc.docType + 'Options'].selector));
|
||||
break;
|
||||
case 'pipe':
|
||||
if (doc.pipeOptions.name) {
|
||||
doc.aliases = doc.aliases.concat(stripQuotes(doc.pipeOptions.name));
|
||||
}
|
||||
break;
|
||||
}
|
||||
});
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
function extractSelectors(selectors) {
|
||||
if (selectors) {
|
||||
return stripQuotes(selectors).split(',').map(selector => selector.replace(/^\W*([\w-]+)\W*$/, '$1'));
|
||||
} else {
|
||||
return [];
|
||||
}
|
||||
}
|
||||
|
||||
function stripQuotes(value) {
|
||||
return (typeof(value) === 'string') ? value.trim().replace(/^(['"])(.*)\1$/, '$2') : value;
|
||||
}
|
Reference in New Issue
Block a user