2017-04-16 15:48:22 -04:00
|
|
|
/* eslint no-console: "off" */
|
|
|
|
const watchr = require('watchr');
|
2017-05-03 08:55:00 -04:00
|
|
|
const {relative} = require('canonical-path');
|
2017-04-16 15:48:22 -04:00
|
|
|
const {generateDocs} = require('./index.js');
|
2017-05-03 08:55:00 -04:00
|
|
|
const { PROJECT_ROOT, CONTENTS_PATH, API_SOURCE_PATH } = require('../config');
|
2017-04-16 15:48:22 -04:00
|
|
|
|
|
|
|
function listener(changeType, fullPath) {
|
|
|
|
try {
|
2017-05-03 08:55:00 -04:00
|
|
|
const relativePath = relative(PROJECT_ROOT, fullPath);
|
2017-04-16 15:48:22 -04:00
|
|
|
console.log('The file', relativePath, `was ${changeType}d at`, new Date().toUTCString());
|
|
|
|
generateDocs(relativePath);
|
|
|
|
} catch(err) {
|
|
|
|
console.log('Error generating docs', err);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-04-16 16:31:21 -04:00
|
|
|
function next(error) {
|
|
|
|
if (error) {
|
|
|
|
console.log(error);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-04-20 15:42:42 -04:00
|
|
|
let p = Promise.resolve();
|
2017-04-16 15:48:22 -04:00
|
|
|
|
2017-04-20 15:42:42 -04:00
|
|
|
if (process.argv.indexOf('--watch-only') === -1) {
|
2017-09-23 10:25:11 -04:00
|
|
|
console.log('================================================================');
|
2017-04-20 15:42:42 -04:00
|
|
|
console.log('Running initial doc generation');
|
2017-09-23 10:25:11 -04:00
|
|
|
console.log('----------------------------------------------------------------');
|
|
|
|
console.log('Skip the full doc-gen by running: `yarn docs-watch --watch-only`');
|
|
|
|
console.log('================================================================');
|
2017-04-20 15:42:42 -04:00
|
|
|
const {Dgeni} = require('dgeni');
|
2017-10-30 17:29:25 -04:00
|
|
|
const dgeni = new Dgeni([require('../angular.io-package')]);
|
|
|
|
|
|
|
|
// Turn off all the potential failures for this doc-gen one-off run.
|
|
|
|
// This enables authors to run `docs-watch` while the docs are still in an unstable state.
|
|
|
|
const injector = dgeni.configureInjector();
|
|
|
|
injector.get('linkInlineTagDef').failOnBadLink = false;
|
|
|
|
injector.get('checkAnchorLinksProcessor').$enabled = false;
|
|
|
|
injector.get('renderExamples').ignoreBrokenExamples = true;
|
|
|
|
|
2017-04-20 15:42:42 -04:00
|
|
|
p = dgeni.generate();
|
|
|
|
}
|
|
|
|
|
|
|
|
p.then(() => {
|
|
|
|
console.log('===================================================================');
|
|
|
|
console.log('Started watching files in:');
|
2017-05-03 08:55:00 -04:00
|
|
|
console.log(' - ', CONTENTS_PATH);
|
|
|
|
console.log(' - ', API_SOURCE_PATH);
|
2017-04-20 15:42:42 -04:00
|
|
|
console.log('Doc gen will run when you change a file in either of these folders.');
|
|
|
|
console.log('===================================================================');
|
|
|
|
|
2017-05-03 08:55:00 -04:00
|
|
|
watchr.open(CONTENTS_PATH, listener, next);
|
|
|
|
watchr.open(API_SOURCE_PATH, listener, next);
|
2017-04-20 15:42:42 -04:00
|
|
|
|
2017-09-23 10:25:11 -04:00
|
|
|
});
|