diff options
author | Samy Pessé <samypesse@gmail.com> | 2014-04-28 20:29:36 +0200 |
---|---|---|
committer | Samy Pessé <samypesse@gmail.com> | 2014-04-28 20:29:36 +0200 |
commit | 23056fc85da957d6f63808e59e13d8bd646a215d (patch) | |
tree | 022bdc72e87ef34677951b6743df291522661899 /bin/utils.js | |
parent | 5f1bfc02805e074ab47bc8966410cf8042363c48 (diff) | |
download | gitbook-23056fc85da957d6f63808e59e13d8bd646a215d.zip gitbook-23056fc85da957d6f63808e59e13d8bd646a215d.tar.gz gitbook-23056fc85da957d6f63808e59e13d8bd646a215d.tar.bz2 |
Use a global configuration file for a book (default to book.json)
Diffstat (limited to 'bin/utils.js')
-rw-r--r-- | bin/utils.js | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/bin/utils.js b/bin/utils.js new file mode 100644 index 0000000..b43936f --- /dev/null +++ b/bin/utils.js @@ -0,0 +1,42 @@ +var Q = require('q'); +var _ = require('lodash'); + +var http = require('http'); +var send = require('send'); + +var path = require('path'); +var Gaze = require('gaze').Gaze; + +function watch(dir) { + var d = Q.defer(); + dir = path.resolve(dir); + + var gaze = new Gaze("**/*.md", { + 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; +} + +function logError(err) { + console.log(err.stack || err.message || err); + return Q.reject(err); +}; + + +// Exports +module.exports = { + watch: watch, + logError: logError +}; |