Comparing version 0.1.2 to 0.2.0
201
lib/cli.js
// Generated by IcedCoffeeScript 1.3.3f | ||
(function() { | ||
var FSMonitorTool, RelPathList, RelPathSpec, USAGE, displayStringForShellArgs, escapeShellArgForDisplay, fsmonitor, spawn, _ref; | ||
var FSMonitorTool, RelPathList, RelPathSpec, USAGE, displayStringForShellArgs, escapeShellArgForDisplay, fsmonitor, iced, spawn, __iced_k, __iced_k_noop, _ref, | ||
__slice = [].slice; | ||
iced = { | ||
Deferrals: (function() { | ||
function _Class(_arg) { | ||
this.continuation = _arg; | ||
this.count = 1; | ||
this.ret = null; | ||
} | ||
_Class.prototype._fulfill = function() { | ||
if (!--this.count) return this.continuation(this.ret); | ||
}; | ||
_Class.prototype.defer = function(defer_params) { | ||
var _this = this; | ||
++this.count; | ||
return function() { | ||
var inner_params, _ref; | ||
inner_params = 1 <= arguments.length ? __slice.call(arguments, 0) : []; | ||
if (defer_params != null) { | ||
if ((_ref = defer_params.assign_fn) != null) { | ||
_ref.apply(null, inner_params); | ||
} | ||
} | ||
return _this._fulfill(); | ||
}; | ||
}; | ||
return _Class; | ||
})(), | ||
findDeferral: function() { | ||
return null; | ||
} | ||
}; | ||
__iced_k = __iced_k_noop = function() {}; | ||
_ref = require('pathspec'), RelPathList = _ref.RelPathList, RelPathSpec = _ref.RelPathSpec; | ||
@@ -11,3 +49,3 @@ | ||
USAGE = "Usage: fsmonitor [-d <folder>] [-p] [-s] [-q] [<mask>]... [<command> <arg>...]\n\nOptions:\n -d <folder> Specify the folder to monitor (defaults to the current folder)\n -p Print changes to console (default if no command specified)\n -s Run the provided command once on start up\n -q Quiet mode (don't print the initial banner)\n\nMasks:\n +<mask> Include only the files matching the given mask\n !<mask> Exclude files matching the given mask\n\n If no inclusion masks are provided, all files not explicitly excluded will be included.\n\nGeneral options:\n --help Display this message\n --version Display fsmonitor version number"; | ||
USAGE = "Usage: fsmonitor [-d <folder>] [-p] [-s] [-q] [<mask>]... [<command> <arg>...]\n\nOptions:\n -d <folder> Specify the folder to monitor (defaults to the current folder)\n -p Print changes to console (default if no command specified)\n -s Run the provided command once on start up\n -l Display a full list of matched (monitored) files and folders\n -q Quiet mode (don't print the initial banner)\n -J <subst> Replace <subst> in the executed command with the name of the modified file\n (this also changes how multiple changes are handled; normally, the command\n is only invoked once per a batch of changes; when -J is specified, the command\n is invoked once per every modified file)\n\nMasks:\n +<mask> Include only the files matching the given mask\n !<mask> Exclude files matching the given mask\n\n If no inclusion masks are provided, all files not explicitly excluded will be included.\n\nGeneral options:\n --help Display this message\n --version Display fsmonitor version number"; | ||
@@ -43,4 +81,4 @@ escapeShellArgForDisplay = function(arg) { | ||
this.list = new RelPathList(); | ||
this.included = []; | ||
this.excluded = []; | ||
this.list.include(RelPathSpec.parse('**')); | ||
this.list2 = new RelPathList(); | ||
this.folder = process.cwd(); | ||
@@ -51,2 +89,4 @@ this.command = []; | ||
this.prerun = false; | ||
this.subst = null; | ||
this.listFiles = false; | ||
this._latestChangeForExternalCommand = null; | ||
@@ -57,3 +97,3 @@ this._externalCommandRunning = false; | ||
FSMonitorTool.prototype.parseCommandLine = function(argv) { | ||
var arg, mask, requiredValue, _i, _j, _len, _len1, _ref1, _ref2, _results; | ||
var arg, requiredValue, spec, _ref1; | ||
requiredValue = function(arg) { | ||
@@ -83,2 +123,6 @@ if (argv.length === 0) { | ||
} else if (arg.match(/^-./)) { | ||
if (arg.match(/^-[dJ]./)) { | ||
argv.unshift(arg.substr(2)); | ||
arg = arg.substr(0, 2); | ||
} | ||
switch (arg) { | ||
@@ -88,2 +132,5 @@ case '-d': | ||
break; | ||
case '-J': | ||
this.subst = requiredValue(); | ||
break; | ||
case '-p': | ||
@@ -98,2 +145,5 @@ this.print = true; | ||
break; | ||
case '-l': | ||
this.listFiles = true; | ||
break; | ||
default: | ||
@@ -105,5 +155,12 @@ process.stderr.write(" *** Unknown option: " + arg + ".\n"); | ||
if (arg.match(/^!/)) { | ||
this.excluded.push(arg.slice(1)); | ||
spec = RelPathSpec.parseGitStyleSpec(arg.slice(1)); | ||
this.list.exclude(spec); | ||
if ((_ref1 = this.list2) != null) _ref1.exclude(spec); | ||
} else if (arg.match(/^[+]/)) { | ||
this.included.push(arg.slice(1)); | ||
spec = RelPathSpec.parseGitStyleSpec(arg.slice(1)); | ||
if (this.list2) { | ||
this.list = this.list2; | ||
this.list2 = null; | ||
} | ||
this.list.include(spec); | ||
} else { | ||
@@ -116,19 +173,3 @@ argv.unshift(arg); | ||
this.command = argv; | ||
if (this.command.length === 0) this.print = true; | ||
if (this.included.length > 0) { | ||
_ref1 = this.included; | ||
for (_i = 0, _len = _ref1.length; _i < _len; _i++) { | ||
mask = _ref1[_i]; | ||
this.list.include(RelPathSpec.parseGitStyleSpec(mask)); | ||
} | ||
} else { | ||
this.list.include(RelPathSpec.parse('**')); | ||
} | ||
_ref2 = this.excluded; | ||
_results = []; | ||
for (_j = 0, _len1 = _ref2.length; _j < _len1; _j++) { | ||
mask = _ref2[_j]; | ||
_results.push(this.list.exclude(RelPathSpec.parseGitStyleSpec(mask))); | ||
} | ||
return _results; | ||
if (this.command.length === 0) return this.print = true; | ||
}; | ||
@@ -148,2 +189,3 @@ | ||
process.stderr.write(" action: " + action + "\n"); | ||
if (this.subst) process.stderr.write(" subst: " + this.subst + "\n"); | ||
return process.stderr.write("\n"); | ||
@@ -153,3 +195,22 @@ }; | ||
FSMonitorTool.prototype.startMonitoring = function() { | ||
return fsmonitor.watch(this.folder, this.list, this.handleChange.bind(this)); | ||
var watcher, | ||
_this = this; | ||
watcher = fsmonitor.watch(this.folder, this.list, this.handleChange.bind(this)); | ||
return watcher.on('complete', function() { | ||
var file, folder, _i, _j, _len, _len1, _ref1, _ref2; | ||
if (_this.listFiles) { | ||
_ref1 = watcher.tree.allFiles; | ||
for (_i = 0, _len = _ref1.length; _i < _len; _i++) { | ||
file = _ref1[_i]; | ||
process.stdout.write("" + file + "\n"); | ||
} | ||
_ref2 = watcher.tree.allFolders; | ||
for (_j = 0, _len1 = _ref2.length; _j < _len1; _j++) { | ||
folder = _ref2[_j]; | ||
process.stdout.write("" + folder + "/\n"); | ||
} | ||
process.exit(); | ||
} | ||
if (!_this.quiet) return process.stderr.write("..."); | ||
}); | ||
}; | ||
@@ -176,3 +237,7 @@ | ||
FSMonitorTool.prototype.executeCommandForChange = function(change) { | ||
this._latestChangeForExternalCommand = change; | ||
if (this._latestChangeForExternalCommand) { | ||
this._latestChangeForExternalCommand.append(change); | ||
} else { | ||
this._latestChangeForExternalCommand = change; | ||
} | ||
return this._scheduleExternalCommandExecution(); | ||
@@ -185,11 +250,72 @@ }; | ||
return process.nextTick(function() { | ||
var change, child; | ||
var arg, change, command, file, files, ___iced_passed_deferral, __iced_deferrals, __iced_k; | ||
__iced_k = __iced_k_noop; | ||
___iced_passed_deferral = iced.findDeferral(arguments); | ||
change = _this._latestChangeForExternalCommand; | ||
_this._latestChangeForExternalCommand = null; | ||
_this._externalCommandRunning = true; | ||
process.stderr.write("" + (displayStringForShellArgs(_this.command)) + "\n"); | ||
child = spawn(_this.command[0], _this.command.slice(1), { | ||
stdio: 'inherit' | ||
}); | ||
return child.on('exit', function() { | ||
(function(__iced_k) { | ||
if (_this.subst) { | ||
files = change.addedFiles.concat(change.modifiedFiles); | ||
(function(__iced_k) { | ||
var _i, _len, _ref1, _results, _while; | ||
_ref1 = files; | ||
_len = _ref1.length; | ||
_i = 0; | ||
_results = []; | ||
_while = function(__iced_k) { | ||
var _break, _continue, _next; | ||
_break = function() { | ||
return __iced_k(_results); | ||
}; | ||
_continue = function() { | ||
++_i; | ||
return _while(__iced_k); | ||
}; | ||
_next = function(__iced_next_arg) { | ||
_results.push(__iced_next_arg); | ||
return _continue(); | ||
}; | ||
if (!(_i < _len)) { | ||
return _break(); | ||
} else { | ||
file = _ref1[_i]; | ||
command = (function() { | ||
var _j, _len1, _ref2, _results1; | ||
_ref2 = this.command; | ||
_results1 = []; | ||
for (_j = 0, _len1 = _ref2.length; _j < _len1; _j++) { | ||
arg = _ref2[_j]; | ||
_results1.push(arg.replace(this.subst, file)); | ||
} | ||
return _results1; | ||
}).call(_this); | ||
(function(__iced_k) { | ||
__iced_deferrals = new iced.Deferrals(__iced_k, { | ||
parent: ___iced_passed_deferral, | ||
filename: "generic/fsmonitor.js/lib/cli.iced" | ||
}); | ||
_this._invokeExternalCommand(command, __iced_deferrals.defer({ | ||
lineno: 185 | ||
})); | ||
__iced_deferrals._fulfill(); | ||
})(_next); | ||
} | ||
}; | ||
_while(__iced_k); | ||
})(__iced_k); | ||
} else { | ||
(function(__iced_k) { | ||
__iced_deferrals = new iced.Deferrals(__iced_k, { | ||
parent: ___iced_passed_deferral, | ||
filename: "generic/fsmonitor.js/lib/cli.iced" | ||
}); | ||
_this._invokeExternalCommand(_this.command, __iced_deferrals.defer({ | ||
lineno: 187 | ||
})); | ||
__iced_deferrals._fulfill(); | ||
})(__iced_k); | ||
} | ||
})(function() { | ||
if (!_this.quiet) process.stderr.write("\n..."); | ||
_this._externalCommandRunning = false; | ||
@@ -202,2 +328,13 @@ return _this._scheduleExternalCommandExecution(); | ||
FSMonitorTool.prototype._invokeExternalCommand = function(command, callback) { | ||
var child; | ||
if (!this.quiet) { | ||
process.stderr.write("\r" + (displayStringForShellArgs(command)) + "\n"); | ||
} | ||
child = spawn(command[0], command.slice(1), { | ||
stdio: 'inherit' | ||
}); | ||
return child.on('exit', callback); | ||
}; | ||
return FSMonitorTool; | ||
@@ -204,0 +341,0 @@ |
// Generated by IcedCoffeeScript 1.3.3f | ||
(function() { | ||
var EventEmitter, FSChange, FSFile, FSTree, Path, PlaPath, debug, fs, iced, __iced_k, __iced_k_noop, | ||
var EventEmitter, FSChange, FSFile, FSTree, Path, PlaPath, appendUniques, debug, fs, iced, prependUniques, __iced_k, __iced_k_noop, | ||
__slice = [].slice, | ||
@@ -55,2 +55,20 @@ __hasProp = {}.hasOwnProperty, | ||
prependUniques = function(dest, source) { | ||
var item, _i, _len; | ||
for (_i = 0, _len = source.length; _i < _len; _i++) { | ||
item = source[_i]; | ||
if (dest.indexOf(item) < 0) dest.unshift(item); | ||
} | ||
return dest; | ||
}; | ||
appendUniques = function(dest, source) { | ||
var item, _i, _len; | ||
for (_i = 0, _len = source.length; _i < _len; _i++) { | ||
item = source[_i]; | ||
if (dest.indexOf(item) < 0) dest.push(item); | ||
} | ||
return dest; | ||
}; | ||
FSFile = (function() { | ||
@@ -94,2 +112,20 @@ | ||
FSChange.prototype.prepend = function(peer) { | ||
prependUniques(this.addedFiles, peer.addedFiles); | ||
prependUniques(this.modifiedFiles, peer.modifiedFiles); | ||
prependUniques(this.removedFiles, peer.removedFiles); | ||
prependUniques(this.addedFolders, peer.addedFolders); | ||
prependUniques(this.modifiedFolders, peer.modifiedFolders); | ||
return prependUniques(this.removedFolders, peer.removedFolders); | ||
}; | ||
FSChange.prototype.append = function(peer) { | ||
appendUniques(this.addedFiles, peer.addedFiles); | ||
appendUniques(this.modifiedFiles, peer.modifiedFiles); | ||
appendUniques(this.removedFiles, peer.removedFiles); | ||
appendUniques(this.addedFolders, peer.addedFolders); | ||
appendUniques(this.modifiedFolders, peer.modifiedFolders); | ||
return appendUniques(this.removedFolders, peer.removedFolders); | ||
}; | ||
FSChange.prototype.toString = function() { | ||
@@ -124,2 +160,14 @@ return [this._listToString('+', this.addedFiles, ''), this._listToString('!', this.modifiedFiles, ''), this._listToString('-', this.removedFiles, ''), this._listToString('+', this.addedFolders, '/'), this._listToString('!', this.modifiedFolders, '/'), this._listToString('-', this.removedFolders, '/')].join(''); | ||
this.root = root; | ||
this.filter = filter; | ||
if (this.filter && !((typeof this.filter.matches === 'function') && (typeof this.filter.excludes === 'function'))) { | ||
throw new Error("Invalid filter provided to FSTree; must define .matches() and .excludes()"); | ||
} | ||
this.filter || (this.filter = { | ||
matches: (function() { | ||
return true; | ||
}), | ||
excludes: (function() { | ||
return false; | ||
}) | ||
}); | ||
this._files = []; | ||
@@ -131,7 +179,7 @@ this._folders = []; | ||
parent: ___iced_passed_deferral, | ||
filename: "../mini/fsmonitor.js/lib/tree.iced", | ||
filename: "generic/fsmonitor.js/lib/tree.iced", | ||
funcname: "FSTree" | ||
}); | ||
_this._walk(_this.root, '', __iced_deferrals.defer({ | ||
lineno: 59 | ||
lineno: 93 | ||
})); | ||
@@ -142,3 +190,3 @@ __iced_deferrals._fulfill(); | ||
_this._updateInProgress = false; | ||
debug("Finished building FSTree with " + _this._files.length + " files at " + _this.root); | ||
debug("Finished building FSTree with " + _this._files.length + " files and " + _this._folders.length + " folders at " + _this.root); | ||
return _this.emit('complete'); | ||
@@ -179,7 +227,7 @@ }); | ||
parent: ___iced_passed_deferral, | ||
filename: "../mini/fsmonitor.js/lib/tree.iced", | ||
filename: "generic/fsmonitor.js/lib/tree.iced", | ||
funcname: "FSTree._performQueuedUpdate" | ||
}); | ||
_this._walk(_this.root, '', __iced_deferrals.defer({ | ||
lineno: 90 | ||
lineno: 124 | ||
})); | ||
@@ -355,2 +403,3 @@ __iced_deferrals._fulfill(); | ||
FSTree.prototype._addFile = function(relpath, stats) { | ||
debug("file: " + relpath); | ||
return this._files.push(new FSFile(relpath, stats)); | ||
@@ -360,2 +409,3 @@ }; | ||
FSTree.prototype._addFolder = function(relpath, stats) { | ||
debug("FOLD: " + relpath); | ||
return this._folders.push(new FSFile(relpath, stats)); | ||
@@ -372,3 +422,3 @@ }; | ||
parent: ___iced_passed_deferral, | ||
filename: "../mini/fsmonitor.js/lib/tree.iced", | ||
filename: "generic/fsmonitor.js/lib/tree.iced", | ||
funcname: "FSTree._walk" | ||
@@ -383,3 +433,3 @@ }); | ||
})(), | ||
lineno: 188 | ||
lineno: 224 | ||
})); | ||
@@ -394,6 +444,11 @@ __iced_deferrals._fulfill(); | ||
if (stats.isFile()) { | ||
return __iced_k(_this._addFile(relpath, stats)); | ||
return __iced_k(_this.filter.matches(relpath, false) ? _this._addFile(relpath, stats) : void 0); | ||
} else { | ||
(function(__iced_k) { | ||
if (stats.isDirectory()) { | ||
if (_this.filter.excludes(relpath, true)) { | ||
autocb(); | ||
return; | ||
} | ||
_this._addFolder(relpath, stats); | ||
@@ -403,3 +458,3 @@ (function(__iced_k) { | ||
parent: ___iced_passed_deferral, | ||
filename: "../mini/fsmonitor.js/lib/tree.iced", | ||
filename: "generic/fsmonitor.js/lib/tree.iced", | ||
funcname: "FSTree._walk" | ||
@@ -414,3 +469,3 @@ }); | ||
})(), | ||
lineno: 196 | ||
lineno: 234 | ||
})); | ||
@@ -450,7 +505,7 @@ __iced_deferrals._fulfill(); | ||
parent: ___iced_passed_deferral, | ||
filename: "../mini/fsmonitor.js/lib/tree.iced", | ||
filename: "generic/fsmonitor.js/lib/tree.iced", | ||
funcname: "FSTree._walk" | ||
}); | ||
_this._walk(Path.join(path, file), Path.join(relpath, file), __iced_deferrals.defer({ | ||
lineno: 200 | ||
lineno: 238 | ||
})); | ||
@@ -457,0 +512,0 @@ __iced_deferrals._fulfill(); |
{ | ||
"name": "fsmonitor", | ||
"version": "0.1.2", | ||
"version": "0.2.0", | ||
"description": "Fine-grained cross-platform file system monitoring for Node.js", | ||
@@ -5,0 +5,0 @@ "main": "lib/index.js", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Long strings
Supply chain riskContains long string literals, which may be a sign of obfuscated or packed code.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
40834
988
4