UNPKG

@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>

41 lines 1.43 kB
"use strict"; 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) { path = (0, path_1.resolve)(path); if (!WATCHER) { let unsubscribe = () => { }; 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) => (unsubscribe = unsub.unsubscribe)); return () => { 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