-
Notifications
You must be signed in to change notification settings - Fork 3k
/
index.js
143 lines (121 loc) · 5.44 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
/**
* @license
* Copyright Google Inc. All Rights Reserved.
*
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://angular.io/license
*/
const path = require('path');
const Package = require('dgeni').Package;
const jsdocPackage = require('dgeni-packages/jsdoc');
const nunjucksPackage = require('dgeni-packages/nunjucks');
const linksPackage = require('../links-package');
const targetPackage = require('../target-package');
const remarkPackage = require('../remark-package');
const postProcessPackage = require('dgeni-packages/post-process-html');
const { PROJECT_ROOT, CONTENTS_PATH, OUTPUT_PATH, DOCS_OUTPUT_PATH, TEMPLATES_PATH, AIO_PATH, requireFolder } = require('../config');
// prettier-ignore
module.exports = new Package('angular-base', [
jsdocPackage,
nunjucksPackage,
linksPackage,
targetPackage,
remarkPackage,
postProcessPackage,
])
// Register the processors
.processor(require('./processors/generateKeywords'))
.processor(require('./processors/createSitemap'))
.processor(require('./processors/checkUnbalancedBackTicks'))
.processor(require('./processors/convertToJson'))
.processor(require('./processors/fixInternalDocumentLinks'))
.processor(require('./processors/copyContentAssets'))
.processor(require('./processors/renderLinkInfo'))
.processor(require('./processors/checkOperator'))
// overrides base packageInfo and returns the one for the 'angular/angular' repo.
.factory('packageInfo', function () {
return require(path.resolve(PROJECT_ROOT, 'package.json'));
})
.factory(require('./readers/json'))
.factory(require('./services/copyFolder'))
.factory(require('./services/filterPipes'))
.factory(require('./services/filterAmbiguousDirectiveAliases'))
.factory(require('./services/filterFromInImports'))
.factory(require('./services/filterNeverAsGeneric'))
.factory(require('./services/getImageDimensions'))
.factory(require('./post-processors/add-image-dimensions'))
.factory(require('./post-processors/auto-link-code'))
.config(function (checkAnchorLinksProcessor) {
// This is disabled here to prevent false negatives for the `docs-watch` task.
// It is re-enabled in the main `angular.io-package`
checkAnchorLinksProcessor.$enabled = false;
})
// Where do we get the source files?
.config(function (readFilesProcessor, generateKeywordsProcessor, jsonFileReader) {
readFilesProcessor.fileReaders.push(jsonFileReader);
readFilesProcessor.basePath = PROJECT_ROOT;
readFilesProcessor.sourceFiles = [];
generateKeywordsProcessor.ignoreWordsFile = path.resolve(__dirname, 'ignore.words');
generateKeywordsProcessor.propertiesToIgnore = ['renderedContent'];
})
// Where do we write the output files?
.config(function (writeFilesProcessor) {
writeFilesProcessor.outputFolder = DOCS_OUTPUT_PATH;
})
// Target environments
.config(function (targetEnvironments) {
const ALLOWED_LANGUAGES = ['ts', 'js', 'dart'];
const TARGET_LANGUAGE = 'ts';
ALLOWED_LANGUAGES.forEach((target) => targetEnvironments.addAllowed(target));
targetEnvironments.activate(TARGET_LANGUAGE);
})
// Configure nunjucks rendering of docs via templates
.config(function (renderDocsProcessor, templateFinder, templateEngine, getInjectables) {
// Where to find the templates for the doc rendering
templateFinder.templateFolders = [TEMPLATES_PATH];
// Standard patterns for matching docs to templates
templateFinder.templatePatterns = [
'${ doc.template }',
'${ doc.id }.${ doc.docType }.template.html',
'${ doc.id }.template.html',
'${ doc.docType }.template.html',
'${ doc.id }.${ doc.docType }.template.js',
'${ doc.id }.template.js',
'${ doc.docType }.template.js',
'${ doc.id }.${ doc.docType }.template.json',
'${ doc.id }.template.json',
'${ doc.docType }.template.json',
'common.template.html',
];
// Nunjucks and Angular conflict in their template bindings so change Nunjucks
templateEngine.config.tags = { variableStart: '{$', variableEnd: '$}' };
templateEngine.filters = templateEngine.filters.concat(getInjectables(requireFolder(__dirname, './rendering')));
// helpers are made available to the nunjucks templates
renderDocsProcessor.helpers.relativePath = function (from, to) {
return path.relative(from, to);
};
})
.config(function (copyContentAssetsProcessor) {
copyContentAssetsProcessor.assetMappings.push({ from: path.resolve(CONTENTS_PATH, 'images'), to: path.resolve(OUTPUT_PATH, 'images') });
})
// We are not going to be relaxed about ambiguous links
.config(function (getLinkInfo) {
getLinkInfo.useFirstAmbiguousLink = false;
})
.config(function (generateKeywordsProcessor) {
generateKeywordsProcessor.outputFolder = 'app';
})
.config(function (postProcessHtml, addImageDimensions, autoLinkCode, filterPipes, filterAmbiguousDirectiveAliases, filterFromInImports, filterNeverAsGeneric) {
addImageDimensions.basePath = path.resolve(AIO_PATH, 'src');
autoLinkCode.customFilters = [filterPipes, filterAmbiguousDirectiveAliases];
autoLinkCode.wordFilters = [filterFromInImports, filterNeverAsGeneric];
postProcessHtml.plugins = [
require('./post-processors/autolink-headings'),
addImageDimensions,
require('./post-processors/h1-checker'),
autoLinkCode,
];
})
.config(function (convertToJsonProcessor) {
convertToJsonProcessor.docTypes = [];
});