build(aio): fail the doc-gen if there is an invalid {@link ...} tag

This fail behaviour is only turned on for `yarn docs`;
in `yarn docs-watch` you only receive a warning.
This is because you can get false errors when watching
since we don't parse all the docs in that case.
This commit is contained in:
Peter Bacon Darwin 2017-05-10 10:22:51 +01:00 committed by Pete Bacon Darwin
parent dc7d24267d
commit f5335d17ec
2 changed files with 15 additions and 5 deletions

View File

@ -25,7 +25,11 @@ module.exports = new Package('angular.io', [gitPackage, apiPackage, contentPacka
renderDocsProcessor.extraData.versionInfo = versionInfo; renderDocsProcessor.extraData.versionInfo = versionInfo;
}) })
.config(function(checkAnchorLinksProcessor) { .config(function(checkAnchorLinksProcessor, linkInlineTagDef) {
// Fail the processing if there is an invalid link
linkInlineTagDef.failOnBadLink = true;
checkAnchorLinksProcessor.$enabled = true; checkAnchorLinksProcessor.$enabled = true;
// since we encode the HTML to JSON we need to ensure that this processor runs before that encoding happens. // since we encode the HTML to JSON we need to ensure that this processor runs before that encoding happens.
checkAnchorLinksProcessor.$runBefore = ['convertToJsonProcessor']; checkAnchorLinksProcessor.$runBefore = ['convertToJsonProcessor'];

View File

@ -9,23 +9,29 @@ var INLINE_LINK = /(\S+)(?:\s+([\s\S]+))?/;
* @param {Function} docs error message * @param {Function} docs error message
* @return {String} The html link information * @return {String} The html link information
* *
* @property {boolean} relativeLinks Whether we expect the links to be relative to the originating doc * @property {boolean} failOnBadLink Whether to throw an error (aborting the processing) if a link is invalid.
*/ */
module.exports = function linkInlineTagDef(getLinkInfo, createDocMessage, log) { module.exports = function linkInlineTagDef(getLinkInfo, createDocMessage, log) {
return { return {
name: 'link', name: 'link',
aliases: ['linkDocs'], aliases: ['linkDocs'],
failOnBadLink: false,
description: description:
'Process inline link tags (of the form {@link some/uri Some Title}), replacing them with HTML anchors', 'Process inline link tags (of the form {@link some/uri Some Title}), replacing them with HTML anchors',
handler: function(doc, tagName, tagDescription) { handler(doc, tagName, tagDescription) {
// Parse out the uri and title // Parse out the uri and title
return tagDescription.replace(INLINE_LINK, function(match, uri, title) { return tagDescription.replace(INLINE_LINK, (match, uri, title) => {
var linkInfo = getLinkInfo(uri, title, doc); var linkInfo = getLinkInfo(uri, title, doc);
if (!linkInfo.valid) { if (!linkInfo.valid) {
log.warn(createDocMessage(linkInfo.error, doc)); const message = createDocMessage(linkInfo.error, doc);
if (this.failOnBadLink) {
throw new Error(message);
} else {
log.warn(message);
}
} }
return '<a href=\'' + linkInfo.url + '\'>' + linkInfo.title + '</a>'; return '<a href=\'' + linkInfo.url + '\'>' + linkInfo.title + '</a>';