a4f3f3f81d
Now, one can add an `@alias` tag to API docs, which tells dgeni that this API element (usually a `const`) is really just an alias for some API element defined elsewhere. Dgeni will then look up this API element and copy over the properties from the alias to the current doc. For example, we would like to privately export an Enum from `@angular/core` but then publicly export this from `@angular/common`: **packages/core/private_exports.ts** ```ts /** * Description of this document. */ export enum ɵSomeEnum { ... } ``` **packages/common/public_api.ts** ```ts import {ɵSomeEnum} from '@angular/core'; /** * @alias core/ɵSomeEnum */ export const SomeEnum = ɵSomeEnum; ``` In the generated docs there will be a page for `common/SomeEnum`, which will be rendered as an enum, rather than a const, showing the description extracted from the `core/ɵSomeEnum`. --- The implementation of this feature required some refactoring of the other processing: 1. Previously `ɵ` prefixed exports were not even considered. 2. Due to 1. some processors needed to have guards added to ignore such private exports (`addMetadataAliases` and `checkContentRules`). 3. The processing of package pages had to be reworked (and split) so that it picked up the aliased export docs after their alias proeprties had been copied. See FW-1207, FW-632, #29249 PR Close #29673
73 lines
2.2 KiB
JavaScript
73 lines
2.2 KiB
JavaScript
|
|
/**
|
|
* A processor that can run arbitrary checking rules against properties of documents
|
|
|
|
* The configuration for the processor is via the `docTypeRules`.
|
|
* This is a hash of docTypes to rulesets.
|
|
* Each rules set is a hash of properties to rule functions.
|
|
*
|
|
* The processor will run each rule function against each matching property of each matching doc.
|
|
*
|
|
* An example rule might look like:
|
|
*
|
|
* ```
|
|
* function noMarkdownHeadings(doc, prop, value) {
|
|
* const match = /^\s?#+\s+.*$/m.exec(value);
|
|
* if (match) {
|
|
* return `Headings not allowed in "${prop}" property. Found "${match[0]}"`;
|
|
* }
|
|
* }
|
|
* ```
|
|
*
|
|
*/
|
|
module.exports = function checkContentRules(log, createDocMessage) {
|
|
return {
|
|
/**
|
|
* {
|
|
* [docType]: {
|
|
* [property]: Array<(doc: Document, property: string, value: any) => string|undefined>
|
|
* }
|
|
* }
|
|
*/
|
|
docTypeRules: {},
|
|
failOnContentErrors: false,
|
|
$runAfter: ['tags-extracted'],
|
|
$runBefore: [],
|
|
$process(docs) {
|
|
const logMessage = this.failOnContentErrors ? log.error.bind(log) : log.warn.bind(log);
|
|
const errors = [];
|
|
docs.forEach(doc => {
|
|
// Ignore private exports (and members of a private export).
|
|
if (doc.id && doc.id.indexOf('ɵ') !== -1) return;
|
|
const docErrors = [];
|
|
const rules = this.docTypeRules[doc.docType] || {};
|
|
if (rules) {
|
|
Object.keys(rules).forEach(property => {
|
|
const ruleFns = rules[property];
|
|
ruleFns.forEach(ruleFn => {
|
|
const error = ruleFn(doc, property, doc[property]);
|
|
if (error) {
|
|
docErrors.push(error);
|
|
}
|
|
});
|
|
});
|
|
}
|
|
if (docErrors.length) {
|
|
errors.push({ doc, errors: docErrors });
|
|
}
|
|
});
|
|
|
|
if (errors.length) {
|
|
logMessage('Content contains errors');
|
|
errors.forEach(docError => {
|
|
const errors = docError.errors.join('\n ');
|
|
logMessage(createDocMessage(errors + '\n ', docError.doc));
|
|
});
|
|
if (this.failOnContentErrors) {
|
|
throw new Error('Stopping due to content errors.');
|
|
}
|
|
}
|
|
}
|
|
};
|
|
};
|