-
Notifications
You must be signed in to change notification settings - Fork 44
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add JS wrapper around C++ binding (#14)
* Add JS wrapper around C++ binding * Resolve ignore paths relative to watched directory
- Loading branch information
1 parent
cb1bf1a
commit c016a4e
Showing
3 changed files
with
78 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,36 @@ | ||
module.exports = require('bindings')('fschanges.node'); | ||
const binding = require('bindings')('fschanges.node'); | ||
const path = require('path'); | ||
|
||
function normalizeOptions(dir, opts = {}) { | ||
if (Array.isArray(opts.ignore)) { | ||
opts = Object.assign({}, opts, { | ||
ignore: opts.ignore.map(ignore => path.resolve(dir, ignore)) | ||
}); | ||
} | ||
|
||
return opts; | ||
} | ||
|
||
exports.writeSnapshot = (dir, snapshot, opts) => { | ||
return binding.writeSnapshot(path.resolve(dir), path.resolve(snapshot), normalizeOptions(dir, opts)); | ||
}; | ||
|
||
exports.getEventsSince = (dir, snapshot, opts) => { | ||
return binding.getEventsSince(path.resolve(dir), path.resolve(snapshot), normalizeOptions(dir, opts)); | ||
}; | ||
|
||
exports.subscribe = async (dir, fn, opts) => { | ||
dir = path.resolve(dir); | ||
opts = normalizeOptions(dir, opts); | ||
await binding.subscribe(dir, fn, opts); | ||
|
||
return { | ||
unsubscribe() { | ||
return binding.unsubscribe(dir, fn, opts); | ||
} | ||
}; | ||
}; | ||
|
||
exports.unsubscribe = (dir, fn, opts) => { | ||
return binding.unsubscribe(path.resolve(dir), fn, normalizeOptions(dir, opts)); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters