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
@@ -0,0 +1,288 @@
1
+
2
+ var tusk = require("../tusk");
3
+ var util = require("util");
4
+ var args = require("args");
5
+ var fs = require("file");
6
+ var json = require("json");
7
+ var http = require("http");
8
+ var zip = require("zip");
9
+ var packages = require("packages");
10
+
11
+ var parser = exports.parser = new args.Parser();
12
+
13
+ parser.help('downloads and installs a package and its dependencies');
14
+
15
+ parser.args('package');
16
+
17
+ parser.option('-f', '--force', 'force')
18
+ .bool()
19
+ .help('causes packages to be installed in the project packages directory regardless of whether they are installed elsewhere');
20
+ /*
21
+ parser.option('-l', '--lean', 'lean')
22
+ .bool()
23
+ .help('causes only the essential components of the library to be installed.');
24
+
25
+ parser.option('-t', '--test', 'test')
26
+ .bool()
27
+ .help('run tests before installing');
28
+
29
+ parser.option('-d', '--doc', 'doc')
30
+ .bool()
31
+ .help('build documentation');
32
+ */
33
+
34
+ parser.helpful();
35
+
36
+ parser.action(function (options) {
37
+ exports.install.call(this, options, options.args);
38
+ });
39
+
40
+ exports.install = function (options, names) {
41
+
42
+ var localSourcePath = fs.path(fs.cwd());
43
+
44
+ if (!tusk.getCatalogPath().isFile()) {
45
+ if (options.simulate) {
46
+ this.print("Run 'tusk update' or 'tusk create-catalog' to get a catalog.");
47
+ return;
48
+ }
49
+ tusk.update.call(this, options);
50
+ }
51
+
52
+ var parser = this;
53
+ var catalog = tusk.readCatalog();
54
+
55
+ // download a catalog if the current catalog
56
+ // does not have a version label.
57
+ if (!catalog.version) {
58
+ this.print("Run 'tusk update' or 'tusk create-catalog' to get a catalog.");
59
+ this.print("Your catalog version is no longer supported.");
60
+ return;
61
+ }
62
+
63
+ // validate the requested names against those
64
+ // in the catalog of downloadable packages.
65
+ var names = names.map(function (name) {
66
+ var localPath = fs.path(fs.absolute(name).replace(/\/$/, "")); // FIXME: basename/dirname broken with trailing slash
67
+ var localPackagePath = localPath.join("package.json");
68
+ if (localPackagePath.isFile()) {
69
+ var packageData = json.decode(localPackagePath.read({charset: 'utf-8'}));
70
+ var packageName = packageData.name || String(localPath.basename());
71
+
72
+ packageData.location = "file://" + localPath;
73
+ packageData.type = "directory";
74
+
75
+ catalog.packages[packageName] = packageData;
76
+ return packageName;
77
+ } else if (util.has(catalog.packages, name)) {
78
+ // nothing to do.
79
+ return name;
80
+ }
81
+
82
+ parser.print("ERROR: Package not found: " + util.enquote(name));
83
+ return null;
84
+ }).filter(function(name) { return !!name; });
85
+
86
+ // load the notes on user-requested and dependency packages
87
+ // for book keeping.
88
+ var notes = tusk.readNotes();
89
+ names.forEach(function (name) {
90
+ if (!notes[name]) {
91
+ notes[name] = {};
92
+ }
93
+ notes[name].requester = "user";
94
+ });
95
+ tusk.writeNotes(notes);
96
+
97
+ // note broken dependency chains
98
+ var errors = [];
99
+ var dependencies = exports.dependencies(catalog.packages, names, errors);
100
+ if (errors.length) {
101
+ print('The following dependencies could not be found in the catalog:');
102
+ printUl(errors.map(function (ancestry) {
103
+ return ancestry.join(' <- ');
104
+ }));
105
+ print('Please notify the package system maintainers.');
106
+ this.exit();
107
+ }
108
+
109
+ // notify of packages already installed
110
+ var already = exports.already(packages.catalog, names);
111
+ if (already.length) {
112
+ print('The following packages are already installed:');
113
+ printUl(already);
114
+ }
115
+
116
+ // note missing packages
117
+ var missing = exports.missing(packages.catalog, dependencies);
118
+
119
+ // add forced packages back in
120
+ if (options.force) {
121
+ names.forEach(function(name) {
122
+ if (!util.has(missing, name))
123
+ missing.push(name);
124
+ });
125
+ }
126
+
127
+ if (!missing.length) {
128
+ print('No new packages to install.');
129
+ this.exit();
130
+ }
131
+ print('The following packages will be downloaded and installed:');
132
+ printUl(missing);
133
+
134
+ // download missing packages
135
+ var zipsDirectory = tusk.getZipsDirectory();
136
+ zipsDirectory.mkdirs();
137
+
138
+ missing.forEach(function (name) {
139
+ if (/^file:\/\//.test(catalog.packages[name].location)) {
140
+ print('Local package: ' + name);
141
+ return;
142
+ }
143
+ var info = catalog.packages[name];
144
+ print('Downloading: ' + info.location);
145
+ if (options.simulate)
146
+ return;
147
+ var zipFile = zipsDirectory.join(name + '.zip')
148
+ if (options.resume && zipFile.isFile())
149
+ return;
150
+ var targetPath = tusk.getDirectory().join('packages', name);
151
+ var zipData = http.read(info.location, 'b');
152
+ zipFile.write(zipData, 'b');
153
+ });
154
+
155
+ // install missing packages
156
+ missing.forEach(function (name) {
157
+ if (!notes[name])
158
+ notes[name] = {}
159
+ if (!notes[name].files)
160
+ notes[name].files = [];
161
+ if (!notes[name].requester)
162
+ notes[name].requester = "module";
163
+ try {
164
+ var targetPath = tusk.getDirectory().join('packages', name);
165
+ if (targetPath.exists()) {
166
+ if (options.force) {
167
+ targetPath.rmtree();
168
+ } else {
169
+ print("Error: Directory exists: "+targetPath);
170
+ return;
171
+ }
172
+ }
173
+
174
+ var components = catalog.packages[name].location.match(/^file:\/\/(.*)$/);
175
+ if (components) {
176
+ var sourcePath = components[1];
177
+ print('Copying: ' + sourcePath);
178
+ if (options.simulate)
179
+ return;
180
+
181
+ fs.copyTree(sourcePath, targetPath);
182
+
183
+ var files = targetPath.listTree().filter(function(f) { return targetPath.join(f).isFile(); });
184
+ print(" + " + files.join("\n + "));
185
+ notes[name].files.push.apply(notes[name].files.push, files);
186
+ } else {
187
+ var zipFile = zipsDirectory.join(name + '.zip');
188
+ print('Unzipping: ' + zipFile);
189
+ if (options.simulate)
190
+ return;
191
+
192
+ // unzip
193
+ new zip.Unzip(zipFile).forEach(function (entry) {
194
+ if (entry.isDirectory())
195
+ return;
196
+ var parts = fs.split(entry.getName());
197
+ parts.shift(); // name-project-comment ref dirname
198
+ var path = targetPath.join(fs.join.apply(null, parts));
199
+ path.dirname().mkdirs();
200
+ notes[name].files.push(path);
201
+ print(" + " + path);
202
+ path.write(entry.read('b'), 'b');
203
+ });
204
+ }
205
+
206
+ // write package.json if it was not in the
207
+ // archive
208
+ var packageJson = targetPath.join('package.json');
209
+ if (!packageJson.isFile())
210
+ packageJson.write(
211
+ json.encode(catalog.packages[name], null, 4),
212
+ {'charset': 'UTF-8'}
213
+ );
214
+
215
+ // make bins executable and make symlinks
216
+ // in $SEA/bin
217
+ var bin = targetPath.join('bin');
218
+ if (bin.isDirectory())
219
+ bin.list().forEach(function (name) {
220
+ var target = targetPath.join('bin', name);
221
+ target.chmod(0755);
222
+ var sea = tusk.getDirectory().join('bin');
223
+ var source = sea.join(name);
224
+ var relative = sea.to(target);
225
+ if (!source.linkExists()) {
226
+ target.symlink(source);
227
+ }
228
+ });
229
+
230
+ notes[name].finished = true;
231
+ } catch (exception) {
232
+ var packageJsonPath = tusk.getDirectory().join('packages', name, 'package.json');
233
+ if (packageJsonPath.isFile())
234
+ packageJsonPath.remove();
235
+ throw exception;
236
+ } finally {
237
+ tusk.writeNotes(notes);
238
+ /*
239
+ if (zipFile.isFile())
240
+ zipFile.remove();
241
+ */
242
+ }
243
+ });
244
+
245
+ print('Done.');
246
+
247
+ };
248
+
249
+ function printUl(lines) {
250
+ lines.forEach(function (line) {
251
+ print(' * ' + line);
252
+ });
253
+ };
254
+
255
+ exports.dependencies = function (catalog, names, errors) {
256
+ var dependencies = {};
257
+ names.forEach(function (name) {
258
+ scan(catalog, dependencies, name, [], errors);
259
+ });
260
+ return Object.keys(dependencies);
261
+ };
262
+
263
+ var scan = function (catalog, dependencies, name, ancestry, errors) {
264
+ if (util.has(dependencies, name))
265
+ return;
266
+ ancestry = [name].concat(ancestry);
267
+ if (!util.has(catalog, name)) {
268
+ errors.push(ancestry);
269
+ return;
270
+ }
271
+ dependencies[name] = true;
272
+ (catalog[name].dependencies || []).forEach(function (child) {
273
+ scan(catalog, dependencies, child, ancestry, errors);
274
+ });
275
+ };
276
+
277
+ exports.already = function (catalog, names) {
278
+ return names.filter(function (packageName) {
279
+ return util.has(catalog, packageName);
280
+ });
281
+ };
282
+
283
+ exports.missing = function (catalog, names) {
284
+ return names.filter(function (packageName) {
285
+ return !util.has(catalog, packageName);
286
+ });
287
+ };
288
+
@@ -0,0 +1,20 @@
1
+
2
+ var tusk = require("../tusk");
3
+ var util = require("util");
4
+ var args = require("args");
5
+ var packages = require("packages");
6
+
7
+ var parser = exports.parser = new args.Parser();
8
+
9
+ parser.help('lists all installed packages');
10
+
11
+ parser.action(function (options) {
12
+ var self = this;
13
+ Object.keys(packages.catalog).forEach(function (name) {
14
+ self.print(
15
+ name + ' \0magenta(' +
16
+ packages.catalog[name].directory + '\0)'
17
+ );
18
+ });
19
+ });
20
+
File without changes
@@ -0,0 +1,15 @@
1
+
2
+ var tusk = require("../tusk");
3
+ var install = require('./install');
4
+ var util = require("util");
5
+ var args = require("args");
6
+ var packages = require('packages');
7
+ var parser = exports.parser = new args.Parser();
8
+
9
+ parser.help('reconsistutes the exact versions of all dependencies from a frozen project');
10
+
11
+ parser.action(function (options, name) {
12
+ var names = packages.root.dependencies || [];
13
+ install.install.call(this, options, names);
14
+ });
15
+
@@ -0,0 +1,15 @@
1
+
2
+ var tusk = require("../tusk");
3
+ var util = require("util");
4
+ var args = require("args");
5
+ var parser = exports.parser = new args.Parser();
6
+
7
+ parser.help('removes the local copy of package');
8
+
9
+ parser.action(function (options) {
10
+ var names = options.args;
11
+ });
12
+
13
+ exports.remove = function () {
14
+ };
15
+
@@ -0,0 +1,145 @@
1
+
2
+ var tusk = require("../tusk");
3
+ var util = require("util");
4
+ var http = require("http");
5
+ var packages = require("packages");
6
+ var stream = require("term").stream;
7
+
8
+ var Parser = exports.Parser = function () {
9
+ };
10
+
11
+ Parser.prototype.act = function (args, options) {
12
+ this._action(args, options);
13
+ };
14
+
15
+ Parser.prototype._action = function (args, options) {
16
+ var command = args.shift();
17
+ var packages = tusk.readCatalog().packages;
18
+ index(packages);
19
+ var predicate = Or(args);
20
+ var results = util.values(packages).map(function (info) {
21
+ return [predicate(info), info];
22
+ }).filter(function (pair) {
23
+ return pair[0] != 0;
24
+ });
25
+ util.sort(results);
26
+ util.forEachApply(results, function (score, info) {
27
+ stream.print(
28
+ "\0green(" + info.name + "\0)" +
29
+ (info.description ? ": " + info.description : "")
30
+ );
31
+ });
32
+ options.acted = true;
33
+ };
34
+
35
+ var index = function (packages) {
36
+ util.forEachApply(packages, function (name, info) {
37
+ if (!info.name) {
38
+ info.name = name;
39
+ }
40
+ if (!info.fullText) {
41
+ info.fullText = [
42
+ info.name
43
+ ].concat(info.keywords).concat([
44
+ info.description
45
+ ]).join(" ");
46
+ }
47
+ });
48
+ return packages;
49
+ }
50
+
51
+ var Text = function (args) {
52
+ args = args.map(function (arg) {
53
+ return new RegExp(
54
+ "\\b" + RegExp.escape(arg) + "\\b",
55
+ "i"
56
+ );
57
+ });
58
+ return function (info) {
59
+ var accumulator = undefined;
60
+ return Math.min.apply(this, args.map(function (arg) {
61
+ return info.fullText.search(arg) + 1;
62
+ }));
63
+ }
64
+ };
65
+
66
+ var Terms = function (args) {
67
+ for (var length = 0; length < args.length; length++)
68
+ if (args[length] == "--")
69
+ break;
70
+ if (length) {
71
+ if (/^--/.test(args[0])) {
72
+ var pattern = args.shift().match(/^--([^=]+)(?:=(.*))?/).slice(1);
73
+ var key = pattern[0];
74
+ var value = pattern[1];
75
+ if (!!value) {
76
+ args.unshift(value);
77
+ }
78
+ var parts = key.split(".");
79
+ return function (info) {
80
+ parts.forEach(function (part) {
81
+ if (Array.isArray(info)) {
82
+ info = info.map(function (node) {
83
+ if (node)
84
+ return node[part];
85
+ });
86
+ } else if (info) {
87
+ info = info[part];
88
+ }
89
+ });
90
+ var value = args[0];
91
+ if (Array.isArray(info)) {
92
+ return util.has(info, value);
93
+ } else {
94
+ return info == value;
95
+ }
96
+ }
97
+ } else if (/^-/.test(args[0])) {
98
+ throw new Error("Option " + args[0] + " not recognized.");
99
+ } else {
100
+ return Text(args);
101
+ }
102
+ } else {
103
+ return Text(args);
104
+ }
105
+ };
106
+
107
+ // - recursive descent scanner
108
+ // - divide and conquor
109
+
110
+ var BinaryOperator = function (Low, High, _, __) {
111
+ return function Self(args) {
112
+ var length = args.length;
113
+ for (var i = 0; i < length; i++)
114
+ if (args[i] == "--")
115
+ break;
116
+ while (i >= 0) {
117
+ i--;
118
+ var arg = args[i];
119
+ if (arg == _ || arg == __) {
120
+ var left = Self(args.slice(0, i));
121
+ var right = High(args.slice(i + 1));
122
+ return function () {
123
+ return Low(
124
+ left.apply(this, arguments),
125
+ right.apply(this, arguments)
126
+ );
127
+ }
128
+ }
129
+ }
130
+ return High(args);
131
+ }
132
+ }
133
+
134
+ var And = BinaryOperator(function (lhs, rhs) {
135
+ return lhs * rhs;
136
+ }, Terms, '-a', '--and');
137
+
138
+ var Or = BinaryOperator(function (lhs, rhs) {
139
+ return lhs || rhs ? lhs + rhs : 0;
140
+ }, And, '-o', '--or');
141
+
142
+ Parser.prototype._help = "{keyword}, --and, --or, --{key} {value}";
143
+
144
+ exports.parser = new Parser();
145
+