sproutit-narwhal 0.1.106

Sign up to get free protection for your applications and to get access to all the features.
Files changed (291) hide show
  1. data/DISTRIBUTION.yml +15 -0
  2. data/README.md +86 -0
  3. data/Rakefile +349 -0
  4. data/VERSION.yml +7 -0
  5. data/bin/activate +50 -0
  6. data/bin/activate.bash +50 -0
  7. data/bin/activate.cmd +3 -0
  8. data/bin/js +67 -0
  9. data/bin/json +2 -0
  10. data/bin/narwhal +67 -0
  11. data/bin/narwhal.cmd +29 -0
  12. data/bin/sea +45 -0
  13. data/bin/sea.cmd +25 -0
  14. data/bin/tusk +2 -0
  15. data/bin/tusk.cmd +5 -0
  16. data/catalog.json +902 -0
  17. data/docs/available-packages.md +32 -0
  18. data/docs/browser-api-plan.md +290 -0
  19. data/docs/browser-api.md +153 -0
  20. data/docs/download.md +25 -0
  21. data/docs/engines.md +32 -0
  22. data/docs/json-tool.md +121 -0
  23. data/docs/lib/binary.wiki +242 -0
  24. data/docs/lib/file.wiki +325 -0
  25. data/docs/lib/os/popen.md +70 -0
  26. data/docs/modules.md +38 -0
  27. data/docs/narwhal.md +487 -0
  28. data/docs/packages-howto.md +32 -0
  29. data/docs/packages.md +30 -0
  30. data/docs/posts/2009-07-29-hello-0.1.md +19 -0
  31. data/docs/quick-start.md +69 -0
  32. data/docs/sea.md +49 -0
  33. data/engines/browser/lib/binary.js +2 -0
  34. data/engines/browser/lib/reactor.js +21 -0
  35. data/engines/browser/lib/system.js +3 -0
  36. data/engines/default/lib/array.js +164 -0
  37. data/engines/default/lib/binary-engine.js +53 -0
  38. data/engines/default/lib/binary.js +755 -0
  39. data/engines/default/lib/date.js +8 -0
  40. data/engines/default/lib/file-engine.js +119 -0
  41. data/engines/default/lib/function.js +119 -0
  42. data/engines/default/lib/global.js +11 -0
  43. data/engines/default/lib/io-engine.js +26 -0
  44. data/engines/default/lib/json.js +488 -0
  45. data/engines/default/lib/object.js +69 -0
  46. data/engines/default/lib/os-engine.js +3 -0
  47. data/engines/default/lib/reactor.js +12 -0
  48. data/engines/default/lib/string.js +84 -0
  49. data/engines/default/lib/system.js +20 -0
  50. data/engines/default/lib/worker.js +133 -0
  51. data/engines/jsc/README.md +18 -0
  52. data/engines/jsc/bootstrap.js +53 -0
  53. data/engines/jsc/deps/http-parser/LICENSE +77 -0
  54. data/engines/jsc/deps/http-parser/README.md +145 -0
  55. data/engines/jsc/deps/http-parser/http_parser.c +6087 -0
  56. data/engines/jsc/deps/http-parser/http_parser.h +141 -0
  57. data/engines/jsc/deps/http-parser/http_parser.rl +500 -0
  58. data/engines/jsc/deps/http-parser/test.c +858 -0
  59. data/engines/jsc/include/binary-engine.h +11 -0
  60. data/engines/jsc/include/io-engine.h +23 -0
  61. data/engines/jsc/include/narwhal.h +427 -0
  62. data/engines/jsc/lib/file-engine.js +31 -0
  63. data/engines/jsc/lib/http.js +1 -0
  64. data/engines/jsc/lib/io-engine.js +202 -0
  65. data/engines/jsc/lib/os-engine.js +25 -0
  66. data/engines/jsc/lib/system.js +18 -0
  67. data/engines/jsc/lib/zip.js +1 -0
  68. data/engines/jsc/narwhal-jsc.c +273 -0
  69. data/engines/jsc/narwhal.c +29 -0
  70. data/engines/jsc/package.json +8 -0
  71. data/engines/jsc/src/binary-engine.cc +290 -0
  72. data/engines/jsc/src/file-engine.cc +405 -0
  73. data/engines/jsc/src/io-engine.cc +423 -0
  74. data/engines/jsc/src/jack/handler/jill.cc +710 -0
  75. data/engines/jsc/src/os-engine.cc +210 -0
  76. data/engines/rhino/bin/narwhal-rhino +68 -0
  77. data/engines/rhino/bin/narwhal-rhino.cmd +34 -0
  78. data/engines/rhino/bootstrap.js +119 -0
  79. data/engines/rhino/jars/jline.jar +0 -0
  80. data/engines/rhino/jars/jna.jar +0 -0
  81. data/engines/rhino/jars/js.jar +0 -0
  82. data/engines/rhino/lib/binary-engine.js +83 -0
  83. data/engines/rhino/lib/concurrency.js +6 -0
  84. data/engines/rhino/lib/event-queue.js +18 -0
  85. data/engines/rhino/lib/file-engine.js +216 -0
  86. data/engines/rhino/lib/http-client-engine.js +90 -0
  87. data/engines/rhino/lib/http-engine.js +10 -0
  88. data/engines/rhino/lib/io-engine.js +347 -0
  89. data/engines/rhino/lib/md5-engine.js +40 -0
  90. data/engines/rhino/lib/os-engine.js +150 -0
  91. data/engines/rhino/lib/packages-engine.js +71 -0
  92. data/engines/rhino/lib/sandbox-engine.js +70 -0
  93. data/engines/rhino/lib/system.js +38 -0
  94. data/engines/rhino/lib/worker-engine.js +23 -0
  95. data/engines/rhino/lib/zip.js +78 -0
  96. data/engines/rhino/package.json +4 -0
  97. data/engines/secure/lib/file.js +6 -0
  98. data/engines/secure/lib/system.js +6 -0
  99. data/engines/template/bin/narwhal-engine-name +32 -0
  100. data/engines/template/bootstrap.js +40 -0
  101. data/engines/template/lib/file-engine.js +118 -0
  102. data/engines/template/lib/system.js +17 -0
  103. data/examples/browser-deployment-jackconfig.js +35 -0
  104. data/examples/fibonacci-worker.js +35 -0
  105. data/examples/fibonacci.js +19 -0
  106. data/examples/hello +2 -0
  107. data/examples/narwhal +3 -0
  108. data/examples/not-quite-a-quine.js +1 -0
  109. data/extconf.rb +44 -0
  110. data/gem_bin/narwhal +5 -0
  111. data/gem_bin/sea +4 -0
  112. data/gem_bin/tusk +4 -0
  113. data/lib/args.js +849 -0
  114. data/lib/base16.js +16 -0
  115. data/lib/base64.js +120 -0
  116. data/lib/codec/base64.js +8 -0
  117. data/lib/crc32.js +60 -0
  118. data/lib/file-bootstrap.js +187 -0
  119. data/lib/file.js +659 -0
  120. data/lib/hash.js +28 -0
  121. data/lib/hashp.js +65 -0
  122. data/lib/html.js +16 -0
  123. data/lib/http-client.js +134 -0
  124. data/lib/http.js +17 -0
  125. data/lib/io.js +98 -0
  126. data/lib/jsmin.js +315 -0
  127. data/lib/jsonpath.js +89 -0
  128. data/lib/logger.js +55 -0
  129. data/lib/md4.js +146 -0
  130. data/lib/md5.js +164 -0
  131. data/lib/mime.js +166 -0
  132. data/lib/narwhal.js +102 -0
  133. data/lib/narwhal/client.js +261 -0
  134. data/lib/narwhal/compile.js +99 -0
  135. data/lib/narwhal/env.js +140 -0
  136. data/lib/narwhal/inline.js +106 -0
  137. data/lib/narwhal/json.js +324 -0
  138. data/lib/narwhal/json.md +178 -0
  139. data/lib/narwhal/repl.js +96 -0
  140. data/lib/narwhal/server-test.js +6 -0
  141. data/lib/narwhal/server.js +270 -0
  142. data/lib/narwhal/tusk.js +170 -0
  143. data/lib/narwhal/tusk/bin.js +13 -0
  144. data/lib/narwhal/tusk/bundle.js +0 -0
  145. data/lib/narwhal/tusk/catalog.js +22 -0
  146. data/lib/narwhal/tusk/clone.js +66 -0
  147. data/lib/narwhal/tusk/consolidate.js +25 -0
  148. data/lib/narwhal/tusk/create-catalog.js +80 -0
  149. data/lib/narwhal/tusk/engine.js +42 -0
  150. data/lib/narwhal/tusk/freeze.js +0 -0
  151. data/lib/narwhal/tusk/init.js +56 -0
  152. data/lib/narwhal/tusk/install.js +288 -0
  153. data/lib/narwhal/tusk/list.js +20 -0
  154. data/lib/narwhal/tusk/orphans.js +0 -0
  155. data/lib/narwhal/tusk/reheat.js +15 -0
  156. data/lib/narwhal/tusk/remove.js +15 -0
  157. data/lib/narwhal/tusk/search.js +145 -0
  158. data/lib/narwhal/tusk/update.js +21 -0
  159. data/lib/narwhal/tusk/upgrade.js +0 -0
  160. data/lib/os.js +33 -0
  161. data/lib/packages.js +423 -0
  162. data/lib/printf.js +169 -0
  163. data/lib/promise.js +352 -0
  164. data/lib/querystring.js +176 -0
  165. data/lib/ref-send.js +257 -0
  166. data/lib/regexp.js +12 -0
  167. data/lib/sandbox.js +422 -0
  168. data/lib/sha.js +112 -0
  169. data/lib/sha256.js +102 -0
  170. data/lib/struct.js +228 -0
  171. data/lib/term.js +179 -0
  172. data/lib/test/assert.js +95 -0
  173. data/lib/test/equiv.js +188 -0
  174. data/lib/test/jsdump.js +165 -0
  175. data/lib/test/runner.js +129 -0
  176. data/lib/unload.js +13 -0
  177. data/lib/uri.js +378 -0
  178. data/lib/url.js +5 -0
  179. data/lib/utf8.js +64 -0
  180. data/lib/util.js +985 -0
  181. data/lib/uuid.js +89 -0
  182. data/lib/xregexp.js +521 -0
  183. data/local.json.template +1 -0
  184. data/narwhal.gemspec +105 -0
  185. data/narwhal.js +213 -0
  186. data/package.json +26 -0
  187. data/packages/readline/engines/default/lib/readline.js +4 -0
  188. data/packages/readline/engines/rhino/lib/readline.js +6 -0
  189. data/packages/readline/package.json +5 -0
  190. data/sources.json +207 -0
  191. data/tests/all-tests.js +17 -0
  192. data/tests/args.js +31 -0
  193. data/tests/args/domain.js +215 -0
  194. data/tests/args/options.js +36 -0
  195. data/tests/args/shifting.js +92 -0
  196. data/tests/args/validation.js +31 -0
  197. data/tests/base64.js +23 -0
  198. data/tests/commonjs.js +3 -0
  199. data/tests/commonjs/all-tests.js +12 -0
  200. data/tests/commonjs/bytearray-encodings-tests.js +69 -0
  201. data/tests/commonjs/bytearray-tests.js +465 -0
  202. data/tests/commonjs/bytestring-encodings-tests.js +89 -0
  203. data/tests/commonjs/bytestring-tests.js +263 -0
  204. data/tests/commonjs/es5/all-tests.js +3 -0
  205. data/tests/commonjs/es5/bind.js +29 -0
  206. data/tests/commonjs/file-tests.js +315 -0
  207. data/tests/commonjs/file/dirname.js +31 -0
  208. data/tests/commonjs/file/extension.js +45 -0
  209. data/tests/commonjs/file/is-absolute.js +11 -0
  210. data/tests/commonjs/file/iterator.js +101 -0
  211. data/tests/commonjs/file/normal.js +27 -0
  212. data/tests/commonjs/file/path.js +17 -0
  213. data/tests/commonjs/file/relative.js +42 -0
  214. data/tests/commonjs/file/resolve.js +44 -0
  215. data/tests/commonjs/module-tests.js +9 -0
  216. data/tests/commonjs/modules/absolute/b.js +1 -0
  217. data/tests/commonjs/modules/absolute/program.js +5 -0
  218. data/tests/commonjs/modules/absolute/submodule/a.js +3 -0
  219. data/tests/commonjs/modules/absolute/test.js +9 -0
  220. data/tests/commonjs/modules/all-tests.js +47 -0
  221. data/tests/commonjs/modules/config.js +11 -0
  222. data/tests/commonjs/modules/cyclic/a.js +4 -0
  223. data/tests/commonjs/modules/cyclic/b.js +4 -0
  224. data/tests/commonjs/modules/cyclic/program.js +10 -0
  225. data/tests/commonjs/modules/cyclic/test.js +9 -0
  226. data/tests/commonjs/modules/determinism/program.js +3 -0
  227. data/tests/commonjs/modules/determinism/submodule/a.js +8 -0
  228. data/tests/commonjs/modules/determinism/submodule/b.js +2 -0
  229. data/tests/commonjs/modules/determinism/test.js +9 -0
  230. data/tests/commonjs/modules/exactExports/a.js +3 -0
  231. data/tests/commonjs/modules/exactExports/program.js +4 -0
  232. data/tests/commonjs/modules/exactExports/test.js +9 -0
  233. data/tests/commonjs/modules/hasOwnProperty/hasOwnProperty.js +0 -0
  234. data/tests/commonjs/modules/hasOwnProperty/program.js +3 -0
  235. data/tests/commonjs/modules/hasOwnProperty/test.js +9 -0
  236. data/tests/commonjs/modules/hasOwnProperty/toString.js +0 -0
  237. data/tests/commonjs/modules/method/a.js +12 -0
  238. data/tests/commonjs/modules/method/program.js +8 -0
  239. data/tests/commonjs/modules/method/test.js +9 -0
  240. data/tests/commonjs/modules/missing/program.js +8 -0
  241. data/tests/commonjs/modules/missing/test.js +9 -0
  242. data/tests/commonjs/modules/monkeys/a.js +1 -0
  243. data/tests/commonjs/modules/monkeys/program.js +4 -0
  244. data/tests/commonjs/modules/monkeys/test.js +9 -0
  245. data/tests/commonjs/modules/nested/a/b/c/d.js +3 -0
  246. data/tests/commonjs/modules/nested/program.js +3 -0
  247. data/tests/commonjs/modules/nested/test.js +9 -0
  248. data/tests/commonjs/modules/relative/program.js +5 -0
  249. data/tests/commonjs/modules/relative/submodule/a.js +1 -0
  250. data/tests/commonjs/modules/relative/submodule/b.js +2 -0
  251. data/tests/commonjs/modules/relative/test.js +9 -0
  252. data/tests/commonjs/modules/transitive/a.js +1 -0
  253. data/tests/commonjs/modules/transitive/b.js +1 -0
  254. data/tests/commonjs/modules/transitive/c.js +3 -0
  255. data/tests/commonjs/modules/transitive/program.js +3 -0
  256. data/tests/commonjs/modules/transitive/test.js +9 -0
  257. data/tests/file/all-tests.js +61 -0
  258. data/tests/file/fnmatch.js +102 -0
  259. data/tests/file/glob.js +466 -0
  260. data/tests/file/match.js +102 -0
  261. data/tests/global.js +6 -0
  262. data/tests/global/array.js +19 -0
  263. data/tests/hashes.js +94 -0
  264. data/tests/html.js +13 -0
  265. data/tests/io/stringio.js +21 -0
  266. data/tests/os/all-tests.js +4 -0
  267. data/tests/os/popen.js +41 -0
  268. data/tests/os/system.js +22 -0
  269. data/tests/printf.js +123 -0
  270. data/tests/query-string.js +87 -0
  271. data/tests/sandbox/byte-io.js +20 -0
  272. data/tests/sandbox/fileName.js +3 -0
  273. data/tests/sandbox/foo.js +0 -0
  274. data/tests/sandbox/reload.js +79 -0
  275. data/tests/string.js +35 -0
  276. data/tests/uri.js +41 -0
  277. data/tests/util/all-tests.js +79 -0
  278. data/tests/util/array.js +207 -0
  279. data/tests/util/array/is-arguments.js +29 -0
  280. data/tests/util/array/is-array-like.js +29 -0
  281. data/tests/util/case.js +9 -0
  282. data/tests/util/collection.js +104 -0
  283. data/tests/util/eq.js +57 -0
  284. data/tests/util/expand.js +45 -0
  285. data/tests/util/object.js +125 -0
  286. data/tests/util/operator.js +25 -0
  287. data/tests/util/range.js +19 -0
  288. data/tests/util/repr.js +26 -0
  289. data/tests/util/string.js +34 -0
  290. data/tests/util/unique.js +12 -0
  291. metadata +434 -0
