angular/aio/tools/transforms/authors-package/watchr.mjs
Matthieu Riegler 5fb5f087e3 docs(docs-infra): fix docs-watch script (#51316)
With this commit we can use `yarn docs-watch` again
Fixes #51308

PR Close #51316
2023-08-17 10:17:33 -07:00

34 lines
1.1 KiB
JavaScript

/* eslint no-console: "off" */
import watchr from 'watchr';
import canonicalPath from 'canonical-path';
import authorsPackage from './index.js';
import config from '../config.js';
function listener(changeType, fullPath) {
try {
const relativePath = canonicalPath.relative(config.PROJECT_ROOT, fullPath);
console.log('The file', relativePath, `was ${changeType}d at`, new Date().toUTCString());
authorsPackage.generateDocs(relativePath);
} catch (err) {
console.log('Error generating docs', err);
}
}
function next(error) {
if (error) {
console.log(error);
}
}
export function watch() {
console.log('============================================================================');
console.log('Started watching files in:');
console.log(' - ', config.CONTENTS_PATH);
console.log(' - ', config.API_SOURCE_PATH);
console.log('Doc gen will automatically run on any change to a file in either directory.');
console.log('============================================================================');
watchr.open(config.CONTENTS_PATH, listener, next);
watchr.open(config.API_SOURCE_PATH, listener, next);
}