diff options
author | Samy Pessé <samypesse@gmail.com> | 2015-01-24 11:23:53 +0100 |
---|---|---|
committer | Samy Pessé <samypesse@gmail.com> | 2015-01-24 11:23:53 +0100 |
commit | 2efd234824c8ec0a87bd20f807867b16cf169ecc (patch) | |
tree | d634e72c4a3a96c8f1d9fdb22b62f605c0a0fff0 /lib/utils/watch.js | |
parent | 8be4304b5c7bc0d4a3043ea5cfbedb0057b678ef (diff) | |
download | gitbook-2efd234824c8ec0a87bd20f807867b16cf169ecc.zip gitbook-2efd234824c8ec0a87bd20f807867b16cf169ecc.tar.gz gitbook-2efd234824c8ec0a87bd20f807867b16cf169ecc.tar.bz2 |
Complete serve command
Diffstat (limited to 'lib/utils/watch.js')
-rw-r--r-- | lib/utils/watch.js | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/lib/utils/watch.js b/lib/utils/watch.js new file mode 100644 index 0000000..715179d --- /dev/null +++ b/lib/utils/watch.js @@ -0,0 +1,27 @@ +var Q = require('q'); +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; +} + +module.exports = watch; |