data/lib/base16.js ADDED
@@ -0,0 +1,16 @@
1
+
2
+ var util = require('util');
3
+ var binary = require('binary');
4
+ var struct = require('struct');
5
+
6
+ exports.encode = function (n) {
7
+ var length = n.length;
8
+ var result = [];
9
+ var alphabet = struct.alphabet16Lower;
10
+ for (var i = 0; i < length; i++) {
11
+ n[i] = n[i] & 0xFF;
12
+ result.push(alphabet[(n.charCodeAt(i) >>> 4) & 0xF], alphabet[n.charCodeAt(i) & 0xF]);
13
+ }
14
+ return result.join('');
15
+ };
16
+
data/lib/base64.js ADDED
@@ -0,0 +1,120 @@
1
+ /* Copyright (C) 1999 Masanao Izumo <iz@onicos.co.jp>
2
+ * Version: 1.0
3
+ * LastModified: Dec 25 1999
4
+ * This library is free. You can redistribute it and/or modify it.
5
+ */
6
+
7
+ /* modified by Kris Kowal to add support for Binary for Narwhal */
8
+
9
+ var encodeChars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
10
+ var decodeChars = [
11
+ -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
12
+ -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
13
+ -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 62, -1, -1, -1, 63,
14
+ 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, -1, -1, -1, -1, -1, -1,
15
+ -1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14,
16
+ 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, -1, -1, -1, -1, -1,
17
+ -1, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40,
18
+ 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, -1, -1, -1, -1, -1
19
+ ];
20
+
21
+ var binary = require('binary');
22
+
23
+ exports.encode = function (str) {
24
+ var out, i, length;
25
+ var c1, c2, c3;
26
+
27
+ length = len(str);
28
+ i = 0;
29
+ out = [];
30
+ while(i < length) {
31
+ c1 = str.charCodeAt(i++) & 0xff;
32
+ if(i == length)
33
+ {
34
+ out.push(encodeChars.charCodeAt(c1 >> 2));
35
+ out.push(encodeChars.charCodeAt((c1 & 0x3) << 4));
36
+ out.push("=".charCodeAt(0));
37
+ out.push("=".charCodeAt(0));
38
+ break;
39
+ }
40
+ c2 = str.charCodeAt(i++);
41
+ if(i == length)
42
+ {
43
+ out.push(encodeChars.charCodeAt(c1 >> 2));
44
+ out.push(encodeChars.charCodeAt(((c1 & 0x3)<< 4) | ((c2 & 0xF0) >> 4)));
45
+ out.push(encodeChars.charCodeAt((c2 & 0xF) << 2));
46
+ out.push("=".charCodeAt(0));
47
+ break;
48
+ }
49
+ c3 = str.charCodeAt(i++);
50
+ out.push(encodeChars.charCodeAt(c1 >> 2));
51
+ out.push(encodeChars.charCodeAt(((c1 & 0x3)<< 4) | ((c2 & 0xF0) >> 4)));
52
+ out.push(encodeChars.charCodeAt(((c2 & 0xF) << 2) | ((c3 & 0xC0) >>6)));
53
+ out.push(encodeChars.charCodeAt(c3 & 0x3F));
54
+ }
55
+ return binary.ByteString(out).toString('ascii');
56
+ };
57
+
58
+ exports.decode = function (str) {
59
+ var c1, c2, c3, c4;
60
+ var i, length, out;
61
+
62
+ length = len(str);
63
+ i = 0;
64
+ out = [];
65
+ while(i < length) {
66
+ /* c1 */
67
+ do {
68
+ c1 = decodeChars[str.charCodeAt(i++) & 0xff];
69
+ } while(i < length && c1 == -1);
70
+ if(c1 == -1)
71
+ break;
72
+
73
+ /* c2 */
74
+ do {
75
+ c2 = decodeChars[str.charCodeAt(i++) & 0xff];
76
+ } while(i < length && c2 == -1);
77
+ if(c2 == -1)
78
+ break;
79
+
80
+ out.push(String.fromCharCode((c1 << 2) | ((c2 & 0x30) >> 4)));
81
+
82
+ /* c3 */
83
+ do {
84
+ c3 = str.charCodeAt(i++) & 0xff;
85
+ if(c3 == 61)
86
+ return out.join('');
87
+ c3 = decodeChars[c3];
88
+ } while(i < length && c3 == -1);
89
+ if(c3 == -1)
90
+ break;
91
+
92
+ out.push(String.fromCharCode(((c2 & 0xF) << 4) | ((c3 & 0x3C) >> 2)));
93
+
94
+ /* c4 */
95
+ do {
96
+ c4 = str.charCodeAt(i++) & 0xff;
97
+ if(c4 == 61)
98
+ return out.join('');
99
+ c4 = decodeChars[c4];
100
+ } while(i < length && c4 == -1);
101
+
102
+ if(c4 == -1)
103
+ break;
104
+
105
+ out.push(String.fromCharCode(((c3 & 0x03) << 6) | c4));
106
+ }
107
+
108
+ return out.join('');
109
+ };
110
+
111
+ var len = function (object) {
112
+ if (object.length !== undefined) {
113
+ return object.length;
114
+ } else if (object.getLength !== undefined) {
115
+ return object.getLength();
116
+ } else {
117
+ return undefined;
118
+ }
119
+ };
120
+
@@ -0,0 +1,8 @@
1
+ var system = require("system");
2
+ system.log.warn("codec/base64 is deprecated. use base64 directly.");
3
+ var base64 = require("base64");
4
+ for (var name in base64) {
5
+ if (Object.prototype.hasOwnProperty.call(base64, name)) {
6
+ exports[name] = base64[name];
7
+ }
8
+ }
data/lib/crc32.js ADDED
@@ -0,0 +1,60 @@
1
+
2
+ var util = require('./util');
3
+
4
+ /*** polynomials
5
+ */
6
+ exports.polynomials = {
7
+ 'ieee802_3': 0xEDB88320,
8
+ 'castagnoli': 0x82F63B78,
9
+ 'kooperman': 0xEB31D82E
10
+ };
11
+
12
+ /*** Table
13
+ */
14
+ exports.Table = function (polynomial) {
15
+ var term, table = [];
16
+ for (var i = 0; i < 256; i++) {
17
+ term = i;
18
+ for (var j = 0; j < 8; j++) {
19
+ if (term & 1)
20
+ term = (term >>> 1) ^ polynomial;
21
+ else
22
+ term = term >>> 1;
23
+ }
24
+ table[i] = term;
25
+ }
26
+ return table;
27
+ };
28
+
29
+ /*** table
30
+ */
31
+ exports.table = exports.Table(exports.polynomials.ieee802_3);
32
+
33
+ /*** hash
34
+ returns the crc32 hash for a string as an integer.
35
+ */
36
+ exports.hash = function (bin, table) {
37
+ if (util.no(table))
38
+ table = exports.table;
39
+ var crc = 0xFFFFFFFF;
40
+ for (var i = 0; i < bin.length; i ++) {
41
+ var x = bin.charCodeAt(i);
42
+ if (x & ~0xFF)
43
+ throw new Error(
44
+ "crc32 can only encode strings of bytes. " +
45
+ "Consider using .toByteString(charset)"
46
+ );
47
+ crc = (crc >>> 8) ^ table[x ^ (crc & 0xFF)];
48
+ }
49
+ return ~crc;
50
+ };
51
+
52
+ /*
53
+
54
+ References
55
+ ==========
56
+
57
+ http://www.webtoolkit.info/
58
+ Javascript crc32
59
+
60
+ */
@@ -0,0 +1,187 @@
1
+
2
+ // NOTE: this file is used is the bootstrapping process,
3
+ // so any "requires" must be accounted for in narwhal.js
4
+
5
+ // use the "file" module as the exports object.
6
+ var exports = require("file");
7
+ var system = require("system");
8
+
9
+ /* path manipulation, needed by the sandbox module in the
10
+ * bootstrapping process before "require" is ready for use */
11
+
12
+ if (/\bwindows\b/i.test(system.os)) {
13
+ exports.ROOT = "\\";
14
+ exports.SEPARATOR = "\\";
15
+ exports.ALT_SEPARATOR = "/";
16
+ } else {
17
+ exports.ROOT = "/";
18
+ exports.SEPARATOR = "/";
19
+ exports.ALT_SEPARATOR = undefined;
20
+ }
21
+
22
+ // we need to make sure the separator regex is always in sync with the separators.
23
+ // this caches the generated regex and rebuild if either separator changes.
24
+ exports.SEPARATORS_RE = function() {
25
+ if (
26
+ separatorCached !== exports.SEPARATOR ||
27
+ altSeparatorCached !== exports.ALT_SEPARATOR
28
+ ) {
29
+ separatorCached = exports.SEPARATOR;
30
+ altSeparatorCached = exports.ALT_SEPARATOR;
31
+ separatorReCached = new RegExp("[" +
32
+ (separatorCached || '').replace(/[-[\]{}()*+?.\\^$|,#\s]/g, "\\$&") +
33
+ (altSeparatorCached || '').replace(/[-[\]{}()*+?.\\^$|,#\s]/g, "\\$&") +
34
+ "]", "g");
35
+ }
36
+ return separatorReCached;
37
+ }
38
+ var separatorCached, altSeparatorCached, separatorReCached;
39
+
40
+ exports.join = function () {
41
+ // special case for root, helps glob
42
+ if (arguments.length == 1 && arguments[0] == "")
43
+ return exports.SEPARATOR; // [""] -> "/"
44
+ // ["", ""] -> "/",
45
+ // ["", "a"] -> "/a"
46
+ // ["a"] -> "a"
47
+ return exports.normal(Array.prototype.join.call(arguments, exports.SEPARATOR));
48
+ };
49
+
50
+ exports.split = function (path) {
51
+ var parts;
52
+ try {
53
+ parts = String(path).split(exports.SEPARATORS_RE());
54
+ } catch (exception) {
55
+ throw new Error("Cannot split " + (typeof path) + ', "' + path + '"');
56
+ }
57
+ // this special case helps isAbsolute
58
+ // distinguish an empty path from an absolute path
59
+ // "" -> [] NOT [""]
60
+ if (parts.length == 1 && parts[0] == "")
61
+ return [];
62
+ // "a" -> ["a"]
63
+ // "/a" -> ["", "a"]
64
+ return parts;
65
+ };
66
+
67
+ exports.resolve = function () {
68
+ var root = "";
69
+ var parents = [];
70
+ var children = [];
71
+ var leaf = "";
72
+ for (var i = 0; i < arguments.length; i++) {
73
+ var path = String(arguments[i]);
74
+ if (path == "")
75
+ continue;
76
+ var parts = path.split(exports.SEPARATORS_RE());
77
+ if (exports.isAbsolute(path)) {
78
+ root = parts.shift() + exports.SEPARATOR;
79
+ parents = [];
80
+ children = [];
81
+ }
82
+ leaf = parts.pop();
83
+ if (leaf == "." || leaf == "..") {
84
+ parts.push(leaf);
85
+ leaf = "";
86
+ }
87
+ for (var j = 0; j < parts.length; j++) {
88
+ var part = parts[j];
89
+ if (part == "." || part == '') {
90
+ } else if (part == "..") {
91
+ if (children.length) {
92
+ children.pop();
93
+ } else {
94
+ if (root) {
95
+ } else {
96
+ parents.push("..");
97
+ }
98
+ }
99
+ } else {
100
+ children.push(part);
101
+ }
102
+ };
103
+ }
104
+ path = parents.concat(children).join(exports.SEPARATOR);
105
+ if (path) leaf = exports.SEPARATOR + leaf;
106
+ return root + path + leaf;
107
+ };
108
+
109
+ exports.normal = function (path) {
110
+ return exports.resolve(path);
111
+ };
112
+
113
+ // XXX not standard
114
+ exports.isAbsolute = function (path) {
115
+ // for absolute paths on any operating system,
116
+ // the first path component always determines
117
+ // whether it is relative or absolute. On Unix,
118
+ // it is empty, so ['', 'foo'].join('/') == '/foo',
119
+ // '/foo'.split('/') == ['', 'foo'].
120
+ var parts = exports.split(path);
121
+ // split('') == []. '' is not absolute.
122
+ // split('/') == ['', ''] is absolute.
123
+ // split(?) == [''] does not occur.
124
+ if (parts.length == 0)
125
+ return false;
126
+ return exports.isDrive(parts[0]);
127
+ };
128
+
129
+ // XXX not standard
130
+ exports.isRelative = function (path) {
131
+ return !exports.isAbsolute(path);
132
+ };
133
+
134
+ // XXX not standard
135
+ exports.isDrive = function (first) {
136
+ if (/\bwindows\b/i.test(system.os)) {
137
+ return /:$/.test(first);
138
+ } else {
139
+ return first == "";
140
+ }
141
+ };
142
+
143
+ /*** root
144
+ returns the Unix root path
145
+ or corresponding Windows drive
146
+ for a given path.
147
+ */
148
+ // XXX not standard
149
+ exports.root = function (path) {
150
+ if (!exports.isAbsolute(path))
151
+ path = require("file").absolute(path);
152
+ var parts = exports.split(path);
153
+ return exports.join(parts[0], '');
154
+ };
155
+
156
+ exports.dirname = function (path) {
157
+ var parts = exports.split(path);
158
+ // XXX needs to be sensitive to the root for
159
+ // Windows compatibility
160
+ parts.pop();
161
+ return exports.join.apply(null, parts) || ".";
162
+ };
163
+
164
+ // XXX the extension argument is not standard
165
+ exports.basename = function (path, extension) {
166
+ var basename = path.split(exports.SEPARATORS_RE()).pop();
167
+ if (extension)
168
+ basename = basename.replace(
169
+ new RegExp(RegExp.escape(extension) + '$'),
170
+ ''
171
+ );
172
+ return basename;
173
+ };
174
+
175
+ exports.extension = function (path) {
176
+ path = exports.basename(path);
177
+ path = path.replace(/^\.*/, '');
178
+ var index = path.lastIndexOf(".");
179
+ return index <= 0 ? "" : path.substring(index);
180
+ };
181
+
182
+ // XXX not standard, deprecated
183
+ exports.extname = function (path) {
184
+ system.log.warn('extname is deprecated in favor of extension');
185
+ return exports.extension(path);
186
+ };
187
+
data/lib/file.js ADDED
@@ -0,0 +1,659 @@
1
+
2
+ // NOTE: portions of the "file" module are implemented in "file-bootstrap" and "file-engine",
3
+ // which are loaded at the bottom of this file to allow for overriding default implementations
4
+
5
+ var io = require('io');
6
+
7
+ /* streams */
8
+
9
+ exports.open = function (path, mode, options) {
10
+
11
+ // it's possible to confuse options and mode,
12
+ // particularly with exports.read(path, options).
13
+ // if a mode string is passed into options,
14
+ // tollerate it.
15
+ if (typeof options == 'string') {
16
+ options = {
17
+ mode: exports.mode(options)
18
+ }
19
+ }
20
+
21
+ // we'll channel all of the arguments through
22
+ // the options object, so create an empty one if none
23
+ // was given.
24
+ if (!options)
25
+ options = {};
26
+
27
+ // if options were specified as the first (and
28
+ // presumably only) argument, use those options,
29
+ // overriding any in the options object if both
30
+ // were provided.
31
+ if (typeof path == 'object') {
32
+ for (var key in path) {
33
+ if (Object.prototype.hasOwnProperty.call(path, key)) {
34
+ options[key] = path[key];
35
+ }
36
+ }
37
+ }
38
+ // if the path is a string, however, write it
39
+ // onto the options object alone.
40
+ if (typeof path == 'string')
41
+ options.path = path;
42
+
43
+ // accumulate the mode from options.mode and
44
+ // the mode arg through successive generations;
45
+ // coerce the options.mode to an object, suitable
46
+ // for updates
47
+ options.mode = exports.mode(options.mode);
48
+ // update options.mode with the mode argument
49
+ if (mode)
50
+ options.mode = exports.mode(mode, options.mode);
51
+
52
+
53
+ // channel all the options back into local variables
54
+ path = options.path;
55
+ mode = options.mode;
56
+ var permissions = options.permissions,
57
+ charset = options.charset,
58
+ buffering = options.buffering,
59
+ recordSeparator = options.recordSeparator,
60
+ fieldSeparator = options.fieldSeparator;
61
+
62
+ // and decompose the mode object
63
+ var read = mode.read,
64
+ write = mode.write,
65
+ append = mode.append,
66
+ update = mode.update,
67
+ binary = mode.binary;
68
+
69
+ // read by default
70
+ if (!(read || write || append))
71
+ read = mode.read = true;
72
+
73
+ // create a byte stream
74
+ var raw = exports.FileIO(path, mode, permissions);
75
+
76
+ // if we're in binary mode, just return the raw
77
+ // stream
78
+ if (binary)
79
+ return raw;
80
+
81
+ // otherwise, go through the courses to return the
82
+ // appropriate reader, writer, or updater, buffered,
83
+ // line buffered, and charset decoded/encoded
84
+ // abstraction
85
+
86
+ var lineBuffering = buffering == 1 || buffering === undefined && raw.isatty && raw.isatty();
87
+ // leaving buffering undefined is a signal to the engine implementation
88
+ // that it ought to pick a good size on its own.
89
+ if (buffering < 0) {
90
+ throw new Error("invalid buffering size");
91
+ }
92
+ if (buffering === 0) {
93
+ throw new Error("can't have unbuffered text IO");
94
+ }
95
+
96
+ return new io.TextIOWrapper(raw, mode, lineBuffering, buffering, charset, options);
97
+
98
+ };
99
+
100
+ /*
101
+ idempotent normalization of acceptable formats for
102
+ file modes.
103
+ */
104
+ exports.mode = function (mode, result) {
105
+ if (!result)
106
+ result = {
107
+ read: false,
108
+ write: false,
109
+ append: false,
110
+ update: false,
111
+ binary: false,
112
+ canonical: false,
113
+ exclusive: false
114
+ };
115
+ else if (typeof result != 'object')
116
+ throw new Error("Mode to update is not a proper mode object: " + result);
117
+
118
+ if (mode === undefined || mode === null) {
119
+ } else if (mode instanceof String || typeof mode == "string") {
120
+ mode.split("").forEach(function (option) {
121
+ if (option == 'r') {
122
+ result.read = true;
123
+ } else if (option == 'w') {
124
+ result.write = true;
125
+ } else if (option == 'a') {
126
+ result.append = true;
127
+ } else if (option == '+') {
128
+ result.update = false;
129
+ } else if (option == 'b') {
130
+ result.binary = true;
131
+ } else if (option == 't') {
132
+ result.binary = false;
133
+ } else if (option == 'c') {
134
+ result.canonical = true;
135
+ } else if (option == 'x') {
136
+ result.exclusive = true;
137
+ } else {
138
+ throw new Error("unrecognized mode option in mode: " + option);
139
+ }
140
+ });
141
+ } else if (mode instanceof Array) {
142
+ mode.forEach(function (option) {
143
+ if (Object.prototype.hasOwnProperty.call(result, option)) {
144
+ result[option] = true;
145
+ } else {
146
+ throw new Error("unrecognized mode option in mode: " + option);
147
+ }
148
+ });
149
+ } else if (mode instanceof Object) {
150
+ for (var option in mode) {
151
+ if (Object.prototype.hasOwnProperty.call(mode, option)) {
152
+ if (Object.prototype.hasOwnProperty.call(result, option)) {
153
+ result[option] = !!mode[option];
154
+ } else {
155
+ throw new Error("unrecognized mode option in mode: " + option);
156
+ }
157
+ }
158
+ }
159
+ } else {
160
+ throw new Error("unrecognized mode: " + mode);
161
+ }
162
+
163
+ return result;
164
+ };
165
+
166
+ /* read, write, &c */
167
+
168
+ exports.read = function (path, options) {
169
+ path = String(path);
170
+ var file = exports.open(path, 'r', options);
171
+ try {
172
+ return file.read();
173
+ } finally {
174
+ file.close();
175
+ }
176
+ };
177
+
178
+ exports.write = function (path, data, options) {
179
+ path = String(path);
180
+ var file = exports.open(path, 'w', options);
181
+ try {
182
+ file.write(data);
183
+ file.flush();
184
+ } finally {
185
+ file.close();
186
+ }
187
+ };
188
+
189
+ exports.copy = function (source, target) {
190
+ source = exports.path(source);
191
+ target = exports.path(target);
192
+ source.open("rb").copy(target.open("wb")).close();
193
+ };
194
+
195
+ exports.list = function (path) {
196
+ return exports.listImpl(String(path || '') || ".");
197
+ };
198
+
199
+ exports.listTree = function (path) {
200
+ path = String(path || '');
201
+ if (!path)
202
+ path = ".";
203
+ var paths = [""];
204
+ exports.list(path).forEach(function (child) {
205
+ var fullPath = exports.join(path, child);
206
+ if (exports.isDirectory(fullPath)) {
207
+ paths.push.apply(paths, exports.listTree(fullPath).map(function(p) {
208
+ return exports.join(child, p);
209
+ }));
210
+ } else {
211
+ paths.push(child)
212
+ }
213
+ });
214
+ return paths;
215
+ };
216
+
217
+ exports.listDirectoryTree = function (path) {
218
+ path = String(path || '');
219
+ if (!path)
220
+ path = ".";
221
+ var paths = [""];
222
+ exports.list(path).forEach(function (child) {
223
+ var fullPath = exports.join(path, child);
224
+ if (exports.isDirectory(fullPath)) {
225
+ paths.push.apply(paths, exports.listDirectoryTree(fullPath).map(function(p) {
226
+ return exports.join(child, p);
227
+ }));
228
+ }
229
+ });
230
+ return paths;
231
+ };
232
+
233
+ exports.FNM_LEADING_DIR = 1 << 1;
234
+ exports.FNM_PATHNAME = 1 << 2;
235
+ exports.FNM_PERIOD = 1 << 3;
236
+ exports.FNM_NOESCAPE = 1 << 4;
237
+ exports.FNM_CASEFOLD = 1 << 5;
238
+ exports.FNM_DOTMATCH = 1 << 6;
239
+
240
+ var fnmatchFlags = ["FNM_LEADING_DIR","FNM_PATHNAME","FNM_PERIOD","FNM_NOESCAPE","FNM_CASEFOLD","FNM_DOTMATCH"];
241
+
242
+ exports.fnmatch = function (pattern, string, flags) {
243
+ var re = exports.patternToRegExp(pattern, flags);
244
+ //print("PATTERN={"+pattern+"} REGEXP={"+re+"}");
245
+ return re.test(string);
246
+ }
247
+
248
+ exports.patternToRegExp = function (pattern, flags) {
249
+ var options = {};
250
+ if (typeof flags === "number") {
251
+ fnmatchFlags.forEach(function(flagName) {
252
+ options[flagName] = !!(flags & exports[flagName]);
253
+ });
254
+ } else if (flags) {
255
+ options = flags;
256
+ }
257
+
258
+ // FNM_PATHNAME: don't match separators
259
+ var matchAny = options.FNM_PATHNAME ? "[^"+RegExp.escape(exports.SEPARATOR)+"]" : ".";
260
+
261
+ // FNM_NOESCAPE match "\" separately
262
+ var tokenizeRegex = options.FNM_NOESCAPE ?
263
+ /\[[^\]]*\]|{[^}]*}|[^\[{]*/g :
264
+ /\\(.)|\[[^\]]*\]|{[^}]*}|[^\\\[{]*/g;
265
+
266
+ return new RegExp(
267
+ '^' +
268
+ pattern.replace(tokenizeRegex, function (pattern, $1) {
269
+ // if escaping is on, always return the next character escaped
270
+ if (!options.FNM_NOESCAPE && (/^\\/).test(pattern) && $1) {
271
+ return RegExp.escape($1);
272
+ }
273
+ if (/^\[/.test(pattern)) {
274
+ var result = "[";
275
+ pattern = pattern.slice(1, pattern.length - 1);
276
+ // negation
277
+ if (/^[!^]/.test(pattern)) {
278
+ pattern = pattern.slice(1);
279
+ result += "^";
280
+ }
281
+ // swap any range characters that are out of order
282
+ pattern = pattern.replace(/(.)-(.)/, function(match, a, b) {
283
+ return a.charCodeAt(0) > b.charCodeAt(0) ? b + "-" + a : match;
284
+ });
285
+ return result + pattern.split("-").map(RegExp.escape).join("-") + ']';
286
+ }
287
+ if (/^\{/.test(pattern))
288
+ return (
289
+ '(' +
290
+ pattern.slice(1, pattern.length - 1)
291
+ .split(',').map(function (pattern) {
292
+ return RegExp.escape(pattern);
293
+ }).join('|') +
294
+ ')'
295
+ );
296
+ return pattern
297
+ .replace(exports.SEPARATORS_RE(), exports.SEPARATOR)
298
+ .split(new RegExp(
299
+ exports.SEPARATOR + "?" +
300
+ "\\*\\*" +
301
+ exports.SEPARATOR + "?"
302
+ )).map(function (pattern) {
303
+ return pattern.split(exports.SEPARATOR).map(function (pattern) {
304
+ if (pattern == "")
305
+ return "\\.?";
306
+ if (pattern == ".")
307
+ return;
308
+ if (pattern == "...")
309
+ return "(|\\.|\\.\\.(" + exports.SEPARATOR + "\\.\\.)*?)";
310
+ return pattern.split('*').map(function (pattern) {
311
+ return pattern.split('?').map(function (pattern) {
312
+ return RegExp.escape(pattern);
313
+ }).join(matchAny);
314
+ }).join(matchAny + '*');
315
+ }).join(RegExp.escape(exports.SEPARATOR));
316
+ }).join('.*?');
317
+ }) +
318
+ '$',
319
+ options.FNM_CASEFOLD ? "i" : ""
320
+ );
321
+ };
322
+
323
+ exports.copyTree = function(source, target, path) {
324
+ var sourcePath = (source = exports.path(source)).join(path);
325
+ var targetPath = (target = exports.path(target)).join(path);
326
+ if (exports.exists(targetPath))
327
+ throw new Error("file exists: " + targetPath);
328
+ if (exports.isDirectory(sourcePath)) {
329
+ exports.mkdir(targetPath);
330
+ exports.list(sourcePath).forEach(function (name) {
331
+ exports.copyTree(source, target, exports.join(path, name));
332
+ });
333
+ } else {
334
+ exports.copy(sourcePath, targetPath);
335
+ }
336
+ };
337
+
338
+ exports.match = function (path, pattern) {
339
+ return exports.patternToRegExp(pattern).test(path);
340
+ };
341
+
342
+ exports.glob = function (pattern, flags) {
343
+ pattern = String(pattern || '');
344
+ var parts = exports.split(pattern);
345
+ if (exports.isAbsolute(pattern))
346
+ parts.unshift(exports.join(parts.shift(), parts.shift()));
347
+ var paths = ['.'];
348
+
349
+ if (parts[parts.length-1] == "**")
350
+ parts[parts.length-1] = "*";
351
+
352
+ parts.forEach(function (part) {
353
+ if (part == "") {
354
+ } else if (part == "**") {
355
+ paths = globTree(paths);
356
+ } else if (part == "...") {
357
+ paths = globHeredity(paths);
358
+ } else if (/[\\\*\?\[{]/.test(part)) {
359
+ paths = globPattern(paths, part, flags);
360
+ } else {
361
+ paths = paths.map(function (path) {
362
+ if (path)
363
+ return exports.join(path, part);
364
+ return part;
365
+ }).filter(function (path) {
366
+ return exports.exists(path);
367
+ });
368
+ }
369
+
370
+ // uniqueness
371
+ var visited = {};
372
+ paths = paths.filter(function (path) {
373
+ var result = !Object.prototype.hasOwnProperty.call(visited, path);
374
+ visited[path] = true;
375
+ return result;
376
+ });
377
+
378
+ });
379
+
380
+ if (paths[0] === "") paths.shift();
381
+
382
+ return paths;
383
+ };
384
+
385
+ var globTree = function (paths) {
386
+ return Array.prototype.concat.apply(
387
+ [],
388
+ paths.map(function (path) {
389
+ if (!exports.isDirectory(path))
390
+ return [];
391
+ return exports.listDirectoryTree(path).map(function (child) {
392
+ return exports.join(path, child);
393
+ });
394
+ })
395
+ );
396
+ };
397
+
398
+ var globHeredity = function (paths) {
399
+ return Array.prototype.concat.apply(
400
+ [],
401
+ paths.map(function (path) {
402
+ var isRelative = exports.isRelative(path);
403
+ var heredity = [];
404
+ var parts = exports.split(exports.absolute(path));
405
+ if (parts[parts.length - 1] == "")
406
+ parts.pop();
407
+ while (parts.length) {
408
+ heredity.push(exports.join.apply(null, parts));
409
+ parts.pop();
410
+ }
411
+ if (isRelative) {
412
+ heredity = heredity.map(function (path) {
413
+ return exports.relative("", path);
414
+ });
415
+ }
416
+ return heredity;
417
+ })
418
+ );
419
+ };
420
+
421
+ var globPattern = function (paths, pattern, flags) {
422
+ var re = exports.patternToRegExp(pattern, flags);
423
+ // print("PATTERN={"+pattern+"} REGEXP={"+re+"}");
424
+ // use concat to flatten result arrays
425
+ return Array.prototype.concat.apply([], paths.map(function (path) {
426
+ if (!exports.isDirectory(path))
427
+ return [];
428
+ return [/*".", ".."*/].concat(exports.list(path)).filter(function (name) {
429
+ return re.test(name);
430
+ }).map(function (name) {
431
+ if (path)
432
+ return exports.join(path, name);
433
+ return name;
434
+ }).filter(function (path) {
435
+ return exports.exists(path);
436
+ });
437
+ }));
438
+ };
439
+
440
+ exports.globPaths = function (pattern, flags) {
441
+ return exports.glob(pattern, flags).map(function (path) {
442
+ return new exports.Path(path);
443
+ });
444
+ };
445
+
446
+ exports.rmtree = function(path) {
447
+ if (exports.isLink(path)) {
448
+ exports.remove(path);
449
+ } else
450
+ if (exports.isDirectory(path)) {
451
+ exports.list(path).forEach(function (name) {
452
+ exports.rmtree(exports.join(path, name));
453
+ });
454
+ exports.rmdir(path);
455
+ } else {
456
+ exports.remove(path);
457
+ }
458
+ };
459
+
460
+ /* path manipulation */
461
+
462
+ exports.relative = function (source, target) {
463
+ if (!target) {
464
+ target = source;
465
+ source = exports.cwd() + '/';
466
+ }
467
+ source = exports.absolute(source);
468
+ target = exports.absolute(target);
469
+ source = source.split(exports.SEPARATORS_RE());
470
+ target = target.split(exports.SEPARATORS_RE());
471
+ source.pop();
472
+ while (
473
+ source.length &&
474
+ target.length &&
475
+ target[0] == source[0]) {
476
+ source.shift();
477
+ target.shift();
478
+ }
479
+ while (source.length) {
480
+ source.shift();
481
+ target.unshift("..");
482
+ }
483
+ return target.join(exports.SEPARATOR);
484
+ };
485
+
486
+ exports.absolute = function (path) {
487
+ return exports.resolve(exports.join(exports.cwd(), ''), path);
488
+ };
489
+
490
+ /* path wrapper, for chaining */
491
+
492
+ exports.path = function (/*path*/) {
493
+ if (arguments.length == 1 && arguments[0] == "")
494
+ return exports.Path("");
495
+ return exports.Path(exports.join.apply(exports, arguments));
496
+ };
497
+
498
+ var Path = exports.Path = function (path) {
499
+ if (!(this instanceof exports.Path))
500
+ return new exports.Path(path);
501
+ this.toString = function () {
502
+ return path;
503
+ };
504
+ };
505
+
506
+ Path.prototype = new String();
507
+
508
+ Path.prototype.valueOf = function () {
509
+ return this.toString();
510
+ };
511
+
512
+ Path.prototype.join = function () {
513
+ return exports.Path(
514
+ exports.join.apply(
515
+ null,
516
+ [this.toString()].concat(Array.prototype.slice.call(arguments))
517
+ )
518
+ );
519
+ };
520
+
521
+ Path.prototype.resolve = function () {
522
+ return exports.Path(
523
+ exports.resolve.apply(
524
+ null,
525
+ [this.toString()].concat(Array.prototype.slice.call(arguments))
526
+ )
527
+ );
528
+ };
529
+
530
+ Path.prototype.to = function (target) {
531
+ return exports.Path(exports.relative(this.toString(), target));
532
+ };
533
+
534
+ Path.prototype.from = function (target) {
535
+ return exports.Path(exports.relative(target, this.toString()));
536
+ };
537
+
538
+ Path.prototype.glob = function (pattern, flags) {
539
+ if (!this.isDirectory())
540
+ return [];
541
+ if (this.toString())
542
+ return exports.glob(exports.join(this, pattern), flags).map(function(path) {
543
+ return this.join("").relative(path).toString();
544
+ }, this).filter(function(path) { return !!path });
545
+ return exports.glob(pattern);
546
+ };
547
+
548
+ Path.prototype.globPaths = function (pattern, flags) {
549
+ if (!this.isDirectory())
550
+ return [];
551
+ if (this.toString())
552
+ return exports.glob(exports.join(this, pattern), flags).map(function (path) {
553
+ return this.join("").relative(path);
554
+ //return new exports.Path(path);
555
+ }, this).filter(function(path) { return !!path.toString() });
556
+ return exports.glob(pattern, flags);
557
+ };
558
+
559
+ var pathed = [
560
+ 'absolute',
561
+ 'basename',
562
+ 'canonical',
563
+ 'dirname',
564
+ 'normal',
565
+ 'relative'
566
+ ];
567
+
568
+ for (var i = 0; i < pathed.length; i++) {
569
+ var name = pathed[i];
570
+ Path.prototype[name] = (function (name) {
571
+ return function () {
572
+ return exports.Path(exports[name].apply(
573
+ this,
574
+ [this.toString()].concat(Array.prototype.slice.call(arguments))
575
+ ));
576
+ };
577
+ })(name);
578
+ }
579
+
580
+ var pathIterated = [
581
+ 'list',
582
+ 'listTree'
583
+ ];
584
+
585
+ for (var i = 0; i < pathIterated.length; i++) {
586
+ var name = pathIterated[i];
587
+
588
+ // create the module-scope variant
589
+ exports[name + 'Paths'] = (function (name) {
590
+ return function () {
591
+ return exports[name].apply(exports, arguments).map(function (path) {
592
+ return new exports.Path(path);
593
+ });
594
+ };
595
+ })(name);
596
+
597
+ // create the Path object variant
598
+ Path.prototype[name + 'Paths'] = (function (name) {
599
+ return function () {
600
+ var self = this;
601
+ return exports[name](this).map(function (path) {
602
+ return self.join(path);
603
+ });
604
+ };
605
+ })(name);
606
+ }
607
+
608
+ var nonPathed = [
609
+ 'chmod',
610
+ 'chown',
611
+ 'copy',
612
+ 'exists',
613
+ 'extension',
614
+ 'isDirectory',
615
+ 'isFile',
616
+ 'isLink',
617
+ 'isReadable',
618
+ 'isWritable',
619
+ 'link',
620
+ 'linkExists',
621
+ 'list',
622
+ 'listTree',
623
+ 'mkdir',
624
+ 'mkdirs',
625
+ 'move',
626
+ 'mtime',
627
+ 'open',
628
+ 'read',
629
+ 'remove',
630
+ 'rename',
631
+ 'rmdir',
632
+ 'rmtree',
633
+ 'size',
634
+ 'split',
635
+ 'stat',
636
+ 'symlink',
637
+ 'touch',
638
+ 'write'
639
+ ];
640
+
641
+ for (var i = 0; i < nonPathed.length; i++) {
642
+ var name = nonPathed[i];
643
+ Path.prototype[name] = (function (name) {
644
+ return function () {
645
+ var result = exports[name].apply(
646
+ this,
647
+ [this.toString()].concat(Array.prototype.slice.call(arguments))
648
+ );
649
+ if (result === undefined)
650
+ result = this;
651
+ return result;
652
+ };
653
+ })(name);
654
+ }
655
+
656
+ // load "file-bootstrap" and "file-engine", which in turn load "file" and modify it's module object.
657
+ // "engine" gets priority so it's loaded last.
658
+ require("file-bootstrap");
659
+ require("file-engine");