mirror of
https://github.com/GitbookIO/gitbook.git
synced 2026-09-17 08:05:19 +00:00
39 lines
686 B
JavaScript
39 lines
686 B
JavaScript
var Q = require('q');
|
|
var _ = require('lodash');
|
|
var path = require('path');
|
|
var Gaze = require('gaze').Gaze;
|
|
|
|
var parsers = require('gitbook-parsers')
|
|
|
|
function watch(dir) {
|
|
var d = Q.defer();
|
|
dir = path.resolve(dir);
|
|
|
|
var toWatch = [
|
|
"book.json", "book.js"
|
|
];
|
|
|
|
_.each(parsers.extensions, function(ext) {
|
|
toWatch.push("**/*"+ext);
|
|
});
|
|
|
|
var gaze = new Gaze(toWatch, {
|
|
cwd: dir
|
|
});
|
|
|
|
gaze.once("all", function(e, filepath) {
|
|
gaze.close();
|
|
|
|
d.resolve(filepath);
|
|
});
|
|
gaze.once("error", function(err) {
|
|
gaze.close();
|
|
|
|
d.reject(err);
|
|
});
|
|
|
|
return d.promise;
|
|
}
|
|
|
|
module.exports = watch;
|