1
0
Files
world/book/node_modules/honkit/lib/cli/watch.js
2025-05-12 05:38:44 +09:00

38 lines
1.2 KiB
JavaScript

"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const path_1 = __importDefault(require("path"));
const chokidar_1 = __importDefault(require("chokidar"));
const parsers_1 = __importDefault(require("../parsers"));
/**
Watch a folder and resolve promise once a file is modified
@param {string} dir
@param callback
@return {Promise}
*/
function watch(dir, callback) {
dir = path_1.default.resolve(dir);
const toWatch = ["book.json", "book.js", "_layouts/**"];
// Watch all parsable files
parsers_1.default.extensions.forEach((ext) => {
toWatch.push(`**/*${ext}`);
});
const watcher = chokidar_1.default.watch(toWatch, {
cwd: dir,
// prevent infinity loop
// https://github.com/honkit/honkit/issues/269
ignored: ["_book/**", "node_modules/**"],
ignoreInitial: true
});
watcher.on("all", (e, filepath) => {
callback(null, path_1.default.resolve(dir, filepath));
});
watcher.on("error", (err) => {
callback(err);
});
}
exports.default = watch;