summaryrefslogtreecommitdiffstats
path: root/lib/utils/watch.js
diff options
context:
space:
mode:
Diffstat (limited to 'lib/utils/watch.js')
-rw-r--r--lib/utils/watch.js27
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;