@codedoc/core
Version:
Create beautiful modern documentation websites.
51 lines • 2.76 kB
JavaScript
;
var __makeTemplateObject = (this && this.__makeTemplateObject) || function (cooked, raw) {
if (Object.defineProperty) { Object.defineProperty(cooked, "raw", { value: raw }); } else { cooked.raw = raw; }
return cooked;
};
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.watch = void 0;
var node_watch_1 = __importDefault(require("node-watch"));
var chalk_1 = __importDefault(require("chalk"));
var path_1 = require("path");
var rxjs_1 = require("rxjs");
var operators_1 = require("rxjs/operators");
function watch(root, config, notifier) {
var watchbase = path_1.join(root, config.src.base, '/');
var filechange$ = new rxjs_1.Subject();
var request$ = new rxjs_1.Subject();
var build$ = new rxjs_1.BehaviorSubject(false);
node_watch_1.default(watchbase, {
recursive: true,
filter: function (f) { return (config.src.pick.test(f) && !config.src.drop.test(f) ||
config.src.toc === f.substr(watchbase.length)); },
}, function (event, filename) {
if (event === 'update')
filechange$.next(filename.substr(watchbase.length));
});
filechange$.pipe(operators_1.tap(function (filename) {
if (notifier)
console.log(chalk_1.default(templateObject_1 || (templateObject_1 = __makeTemplateObject(["{blue # Changes in {magenta ", "} queueing ...}"], ["{blue # Changes in {magenta ", "} queueing ...}"])), path_1.join(config.src.base, filename)));
request$.next('queued');
}), operators_1.buffer(filechange$.pipe(operators_1.debounceTime(500), operators_1.delayWhen(function () { return !build$.value ? rxjs_1.of(true) : build$.pipe(operators_1.filter(function (_) { return !_; })); }))), operators_1.filter(function (chanegs) { return chanegs.length > 0; })).subscribe(function (changedFiles) {
if (notifier) {
build$.next(true);
console.log(chalk_1.default(templateObject_2 || (templateObject_2 = __makeTemplateObject(["{gray # Rebuilding due to changes ...}"], ["{gray # Rebuilding due to changes ...}"]))));
}
changedFiles = changedFiles.filter(function (file, index) { return changedFiles.indexOf(file) === index; });
if (changedFiles.includes(config.src.toc)) {
request$.next('all');
}
else {
request$.next(changedFiles);
}
notifier === null || notifier === void 0 ? void 0 : notifier.subscribe(function () { return build$.next(false); });
});
return request$;
}
exports.watch = watch;
var templateObject_1, templateObject_2;
//# sourceMappingURL=watch.js.map