batman-rails-flo 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/README.md +29 -0
- data/Rakefile +2 -0
- data/lib/batman-rails-flo.rb +5 -0
- data/lib/batman_rails_flo/railtie.rb +9 -0
- data/lib/batman_rails_flo/tasks.rake +14 -0
- data/lib/batman_rails_flo/version.rb +3 -0
- data/vendor/assets/javascripts/batman_rails_flo/flo_server.js +67 -0
- data/vendor/assets/javascripts/batman_rails_flo/live_reload.js.coffee +129 -0
- data/vendor/assets/javascripts/batman_rails_flo/node_modules/coffee-script/CNAME +1 -0
- data/vendor/assets/javascripts/batman_rails_flo/node_modules/coffee-script/CONTRIBUTING.md +9 -0
- data/vendor/assets/javascripts/batman_rails_flo/node_modules/coffee-script/LICENSE +22 -0
- data/vendor/assets/javascripts/batman_rails_flo/node_modules/coffee-script/README +50 -0
- data/vendor/assets/javascripts/batman_rails_flo/node_modules/coffee-script/bin/cake +7 -0
- data/vendor/assets/javascripts/batman_rails_flo/node_modules/coffee-script/bin/coffee +7 -0
- data/vendor/assets/javascripts/batman_rails_flo/node_modules/coffee-script/lib/coffee-script/browser.js +134 -0
- data/vendor/assets/javascripts/batman_rails_flo/node_modules/coffee-script/lib/coffee-script/cake.js +112 -0
- data/vendor/assets/javascripts/batman_rails_flo/node_modules/coffee-script/lib/coffee-script/coffee-script.js +335 -0
- data/vendor/assets/javascripts/batman_rails_flo/node_modules/coffee-script/lib/coffee-script/command.js +569 -0
- data/vendor/assets/javascripts/batman_rails_flo/node_modules/coffee-script/lib/coffee-script/grammar.js +631 -0
- data/vendor/assets/javascripts/batman_rails_flo/node_modules/coffee-script/lib/coffee-script/helpers.js +252 -0
- data/vendor/assets/javascripts/batman_rails_flo/node_modules/coffee-script/lib/coffee-script/index.js +11 -0
- data/vendor/assets/javascripts/batman_rails_flo/node_modules/coffee-script/lib/coffee-script/lexer.js +926 -0
- data/vendor/assets/javascripts/batman_rails_flo/node_modules/coffee-script/lib/coffee-script/nodes.js +3158 -0
- data/vendor/assets/javascripts/batman_rails_flo/node_modules/coffee-script/lib/coffee-script/optparse.js +139 -0
- data/vendor/assets/javascripts/batman_rails_flo/node_modules/coffee-script/lib/coffee-script/parser.js +724 -0
- data/vendor/assets/javascripts/batman_rails_flo/node_modules/coffee-script/lib/coffee-script/register.js +66 -0
- data/vendor/assets/javascripts/batman_rails_flo/node_modules/coffee-script/lib/coffee-script/repl.js +163 -0
- data/vendor/assets/javascripts/batman_rails_flo/node_modules/coffee-script/lib/coffee-script/rewriter.js +475 -0
- data/vendor/assets/javascripts/batman_rails_flo/node_modules/coffee-script/lib/coffee-script/scope.js +146 -0
- data/vendor/assets/javascripts/batman_rails_flo/node_modules/coffee-script/lib/coffee-script/sourcemap.js +161 -0
- data/vendor/assets/javascripts/batman_rails_flo/node_modules/coffee-script/node_modules/mkdirp/LICENSE +21 -0
- data/vendor/assets/javascripts/batman_rails_flo/node_modules/coffee-script/node_modules/mkdirp/examples/pow.js +6 -0
- data/vendor/assets/javascripts/batman_rails_flo/node_modules/coffee-script/node_modules/mkdirp/index.js +82 -0
- data/vendor/assets/javascripts/batman_rails_flo/node_modules/coffee-script/node_modules/mkdirp/package.json +34 -0
- data/vendor/assets/javascripts/batman_rails_flo/node_modules/coffee-script/node_modules/mkdirp/readme.markdown +63 -0
- data/vendor/assets/javascripts/batman_rails_flo/node_modules/coffee-script/node_modules/mkdirp/test/chmod.js +38 -0
- data/vendor/assets/javascripts/batman_rails_flo/node_modules/coffee-script/node_modules/mkdirp/test/clobber.js +37 -0
- data/vendor/assets/javascripts/batman_rails_flo/node_modules/coffee-script/node_modules/mkdirp/test/mkdirp.js +28 -0
- data/vendor/assets/javascripts/batman_rails_flo/node_modules/coffee-script/node_modules/mkdirp/test/perm.js +32 -0
- data/vendor/assets/javascripts/batman_rails_flo/node_modules/coffee-script/node_modules/mkdirp/test/perm_sync.js +39 -0
- data/vendor/assets/javascripts/batman_rails_flo/node_modules/coffee-script/node_modules/mkdirp/test/race.js +41 -0
- data/vendor/assets/javascripts/batman_rails_flo/node_modules/coffee-script/node_modules/mkdirp/test/rel.js +32 -0
- data/vendor/assets/javascripts/batman_rails_flo/node_modules/coffee-script/node_modules/mkdirp/test/return.js +25 -0
- data/vendor/assets/javascripts/batman_rails_flo/node_modules/coffee-script/node_modules/mkdirp/test/return_sync.js +24 -0
- data/vendor/assets/javascripts/batman_rails_flo/node_modules/coffee-script/node_modules/mkdirp/test/root.js +18 -0
- data/vendor/assets/javascripts/batman_rails_flo/node_modules/coffee-script/node_modules/mkdirp/test/sync.js +32 -0
- data/vendor/assets/javascripts/batman_rails_flo/node_modules/coffee-script/node_modules/mkdirp/test/umask.js +28 -0
- data/vendor/assets/javascripts/batman_rails_flo/node_modules/coffee-script/node_modules/mkdirp/test/umask_sync.js +32 -0
- data/vendor/assets/javascripts/batman_rails_flo/node_modules/coffee-script/package.json +50 -0
- data/vendor/assets/javascripts/batman_rails_flo/node_modules/coffee-script/register.js +1 -0
- data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/LICENSE +30 -0
- data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/PATENTS +23 -0
- data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/README.md +124 -0
- data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/bin/flo +26 -0
- data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/client/configure/configure.html +57 -0
- data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/client/configure/configure.js +205 -0
- data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/client/configure/style.css +334 -0
- data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/client/connection.js +235 -0
- data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/client/devtools.html +12 -0
- data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/client/index.js +323 -0
- data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/client/logger.js +42 -0
- data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/client/logo.png +0 -0
- data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/client/manifest.json +13 -0
- data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/client/session.js +305 -0
- data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/index.js +10 -0
- data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/lib/flo.js +226 -0
- data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/lib/server.js +94 -0
- data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/node_modules/sane/README.md +66 -0
- data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/node_modules/sane/index.js +437 -0
- data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/node_modules/sane/node_modules/minimatch/LICENSE +23 -0
- data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/node_modules/sane/node_modules/minimatch/README.md +218 -0
- data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/node_modules/sane/node_modules/minimatch/minimatch.js +1055 -0
- data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/node_modules/sane/node_modules/minimatch/node_modules/lru-cache/CONTRIBUTORS +14 -0
- data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/node_modules/sane/node_modules/minimatch/node_modules/lru-cache/LICENSE +23 -0
- data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/node_modules/sane/node_modules/minimatch/node_modules/lru-cache/README.md +97 -0
- data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/node_modules/sane/node_modules/minimatch/node_modules/lru-cache/lib/lru-cache.js +252 -0
- data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/node_modules/sane/node_modules/minimatch/node_modules/lru-cache/package.json +33 -0
- data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/node_modules/sane/node_modules/minimatch/node_modules/lru-cache/test/basic.js +369 -0
- data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/node_modules/sane/node_modules/minimatch/node_modules/lru-cache/test/foreach.js +52 -0
- data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/node_modules/sane/node_modules/minimatch/node_modules/lru-cache/test/memory-leak.js +50 -0
- data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/node_modules/sane/node_modules/minimatch/node_modules/sigmund/LICENSE +27 -0
- data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/node_modules/sane/node_modules/minimatch/node_modules/sigmund/README.md +53 -0
- data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/node_modules/sane/node_modules/minimatch/node_modules/sigmund/bench.js +283 -0
- data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/node_modules/sane/node_modules/minimatch/node_modules/sigmund/package.json +42 -0
- data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/node_modules/sane/node_modules/minimatch/node_modules/sigmund/sigmund.js +39 -0
- data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/node_modules/sane/node_modules/minimatch/node_modules/sigmund/test/basic.js +24 -0
- data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/node_modules/sane/node_modules/minimatch/package.json +40 -0
- data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/node_modules/sane/node_modules/minimatch/test/basic.js +399 -0
- data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/node_modules/sane/node_modules/minimatch/test/brace-expand.js +33 -0
- data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/node_modules/sane/node_modules/minimatch/test/caching.js +14 -0
- data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/node_modules/sane/node_modules/minimatch/test/defaults.js +274 -0
- data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/node_modules/sane/node_modules/minimatch/test/extglob-ending-with-state-char.js +8 -0
- data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/node_modules/sane/node_modules/walker/lib/walker.js +111 -0
- data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/node_modules/sane/node_modules/walker/license +13 -0
- data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/node_modules/sane/node_modules/walker/node_modules/makeerror/lib/makeerror.js +87 -0
- data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/node_modules/sane/node_modules/walker/node_modules/makeerror/node_modules/tmpl/lib/tmpl.js +17 -0
- data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/node_modules/sane/node_modules/walker/node_modules/makeerror/node_modules/tmpl/package.json +31 -0
- data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/node_modules/sane/node_modules/walker/node_modules/makeerror/node_modules/tmpl/readme.md +10 -0
- data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/node_modules/sane/node_modules/walker/node_modules/makeerror/package.json +34 -0
- data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/node_modules/sane/node_modules/walker/node_modules/makeerror/readme.md +77 -0
- data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/node_modules/sane/node_modules/walker/package.json +36 -0
- data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/node_modules/sane/node_modules/walker/readme.md +52 -0
- data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/node_modules/sane/node_modules/watch/LICENSE +55 -0
- data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/node_modules/sane/node_modules/watch/main.js +128 -0
- data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/node_modules/sane/node_modules/watch/package.json +34 -0
- data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/node_modules/sane/node_modules/watch/readme.mkd +72 -0
- data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/node_modules/sane/node_modules/watch/test/d/d/t +0 -0
- data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/node_modules/sane/node_modules/watch/test/d/t +0 -0
- data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/node_modules/sane/node_modules/watch/test/test_monitor.js +31 -0
- data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/node_modules/sane/node_modules/watch/test/test_monitorRootDirectory.js +28 -0
- data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/node_modules/sane/node_modules/watch/test/test_watchTree.js +20 -0
- data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/node_modules/sane/package.json +45 -0
- data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/node_modules/sane/test/test.js +243 -0
- data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/node_modules/websocket/CHANGELOG.md +81 -0
- data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/node_modules/websocket/LICENSE +177 -0
- data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/node_modules/websocket/Makefile +11 -0
- data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/node_modules/websocket/README.md +245 -0
- data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/node_modules/websocket/binding.gyp +14 -0
- data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/node_modules/websocket/build/Makefile +355 -0
- data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/node_modules/websocket/build/Release/linker.lock +0 -0
- data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/node_modules/websocket/build/Release/obj.target/validation/src/validation.o +0 -0
- data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/node_modules/websocket/build/Release/obj.target/xor/src/xor.o +0 -0
- data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/node_modules/websocket/build/Release/validation.node +0 -0
- data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/node_modules/websocket/build/Release/xor.node +0 -0
- data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/node_modules/websocket/build/binding.Makefile +6 -0
- data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/node_modules/websocket/build/config.gypi +115 -0
- data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/node_modules/websocket/build/gyp-mac-tool +512 -0
- data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/node_modules/websocket/build/validation.target.mk +154 -0
- data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/node_modules/websocket/build/xor.target.mk +154 -0
- data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/node_modules/websocket/index.js +1 -0
- data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/node_modules/websocket/install.js +31 -0
- data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/node_modules/websocket/lib/Constants.js +23 -0
- data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/node_modules/websocket/lib/Deprecation.js +38 -0
- data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/node_modules/websocket/lib/Validation.fallback.js +12 -0
- data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/node_modules/websocket/lib/Validation.js +18 -0
- data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/node_modules/websocket/lib/WebSocketClient.js +359 -0
- data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/node_modules/websocket/lib/WebSocketConnection.js +717 -0
- data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/node_modules/websocket/lib/WebSocketFrame.js +282 -0
- data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/node_modules/websocket/lib/WebSocketRequest.js +478 -0
- data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/node_modules/websocket/lib/WebSocketRouter.js +154 -0
- data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/node_modules/websocket/lib/WebSocketRouterRequest.js +59 -0
- data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/node_modules/websocket/lib/WebSocketServer.js +216 -0
- data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/node_modules/websocket/lib/utils.js +7 -0
- data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/node_modules/websocket/lib/websocket.js +11 -0
- data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/node_modules/websocket/lib/xor.fallback.js +13 -0
- data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/node_modules/websocket/lib/xor.js +18 -0
- data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/node_modules/websocket/package.json +43 -0
- data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/node_modules/websocket/src/validation.cc +144 -0
- data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/node_modules/websocket/src/xor.cpp +86 -0
- data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/node_modules/websocket/vendor/FastBufferList.js +192 -0
- data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/node_modules/websocket/vendor/node-ctype/LICENSE +18 -0
- data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/node_modules/websocket/vendor/node-ctype/ctio-faster.js +1126 -0
- data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/package.json +25 -0
- data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/test/client/browser_websocket.js +63 -0
- data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/test/client/connection_test.js +57 -0
- data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/test/client/logger_mock.js +15 -0
- data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/test/client/session_test.js +194 -0
- data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/test/server/flo_test.js +211 -0
- data/vendor/assets/javascripts/batman_rails_flo/package.json +15 -0
- data/vendor/assets/javascripts/batman_rails_flo/reload_event_handler.js.coffee +56 -0
- metadata +232 -0
@@ -0,0 +1,87 @@
|
|
1
|
+
var tmpl = require('tmpl')
|
2
|
+
|
3
|
+
module.exports = makeError
|
4
|
+
|
5
|
+
function BaseError() {}
|
6
|
+
BaseError.prototype = new Error()
|
7
|
+
BaseError.prototype.toString = function() {
|
8
|
+
return this.message
|
9
|
+
}
|
10
|
+
|
11
|
+
|
12
|
+
/**
|
13
|
+
* Makes an Error function with the signature:
|
14
|
+
*
|
15
|
+
* function(message, data)
|
16
|
+
*
|
17
|
+
* You'll typically do something like:
|
18
|
+
*
|
19
|
+
* var UnknownFileTypeError = makeError(
|
20
|
+
* 'UnknownFileTypeError',
|
21
|
+
* 'The specified type is not known.'
|
22
|
+
* )
|
23
|
+
* var er = UnknownFileTypeError()
|
24
|
+
*
|
25
|
+
* `er` will have a prototype chain that ensures:
|
26
|
+
*
|
27
|
+
* er instanceof Error
|
28
|
+
* er instanceof UnknownFileTypeError
|
29
|
+
*
|
30
|
+
* You can also do `var er = new UnknownFileTypeError()` if you really like the
|
31
|
+
* `new` keyword.
|
32
|
+
*
|
33
|
+
* @param String The name of the error.
|
34
|
+
* @param String The default message string.
|
35
|
+
* @param Object The default data object, merged with per instance data.
|
36
|
+
*/
|
37
|
+
function makeError(name, defaultMessage, defaultData) {
|
38
|
+
defaultMessage = tmpl(defaultMessage || '')
|
39
|
+
defaultData = defaultData || {}
|
40
|
+
if (defaultData.proto && !(defaultData.proto instanceof BaseError))
|
41
|
+
throw new Error('The custom "proto" must be an Error created via makeError')
|
42
|
+
|
43
|
+
var CustomError = function(message, data) {
|
44
|
+
if (!(this instanceof CustomError)) return new CustomError(message, data)
|
45
|
+
|
46
|
+
if (typeof message !== 'string' && !data) {
|
47
|
+
data = message
|
48
|
+
message = null
|
49
|
+
}
|
50
|
+
|
51
|
+
this.name = name
|
52
|
+
this.data = data || defaultData
|
53
|
+
|
54
|
+
if (typeof message === 'string') {
|
55
|
+
this.message = tmpl(message, this.data)
|
56
|
+
} else {
|
57
|
+
this.message = defaultMessage(this.data)
|
58
|
+
}
|
59
|
+
|
60
|
+
var er = new Error()
|
61
|
+
this.stack = er.stack
|
62
|
+
if (this.stack) {
|
63
|
+
// remove TWO stack level:
|
64
|
+
if (typeof Components !== 'undefined') {
|
65
|
+
// Mozilla:
|
66
|
+
this.stack = this.stack.substring(this.stack.indexOf('\n') + 2)
|
67
|
+
} else if (typeof chrome !== 'undefined' || typeof process !== 'undefined') {
|
68
|
+
// Google Chrome/Node.js:
|
69
|
+
this.stack = this.stack.replace(/\n[^\n]*/, '')
|
70
|
+
this.stack = this.stack.replace(/\n[^\n]*/, '')
|
71
|
+
this.stack = (
|
72
|
+
this.name +
|
73
|
+
(this.message ? (': ' + this.message) : '') +
|
74
|
+
this.stack.substring(5)
|
75
|
+
)
|
76
|
+
}
|
77
|
+
}
|
78
|
+
|
79
|
+
if ('fileName' in er) this.fileName = er.fileName
|
80
|
+
if ('lineNumber' in er) this.lineNumber = er.lineNumber
|
81
|
+
}
|
82
|
+
|
83
|
+
CustomError.prototype = defaultData.proto || new BaseError()
|
84
|
+
delete defaultData.proto
|
85
|
+
|
86
|
+
return CustomError
|
87
|
+
}
|
@@ -0,0 +1,17 @@
|
|
1
|
+
var INTERPOLATE = /{([\s\S]+?)}/g
|
2
|
+
|
3
|
+
module.exports = function(str, data) {
|
4
|
+
var tmpl = 'var __p=[],print=function(){__p.push.apply(__p,arguments);};' +
|
5
|
+
'with(obj||{}){__p.push(\'' +
|
6
|
+
str.replace(/\\/g, '\\\\')
|
7
|
+
.replace(/'/g, "\\'")
|
8
|
+
.replace(INTERPOLATE, function(match, code) {
|
9
|
+
return "'," + code.replace(/\\'/g, "'") + ",'"
|
10
|
+
})
|
11
|
+
.replace(/\r/g, '\\r')
|
12
|
+
.replace(/\n/g, '\\n')
|
13
|
+
.replace(/\t/g, '\\t')
|
14
|
+
+ "');}return __p.join('');"
|
15
|
+
var func = new Function('obj', tmpl)
|
16
|
+
return data ? func(data) : func
|
17
|
+
}
|
@@ -0,0 +1,31 @@
|
|
1
|
+
{
|
2
|
+
"name": "tmpl",
|
3
|
+
"description": "JavaScript micro templates.",
|
4
|
+
"version": "1.0.1",
|
5
|
+
"homepage": "https://github.com/nshah/nodejs-tmpl",
|
6
|
+
"author": {
|
7
|
+
"name": "Naitik Shah",
|
8
|
+
"email": "n@daaku.org"
|
9
|
+
},
|
10
|
+
"main": "lib/tmpl",
|
11
|
+
"repository": {
|
12
|
+
"type": "git",
|
13
|
+
"url": "https://github.com/nshah/nodejs-tmpl"
|
14
|
+
},
|
15
|
+
"scripts": {
|
16
|
+
"test": "expresso -c"
|
17
|
+
},
|
18
|
+
"devDependencies": {
|
19
|
+
"expresso": ">= 0.8.1"
|
20
|
+
},
|
21
|
+
"engines": {
|
22
|
+
"node": ">= 0.4.1"
|
23
|
+
},
|
24
|
+
"readme": "tmpl\n====\n\nSimple string formatting using `{}`.\n\n```javascript\nassert.equal(\n tmpl('the answer is {answer}', { answer: 42 }),\n 'the answer is 42')\n```\n",
|
25
|
+
"readmeFilename": "readme.md",
|
26
|
+
"bugs": {
|
27
|
+
"url": "https://github.com/nshah/nodejs-tmpl/issues"
|
28
|
+
},
|
29
|
+
"_id": "tmpl@1.0.1",
|
30
|
+
"_from": "tmpl@>= 1.0.0"
|
31
|
+
}
|
@@ -0,0 +1,34 @@
|
|
1
|
+
{
|
2
|
+
"name": "makeerror",
|
3
|
+
"description": "A library to make errors.",
|
4
|
+
"version": "1.0.8",
|
5
|
+
"author": {
|
6
|
+
"name": "Naitik Shah",
|
7
|
+
"email": "n@daaku.org"
|
8
|
+
},
|
9
|
+
"main": "lib/makeerror",
|
10
|
+
"repository": {
|
11
|
+
"type": "git",
|
12
|
+
"url": "http://github.com/nshah/nodejs-makeerror"
|
13
|
+
},
|
14
|
+
"scripts": {
|
15
|
+
"test": "expresso -c"
|
16
|
+
},
|
17
|
+
"dependencies": {
|
18
|
+
"tmpl": ">= 1.0.0"
|
19
|
+
},
|
20
|
+
"devDependencies": {
|
21
|
+
"expresso": ">= 0.8.1"
|
22
|
+
},
|
23
|
+
"engines": {
|
24
|
+
"node": ">= 0.4.1"
|
25
|
+
},
|
26
|
+
"readme": "makeerror\n=========\n\nA library to make errors.\n\n\nBasics\n------\n\nMakes an Error constructor function with the signature below. All arguments are\noptional, and if the first argument is not a `String`, it will be assumed to be\n`data`:\n\n```javascript\nfunction(message, data)\n```\n\nYou'll typically do something like:\n\n```javascript\nvar makeError = require('makeerror')\nvar UnknownFileTypeError = makeError(\n 'UnknownFileTypeError',\n 'The specified type is not known.'\n)\nvar er = UnknownFileTypeError()\n```\n\n`er` will have a prototype chain that ensures:\n\n```javascript\ner instanceof UnknownFileTypeError\ner instanceof Error\n```\n\n\nTemplatized Error Messages\n--------------------------\n\nThere is support for simple string substitutions like:\n\n```javascript\nvar makeError = require('makeerror')\nvar UnknownFileTypeError = makeError(\n 'UnknownFileTypeError',\n 'The specified type \"{type}\" is not known.'\n)\nvar er = UnknownFileTypeError({ type: 'bmp' })\n```\n\nNow `er.message` or `er.toString()` will return `'The specified type \"bmp\" is\nnot known.'`.\n\n\nPrototype Hierarchies\n---------------------\n\nYou can create simple hierarchies as well using the `prototype` chain:\n\n```javascript\nvar makeError = require('makeerror')\nvar ParentError = makeError('ParentError')\nvar ChildError = makeError(\n 'ChildError',\n 'The child error.',\n { proto: ParentError() }\n)\nvar er = ChildError()\n```\n\n`er` will have a prototype chain that ensures:\n\n```javascript\ner instanceof ChildError\ner instanceof ParentError\ner instanceof Error\n```\n",
|
27
|
+
"readmeFilename": "readme.md",
|
28
|
+
"bugs": {
|
29
|
+
"url": "https://github.com/nshah/nodejs-makeerror/issues"
|
30
|
+
},
|
31
|
+
"homepage": "https://github.com/nshah/nodejs-makeerror",
|
32
|
+
"_id": "makeerror@1.0.8",
|
33
|
+
"_from": "makeerror@1.0.x"
|
34
|
+
}
|
@@ -0,0 +1,77 @@
|
|
1
|
+
makeerror
|
2
|
+
=========
|
3
|
+
|
4
|
+
A library to make errors.
|
5
|
+
|
6
|
+
|
7
|
+
Basics
|
8
|
+
------
|
9
|
+
|
10
|
+
Makes an Error constructor function with the signature below. All arguments are
|
11
|
+
optional, and if the first argument is not a `String`, it will be assumed to be
|
12
|
+
`data`:
|
13
|
+
|
14
|
+
```javascript
|
15
|
+
function(message, data)
|
16
|
+
```
|
17
|
+
|
18
|
+
You'll typically do something like:
|
19
|
+
|
20
|
+
```javascript
|
21
|
+
var makeError = require('makeerror')
|
22
|
+
var UnknownFileTypeError = makeError(
|
23
|
+
'UnknownFileTypeError',
|
24
|
+
'The specified type is not known.'
|
25
|
+
)
|
26
|
+
var er = UnknownFileTypeError()
|
27
|
+
```
|
28
|
+
|
29
|
+
`er` will have a prototype chain that ensures:
|
30
|
+
|
31
|
+
```javascript
|
32
|
+
er instanceof UnknownFileTypeError
|
33
|
+
er instanceof Error
|
34
|
+
```
|
35
|
+
|
36
|
+
|
37
|
+
Templatized Error Messages
|
38
|
+
--------------------------
|
39
|
+
|
40
|
+
There is support for simple string substitutions like:
|
41
|
+
|
42
|
+
```javascript
|
43
|
+
var makeError = require('makeerror')
|
44
|
+
var UnknownFileTypeError = makeError(
|
45
|
+
'UnknownFileTypeError',
|
46
|
+
'The specified type "{type}" is not known.'
|
47
|
+
)
|
48
|
+
var er = UnknownFileTypeError({ type: 'bmp' })
|
49
|
+
```
|
50
|
+
|
51
|
+
Now `er.message` or `er.toString()` will return `'The specified type "bmp" is
|
52
|
+
not known.'`.
|
53
|
+
|
54
|
+
|
55
|
+
Prototype Hierarchies
|
56
|
+
---------------------
|
57
|
+
|
58
|
+
You can create simple hierarchies as well using the `prototype` chain:
|
59
|
+
|
60
|
+
```javascript
|
61
|
+
var makeError = require('makeerror')
|
62
|
+
var ParentError = makeError('ParentError')
|
63
|
+
var ChildError = makeError(
|
64
|
+
'ChildError',
|
65
|
+
'The child error.',
|
66
|
+
{ proto: ParentError() }
|
67
|
+
)
|
68
|
+
var er = ChildError()
|
69
|
+
```
|
70
|
+
|
71
|
+
`er` will have a prototype chain that ensures:
|
72
|
+
|
73
|
+
```javascript
|
74
|
+
er instanceof ChildError
|
75
|
+
er instanceof ParentError
|
76
|
+
er instanceof Error
|
77
|
+
```
|
@@ -0,0 +1,36 @@
|
|
1
|
+
{
|
2
|
+
"name": "walker",
|
3
|
+
"description": "A simple directory tree walker.",
|
4
|
+
"version": "1.0.6",
|
5
|
+
"homepage": "https://github.com/daaku/nodejs-walker",
|
6
|
+
"author": {
|
7
|
+
"name": "Naitik Shah",
|
8
|
+
"email": "n@daaku.org"
|
9
|
+
},
|
10
|
+
"keywords": [
|
11
|
+
"utils",
|
12
|
+
"fs",
|
13
|
+
"filesystem"
|
14
|
+
],
|
15
|
+
"main": "lib/walker",
|
16
|
+
"repository": {
|
17
|
+
"type": "git",
|
18
|
+
"url": "https://github.com/daaku/nodejs-walker"
|
19
|
+
},
|
20
|
+
"scripts": {
|
21
|
+
"test": "NODE_PATH=./lib mocha --ui exports"
|
22
|
+
},
|
23
|
+
"dependencies": {
|
24
|
+
"makeerror": "1.0.x"
|
25
|
+
},
|
26
|
+
"devDependencies": {
|
27
|
+
"mocha": "0.12.x"
|
28
|
+
},
|
29
|
+
"readme": "walker [![Build Status](https://secure.travis-ci.org/daaku/nodejs-walker.png)](http://travis-ci.org/daaku/nodejs-walker)\n======\n\nA nodejs directory walker. Broadcasts events for various file types as well as\na generic \"entry\" event for all types and provides the ability to prune\ndirectory trees. This shows the entire API; everything is optional:\n\n```javascript\nWalker('/etc/')\n .filterDir(function(dir, stat) {\n if (dir === '/etc/pam.d') {\n console.warn('Skipping /etc/pam.d and children')\n return false\n }\n return true\n })\n .on('entry', function(entry, stat) {\n console.log('Got entry: ' + entry)\n })\n .on('dir', function(dir, stat) {\n console.log('Got directory: ' + dir)\n })\n .on('file', function(file, stat) {\n console.log('Got file: ' + file)\n })\n .on('symlink', function(symlink, stat) {\n console.log('Got symlink: ' + symlink)\n })\n .on('blockDevice', function(blockDevice, stat) {\n console.log('Got blockDevice: ' + blockDevice)\n })\n .on('fifo', function(fifo, stat) {\n console.log('Got fifo: ' + fifo)\n })\n .on('socket', function(socket, stat) {\n console.log('Got socket: ' + socket)\n })\n .on('characterDevice', function(characterDevice, stat) {\n console.log('Got characterDevice: ' + characterDevice)\n })\n .on('error', function(er, entry, stat) {\n console.log('Got error ' + er + ' on entry ' + entry)\n })\n .on('end', function() {\n console.log('All files traversed.')\n })\n```\n\nYou specify a root directory to walk and optionally specify a function to prune\nsub-directory trees via the `filterDir` function. The Walker exposes a number\nof events, broadcasting various file type events a generic error event and\nfinally the event to signal the end of the process.\n",
|
30
|
+
"readmeFilename": "readme.md",
|
31
|
+
"bugs": {
|
32
|
+
"url": "https://github.com/daaku/nodejs-walker/issues"
|
33
|
+
},
|
34
|
+
"_id": "walker@1.0.6",
|
35
|
+
"_from": "walker@~1.0.5"
|
36
|
+
}
|
@@ -0,0 +1,52 @@
|
|
1
|
+
walker [![Build Status](https://secure.travis-ci.org/daaku/nodejs-walker.png)](http://travis-ci.org/daaku/nodejs-walker)
|
2
|
+
======
|
3
|
+
|
4
|
+
A nodejs directory walker. Broadcasts events for various file types as well as
|
5
|
+
a generic "entry" event for all types and provides the ability to prune
|
6
|
+
directory trees. This shows the entire API; everything is optional:
|
7
|
+
|
8
|
+
```javascript
|
9
|
+
Walker('/etc/')
|
10
|
+
.filterDir(function(dir, stat) {
|
11
|
+
if (dir === '/etc/pam.d') {
|
12
|
+
console.warn('Skipping /etc/pam.d and children')
|
13
|
+
return false
|
14
|
+
}
|
15
|
+
return true
|
16
|
+
})
|
17
|
+
.on('entry', function(entry, stat) {
|
18
|
+
console.log('Got entry: ' + entry)
|
19
|
+
})
|
20
|
+
.on('dir', function(dir, stat) {
|
21
|
+
console.log('Got directory: ' + dir)
|
22
|
+
})
|
23
|
+
.on('file', function(file, stat) {
|
24
|
+
console.log('Got file: ' + file)
|
25
|
+
})
|
26
|
+
.on('symlink', function(symlink, stat) {
|
27
|
+
console.log('Got symlink: ' + symlink)
|
28
|
+
})
|
29
|
+
.on('blockDevice', function(blockDevice, stat) {
|
30
|
+
console.log('Got blockDevice: ' + blockDevice)
|
31
|
+
})
|
32
|
+
.on('fifo', function(fifo, stat) {
|
33
|
+
console.log('Got fifo: ' + fifo)
|
34
|
+
})
|
35
|
+
.on('socket', function(socket, stat) {
|
36
|
+
console.log('Got socket: ' + socket)
|
37
|
+
})
|
38
|
+
.on('characterDevice', function(characterDevice, stat) {
|
39
|
+
console.log('Got characterDevice: ' + characterDevice)
|
40
|
+
})
|
41
|
+
.on('error', function(er, entry, stat) {
|
42
|
+
console.log('Got error ' + er + ' on entry ' + entry)
|
43
|
+
})
|
44
|
+
.on('end', function() {
|
45
|
+
console.log('All files traversed.')
|
46
|
+
})
|
47
|
+
```
|
48
|
+
|
49
|
+
You specify a root directory to walk and optionally specify a function to prune
|
50
|
+
sub-directory trees via the `filterDir` function. The Walker exposes a number
|
51
|
+
of events, broadcasting various file type events a generic error event and
|
52
|
+
finally the event to signal the end of the process.
|
@@ -0,0 +1,55 @@
|
|
1
|
+
Apache License
|
2
|
+
|
3
|
+
Version 2.0, January 2004
|
4
|
+
|
5
|
+
http://www.apache.org/licenses/
|
6
|
+
|
7
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
8
|
+
|
9
|
+
1. Definitions.
|
10
|
+
|
11
|
+
"License" shall mean the terms and conditions for use, reproduction, and distribution as defined by Sections 1 through 9 of this document.
|
12
|
+
|
13
|
+
"Licensor" shall mean the copyright owner or entity authorized by the copyright owner that is granting the License.
|
14
|
+
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all other entities that control, are controlled by, or are under common control with that entity. For the purposes of this definition, "control" means (i) the power, direct or indirect, to cause the direction or management of such entity, whether by contract or otherwise, or (ii) ownership of fifty percent (50%) or more of the outstanding shares, or (iii) beneficial ownership of such entity.
|
16
|
+
|
17
|
+
"You" (or "Your") shall mean an individual or Legal Entity exercising permissions granted by this License.
|
18
|
+
|
19
|
+
"Source" form shall mean the preferred form for making modifications, including but not limited to software source code, documentation source, and configuration files.
|
20
|
+
|
21
|
+
"Object" form shall mean any form resulting from mechanical transformation or translation of a Source form, including but not limited to compiled object code, generated documentation, and conversions to other media types.
|
22
|
+
|
23
|
+
"Work" shall mean the work of authorship, whether in Source or Object form, made available under the License, as indicated by a copyright notice that is included in or attached to the work (an example is provided in the Appendix below).
|
24
|
+
|
25
|
+
"Derivative Works" shall mean any work, whether in Source or Object form, that is based on (or derived from) the Work and for which the editorial revisions, annotations, elaborations, or other modifications represent, as a whole, an original work of authorship. For the purposes of this License, Derivative Works shall not include works that remain separable from, or merely link (or bind by name) to the interfaces of, the Work and Derivative Works thereof.
|
26
|
+
|
27
|
+
"Contribution" shall mean any work of authorship, including the original version of the Work and any modifications or additions to that Work or Derivative Works thereof, that is intentionally submitted to Licensor for inclusion in the Work by the copyright owner or by an individual or Legal Entity authorized to submit on behalf of the copyright owner. For the purposes of this definition, "submitted" means any form of electronic, verbal, or written communication sent to the Licensor or its representatives, including but not limited to communication on electronic mailing lists, source code control systems, and issue tracking systems that are managed by, or on behalf of, the Licensor for the purpose of discussing and improving the Work, but excluding communication that is conspicuously marked or otherwise designated in writing by the copyright owner as "Not a Contribution."
|
28
|
+
|
29
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity on behalf of whom a Contribution has been received by Licensor and subsequently incorporated within the Work.
|
30
|
+
|
31
|
+
2. Grant of Copyright License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable copyright license to reproduce, prepare Derivative Works of, publicly display, publicly perform, sublicense, and distribute the Work and such Derivative Works in Source or Object form.
|
32
|
+
|
33
|
+
3. Grant of Patent License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable (except as stated in this section) patent license to make, have made, use, offer to sell, sell, import, and otherwise transfer the Work, where such license applies only to those patent claims licensable by such Contributor that are necessarily infringed by their Contribution(s) alone or by combination of their Contribution(s) with the Work to which such Contribution(s) was submitted. If You institute patent litigation against any entity (including a cross-claim or counterclaim in a lawsuit) alleging that the Work or a Contribution incorporated within the Work constitutes direct or contributory patent infringement, then any patent licenses granted to You under this License for that Work shall terminate as of the date such litigation is filed.
|
34
|
+
|
35
|
+
4. Redistribution. You may reproduce and distribute copies of the Work or Derivative Works thereof in any medium, with or without modifications, and in Source or Object form, provided that You meet the following conditions:
|
36
|
+
|
37
|
+
You must give any other recipients of the Work or Derivative Works a copy of this License; and
|
38
|
+
|
39
|
+
You must cause any modified files to carry prominent notices stating that You changed the files; and
|
40
|
+
|
41
|
+
You must retain, in the Source form of any Derivative Works that You distribute, all copyright, patent, trademark, and attribution notices from the Source form of the Work, excluding those notices that do not pertain to any part of the Derivative Works; and
|
42
|
+
|
43
|
+
If the Work includes a "NOTICE" text file as part of its distribution, then any Derivative Works that You distribute must include a readable copy of the attribution notices contained within such NOTICE file, excluding those notices that do not pertain to any part of the Derivative Works, in at least one of the following places: within a NOTICE text file distributed as part of the Derivative Works; within the Source form or documentation, if provided along with the Derivative Works; or, within a display generated by the Derivative Works, if and wherever such third-party notices normally appear. The contents of the NOTICE file are for informational purposes only and do not modify the License. You may add Your own attribution notices within Derivative Works that You distribute, alongside or as an addendum to the NOTICE text from the Work, provided that such additional attribution notices cannot be construed as modifying the License. You may add Your own copyright statement to Your modifications and may provide additional or different license terms and conditions for use, reproduction, or distribution of Your modifications, or for any such Derivative Works as a whole, provided Your use, reproduction, and distribution of the Work otherwise complies with the conditions stated in this License.
|
44
|
+
|
45
|
+
5. Submission of Contributions. Unless You explicitly state otherwise, any Contribution intentionally submitted for inclusion in the Work by You to the Licensor shall be under the terms and conditions of this License, without any additional terms or conditions. Notwithstanding the above, nothing herein shall supersede or modify the terms of any separate license agreement you may have executed with Licensor regarding such Contributions.
|
46
|
+
|
47
|
+
6. Trademarks. This License does not grant permission to use the trade names, trademarks, service marks, or product names of the Licensor, except as required for reasonable and customary use in describing the origin of the Work and reproducing the content of the NOTICE file.
|
48
|
+
|
49
|
+
7. Disclaimer of Warranty. Unless required by applicable law or agreed to in writing, Licensor provides the Work (and each Contributor provides its Contributions) on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied, including, without limitation, any warranties or conditions of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE. You are solely responsible for determining the appropriateness of using or redistributing the Work and assume any risks associated with Your exercise of permissions under this License.
|
50
|
+
|
51
|
+
8. Limitation of Liability. In no event and under no legal theory, whether in tort (including negligence), contract, or otherwise, unless required by applicable law (such as deliberate and grossly negligent acts) or agreed to in writing, shall any Contributor be liable to You for damages, including any direct, indirect, special, incidental, or consequential damages of any character arising as a result of this License or out of the use or inability to use the Work (including but not limited to damages for loss of goodwill, work stoppage, computer failure or malfunction, or any and all other commercial damages or losses), even if such Contributor has been advised of the possibility of such damages.
|
52
|
+
|
53
|
+
9. Accepting Warranty or Additional Liability. While redistributing the Work or Derivative Works thereof, You may choose to offer, and charge a fee for, acceptance of support, warranty, indemnity, or other liability obligations and/or rights consistent with this License. However, in accepting such obligations, You may act only on Your own behalf and on Your sole responsibility, not on behalf of any other Contributor, and only if You agree to indemnify, defend, and hold each Contributor harmless for any liability incurred by, or claims asserted against, such Contributor by reason of your accepting any such warranty or additional liability.
|
54
|
+
|
55
|
+
END OF TERMS AND CONDITIONS
|
@@ -0,0 +1,128 @@
|
|
1
|
+
// Copyright 2010-2011 Mikeal Rogers
|
2
|
+
//
|
3
|
+
// Licensed under the Apache License, Version 2.0 (the "License");
|
4
|
+
// you may not use this file except in compliance with the License.
|
5
|
+
// You may obtain a copy of the License at
|
6
|
+
//
|
7
|
+
// http://www.apache.org/licenses/LICENSE-2.0
|
8
|
+
//
|
9
|
+
// Unless required by applicable law or agreed to in writing, software
|
10
|
+
// distributed under the License is distributed on an "AS IS" BASIS,
|
11
|
+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
12
|
+
// See the License for the specific language governing permissions and
|
13
|
+
// limitations under the License.
|
14
|
+
|
15
|
+
var sys = require('util')
|
16
|
+
, fs = require('fs')
|
17
|
+
, path = require('path')
|
18
|
+
, events = require('events')
|
19
|
+
;
|
20
|
+
|
21
|
+
function walk (dir, options, callback) {
|
22
|
+
if (!callback) {callback = options; options = {}}
|
23
|
+
if (!callback.files) callback.files = {};
|
24
|
+
if (!callback.pending) callback.pending = 0;
|
25
|
+
callback.pending += 1;
|
26
|
+
fs.stat(dir, function (err, stat) {
|
27
|
+
if (err) return callback(err);
|
28
|
+
callback.files[dir] = stat;
|
29
|
+
fs.readdir(dir, function (err, files) {
|
30
|
+
if (err) return callback(err);
|
31
|
+
callback.pending -= 1;
|
32
|
+
files.forEach(function (f, index) {
|
33
|
+
f = path.join(dir, f);
|
34
|
+
callback.pending += 1;
|
35
|
+
fs.stat(f, function (err, stat) {
|
36
|
+
var enoent = false
|
37
|
+
, done = false;
|
38
|
+
|
39
|
+
if (err) {
|
40
|
+
if (err.code !== 'ENOENT') {
|
41
|
+
return callback(err);
|
42
|
+
} else {
|
43
|
+
enoent = true;
|
44
|
+
}
|
45
|
+
}
|
46
|
+
callback.pending -= 1;
|
47
|
+
done = callback.pending === 0;
|
48
|
+
if (!enoent) {
|
49
|
+
if (options.ignoreDotFiles && path.basename(f)[0] === '.') return done && callback(null, callback.files);
|
50
|
+
if (options.filter && !options.filter(f, stat)) return done && callback(null, callback.files);
|
51
|
+
callback.files[f] = stat;
|
52
|
+
if (stat.isDirectory()) walk(f, options, callback);
|
53
|
+
done = callback.pending === 0;
|
54
|
+
if (done) callback(null, callback.files);
|
55
|
+
}
|
56
|
+
})
|
57
|
+
})
|
58
|
+
if (callback.pending === 0) callback(null, callback.files);
|
59
|
+
})
|
60
|
+
if (callback.pending === 0) callback(null, callback.files);
|
61
|
+
})
|
62
|
+
|
63
|
+
}
|
64
|
+
exports.watchTree = function ( root, options, callback ) {
|
65
|
+
if (!callback) {callback = options; options = {}}
|
66
|
+
walk(root, options, function (err, files) {
|
67
|
+
if (err) throw err;
|
68
|
+
var fileWatcher = function (f) {
|
69
|
+
fs.watchFile(f, options, function (c, p) {
|
70
|
+
// Check if anything actually changed in stat
|
71
|
+
if (files[f] && !files[f].isDirectory() && c.nlink !== 0 && files[f].mtime.getTime() == c.mtime.getTime()) return;
|
72
|
+
files[f] = c;
|
73
|
+
if (!files[f].isDirectory()) callback(f, c, p);
|
74
|
+
else {
|
75
|
+
fs.readdir(f, function (err, nfiles) {
|
76
|
+
if (err) return;
|
77
|
+
nfiles.forEach(function (b) {
|
78
|
+
var file = path.join(f, b);
|
79
|
+
if (!files[file] && (options.ignoreDotFiles !== true || b[0] != '.')) {
|
80
|
+
fs.stat(file, function (err, stat) {
|
81
|
+
callback(file, stat, null);
|
82
|
+
files[file] = stat;
|
83
|
+
fileWatcher(file);
|
84
|
+
})
|
85
|
+
}
|
86
|
+
})
|
87
|
+
})
|
88
|
+
}
|
89
|
+
if (c.nlink === 0) {
|
90
|
+
// unwatch removed files.
|
91
|
+
delete files[f]
|
92
|
+
fs.unwatchFile(f);
|
93
|
+
}
|
94
|
+
})
|
95
|
+
}
|
96
|
+
fileWatcher(root);
|
97
|
+
for (var i in files) {
|
98
|
+
fileWatcher(i);
|
99
|
+
}
|
100
|
+
callback(files, null, null);
|
101
|
+
})
|
102
|
+
}
|
103
|
+
|
104
|
+
exports.createMonitor = function (root, options, cb) {
|
105
|
+
if (!cb) {cb = options; options = {}}
|
106
|
+
var monitor = new events.EventEmitter();
|
107
|
+
|
108
|
+
var prevFile = {file: null,action: null,stat: null};
|
109
|
+
exports.watchTree(root, options, function (f, curr, prev) {
|
110
|
+
if (typeof f == "object" && prev == null && curr === null) {
|
111
|
+
monitor.files = f;
|
112
|
+
return cb(monitor);
|
113
|
+
}
|
114
|
+
if (prev === null && (prevFile.file != f || prevFile.action != "created")) {
|
115
|
+
prevFile = { file: f, action: "created", stat: curr };
|
116
|
+
return monitor.emit("created", f, curr);
|
117
|
+
}
|
118
|
+
if (curr.nlink === 0 && (prevFile.file != f || prevFile.action != "removed")) {
|
119
|
+
prevFile = { file: f, action: "removed", stat: curr };
|
120
|
+
return monitor.emit("removed", f, curr);
|
121
|
+
}
|
122
|
+
if (prevFile.file === null || prevFile.stat.mtime.getTime() !== curr.mtime.getTime()) {
|
123
|
+
monitor.emit("changed", f, curr, prev);
|
124
|
+
}
|
125
|
+
})
|
126
|
+
}
|
127
|
+
|
128
|
+
exports.walk = walk;
|