fix
This commit is contained in:
37
book/node_modules/honkit/lib/cli/watch.js
generated
vendored
Normal file
37
book/node_modules/honkit/lib/cli/watch.js
generated
vendored
Normal file
@ -0,0 +1,37 @@
|
||||
"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;
|
Reference in New Issue
Block a user