@ng-doc/builder
Version:
<!-- PROJECT LOGO --> <br /> <div align="center"> <a href="https://github.com/ng-doc/ng-doc"> <img src="https://ng-doc.com/assets/images/ng-doc.svg?raw=true" alt="Logo" height="150px"> </a>
59 lines • 2.21 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.watch = watch;
const tslib_1 = require("tslib");
const builder_1 = require("@ng-doc/builder");
const watcher = tslib_1.__importStar(require("@parcel/watcher"));
const path_1 = require("path");
const rxjs_1 = require("rxjs");
const operators_1 = require("rxjs/operators");
let WATCHER = null;
/**
*
* @param path
* @param dir
*/
function watch(path, dir) {
// One-shot builds don't need to react to file changes, so the watcher
// is not started at all to let the process exit as soon as the build is done
if (!builder_1.GLOBALS.watch) {
return rxjs_1.NEVER;
}
path = (0, path_1.resolve)(path);
if (!WATCHER) {
let unsubscribe = () => { };
let disposed = false;
WATCHER = new rxjs_1.Observable((subscriber) => {
watcher
.subscribe(builder_1.GLOBALS.workspaceRoot, (err, events) => {
if (err) {
console.error(err);
subscriber.error(err);
return;
}
subscriber.next(events);
}, { ignore: ['node_modules'] })
.then((unsub) => {
// The teardown may run before this promise resolves (e.g. a one-shot build
// that finishes while the watcher is still crawling the workspace);
// in that case the subscription must be closed here, otherwise it keeps
// the process alive forever (see #333)
if (disposed) {
unsub.unsubscribe();
}
else {
unsubscribe = unsub.unsubscribe;
}
});
return () => {
disposed = true;
unsubscribe();
WATCHER = null;
};
}).pipe((0, operators_1.share)());
}
return WATCHER.pipe((0, operators_1.map)((events) => events.filter((event) => {
return dir ? event.path.startsWith(path) : event.path.endsWith(path);
})), (0, operators_1.filter)((events) => events.length > 0));
}
//# sourceMappingURL=watch.js.map