
This task is suitable for day to day docs authoring. This task cuts corners, which makes it much faster than a full `yarn docs` run but it does not produce completely valid output. In general this isgood enough for authors to see their changes as they make them. The task is triggered by a call to ``` yarn docs-watch ``` This sets up watchers on the `aio/contents` and `packages` folders. Any changes to files below these folders new doc generation run to start. The input to the generation is confined to a collection of files related to the changed file. For example: * a change to a file in `aio/content/marketing` will generate all the marketing files. * a change to a file in `aio/content/tutorial` or `aio/examples/toh-*` will generate all the tutorial files (and their embedded examples). * a change to a file in `aio/guide` or `aio/examples` (but not a `toh-` example) will generate the appropriate guide and its embedded examples * a change to a file in `packages` or `packages/examples` will generate the appropriate API doc and its embedded examples. Be aware that the mapping between docs and its examples are based on doc file and example folder structure being equivalent. Sometimes a doc will reference an example in a different folder, in which case the generated doc will be inaccurate. Mostly this is not a big problem.
51 lines
1.8 KiB
JavaScript
51 lines
1.8 KiB
JavaScript
/**
|
|
* @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
|
|
*/
|
|
/* eslint no-console: "off" */
|
|
|
|
function createPackage(changedFile) {
|
|
const marketingMatch = /^aio\/content\/marketing\/(.*)/.exec(changedFile);
|
|
if (marketingMatch) {
|
|
console.log('Building marketing docs');
|
|
return require('./marketing-package').createPackage();
|
|
}
|
|
|
|
const tutorialMatch = /^aio\/content\/tutorial\/|^aio\/content\/examples\/toh-\d/.exec(changedFile);
|
|
if (tutorialMatch) {
|
|
console.log('Building tutorial docs');
|
|
return require('./tutorial-package').createPackage();
|
|
}
|
|
|
|
const guideMatch = /^aio\/content\/guide\/([^\.]+)\.md/.exec(changedFile);
|
|
const exampleMatch = /^aio\/content\/examples\/(?:cb-)?([^\/]+)\//.exec(changedFile);
|
|
if (guideMatch || exampleMatch) {
|
|
const exampleName = guideMatch && guideMatch[1] || exampleMatch[1];
|
|
console.log(`Building guide doc: ${exampleName}.md`);
|
|
return require('./guide-package').createPackage(exampleName);
|
|
}
|
|
|
|
const apiExamplesMatch = /^packages\/examples\/([^\/]+)\//.exec(changedFile);
|
|
const apiMatch = /^packages\/([^\/]+)\//.exec(changedFile);
|
|
if (apiExamplesMatch || apiMatch) {
|
|
const packageName = apiExamplesMatch && apiExamplesMatch[1] || apiMatch[1];
|
|
console.log('Building API docs for', packageName);
|
|
return require('./api-package').createPackage(packageName);
|
|
}
|
|
}
|
|
|
|
module.exports = {
|
|
generateDocs: function(changedFile) {
|
|
const {Dgeni} = require('dgeni');
|
|
var dgeni = new Dgeni([createPackage(changedFile)]);
|
|
const start = Date.now();
|
|
return dgeni.generate()
|
|
.then(
|
|
() => console.log('Generated docs in ' + (Date.now() - start)/1000 + ' secs'),
|
|
err => console.log('Error generating docs', err));
|
|
}
|
|
};
|