watch-tree-maintained
Version:
Yet another library for watching FS trees. Includes a JSON-on-stdout command-line tool and {filePreexisted,allPreexistingFilesReported} events.
58 lines (43 loc) • 1.21 kB
text/coffeescript
{exec} = require 'child_process'
util = try require 'util' catch e then require 'sys'
exports.check_exec_options = check_exec_options = (cmd, options, callback) ->
exec cmd, options, (e, stdout, stderr) ->
throw e if e
callback() if callback
exports.check_exec = check_exec = (cmd, callback) ->
exec cmd, (e, stdout, stderr) ->
throw e if e
callback() if callback
exports.listsContainSameElements = listsContainSameElements = (t, arr1, arr2) ->
d1 = {}
d2 = {}
for x in arr1
d1[x] = true
for x in arr2
d2[x] = true
t.deepEqual d1, d2
exports.EventBuffer = class EventBuffer
constructor: () ->
= []
= null
wait: (callback) ->
if .length > 0
event = .pop()
callback event
else
if
throw new Error "Only store one callback"
= callback
expect: (t, args...) ->
util.debug "Expecting #{args[0]}..."
(event) ->
for x, i in args[...-1]
t.equal event[i], x
args[-1...][0](event)
event: (event) ->
if
callback =
= null
callback event
else
.push event