traceur-rb 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +15 -0
- data/.gitignore +22 -0
- data/.rspec +1 -0
- data/.ruby-gemset +1 -0
- data/.ruby-version +1 -0
- data/Gemfile +4 -0
- data/Guardfile +8 -0
- data/LICENSE.txt +22 -0
- data/README.md +87 -0
- data/Rakefile +2 -0
- data/lib/js/compile.js +31 -0
- data/lib/traceur-rb.rb +1 -0
- data/lib/traceur.rb +43 -0
- data/lib/traceur/compilation_options.rb +65 -0
- data/lib/traceur/compiler.rb +33 -0
- data/lib/traceur/configuration.rb +47 -0
- data/lib/traceur/node.rb +26 -0
- data/lib/traceur/node/command_result.rb +28 -0
- data/lib/traceur/node/runner.rb +40 -0
- data/lib/traceur/version.rb +3 -0
- data/spec/examples/classes.js +12 -0
- data/spec/integration/examples_spec.rb +28 -0
- data/spec/spec_helper.rb +1 -0
- data/spec/traceur/compilation_options_spec.rb +31 -0
- data/spec/traceur/configuration_spec.rb +54 -0
- data/spec/traceur/node_spec.rb +15 -0
- data/traceur-rb.gemspec +25 -0
- data/vendor/node_modules/.bin/traceur +3 -0
- data/vendor/node_modules/traceur/README.md +40 -0
- data/vendor/node_modules/traceur/bin/traceur-runtime.js +2101 -0
- data/vendor/node_modules/traceur/bin/traceur.js +23034 -0
- data/vendor/node_modules/traceur/node_modules/.bin/semver +125 -0
- data/vendor/node_modules/traceur/node_modules/commander/Readme.md +208 -0
- data/vendor/node_modules/traceur/node_modules/commander/index.js +852 -0
- data/vendor/node_modules/traceur/node_modules/commander/package.json +40 -0
- data/vendor/node_modules/traceur/node_modules/q-io/.npmignore +1 -0
- data/vendor/node_modules/traceur/node_modules/q-io/.travis.yml +3 -0
- data/vendor/node_modules/traceur/node_modules/q-io/CHANGES.md +122 -0
- data/vendor/node_modules/traceur/node_modules/q-io/LICENSE +19 -0
- data/vendor/node_modules/traceur/node_modules/q-io/README.md +928 -0
- data/vendor/node_modules/traceur/node_modules/q-io/buffer-stream.js +59 -0
- data/vendor/node_modules/traceur/node_modules/q-io/coverage-report.js +44 -0
- data/vendor/node_modules/traceur/node_modules/q-io/deprecate.js +51 -0
- data/vendor/node_modules/traceur/node_modules/q-io/fs-boot.js +307 -0
- data/vendor/node_modules/traceur/node_modules/q-io/fs-common.js +499 -0
- data/vendor/node_modules/traceur/node_modules/q-io/fs-mock.js +547 -0
- data/vendor/node_modules/traceur/node_modules/q-io/fs-root.js +105 -0
- data/vendor/node_modules/traceur/node_modules/q-io/fs.js +355 -0
- data/vendor/node_modules/traceur/node_modules/q-io/fs2http.js +65 -0
- data/vendor/node_modules/traceur/node_modules/q-io/http-apps.js +152 -0
- data/vendor/node_modules/traceur/node_modules/q-io/http-apps/chain.js +24 -0
- data/vendor/node_modules/traceur/node_modules/q-io/http-apps/content.js +93 -0
- data/vendor/node_modules/traceur/node_modules/q-io/http-apps/cookie.js +154 -0
- data/vendor/node_modules/traceur/node_modules/q-io/http-apps/decorators.js +178 -0
- data/vendor/node_modules/traceur/node_modules/q-io/http-apps/fs.js +417 -0
- data/vendor/node_modules/traceur/node_modules/q-io/http-apps/html.js +58 -0
- data/vendor/node_modules/traceur/node_modules/q-io/http-apps/json.js +78 -0
- data/vendor/node_modules/traceur/node_modules/q-io/http-apps/negotiate.js +120 -0
- data/vendor/node_modules/traceur/node_modules/q-io/http-apps/proxy.js +27 -0
- data/vendor/node_modules/traceur/node_modules/q-io/http-apps/redirect.js +209 -0
- data/vendor/node_modules/traceur/node_modules/q-io/http-apps/route.js +125 -0
- data/vendor/node_modules/traceur/node_modules/q-io/http-apps/status.js +175 -0
- data/vendor/node_modules/traceur/node_modules/q-io/http-cookie.js +75 -0
- data/vendor/node_modules/traceur/node_modules/q-io/http.js +378 -0
- data/vendor/node_modules/traceur/node_modules/q-io/node_modules/collections/.npmignore +11 -0
- data/vendor/node_modules/traceur/node_modules/q-io/node_modules/collections/.travis.yml +4 -0
- data/vendor/node_modules/traceur/node_modules/q-io/node_modules/collections/CHANGES.md +78 -0
- data/vendor/node_modules/traceur/node_modules/q-io/node_modules/collections/LICENSE.md +21 -0
- data/vendor/node_modules/traceur/node_modules/q-io/node_modules/collections/README.md +1285 -0
- data/vendor/node_modules/traceur/node_modules/q-io/node_modules/collections/collections.js +22 -0
- data/vendor/node_modules/traceur/node_modules/q-io/node_modules/collections/dict.js +142 -0
- data/vendor/node_modules/traceur/node_modules/q-io/node_modules/collections/fast-map.js +57 -0
- data/vendor/node_modules/traceur/node_modules/q-io/node_modules/collections/fast-set.js +183 -0
- data/vendor/node_modules/traceur/node_modules/q-io/node_modules/collections/generic-collection.js +261 -0
- data/vendor/node_modules/traceur/node_modules/q-io/node_modules/collections/generic-map.js +186 -0
- data/vendor/node_modules/traceur/node_modules/q-io/node_modules/collections/generic-order.js +55 -0
- data/vendor/node_modules/traceur/node_modules/q-io/node_modules/collections/generic-set.js +59 -0
- data/vendor/node_modules/traceur/node_modules/q-io/node_modules/collections/heap.js +236 -0
- data/vendor/node_modules/traceur/node_modules/q-io/node_modules/collections/iterator.js +371 -0
- data/vendor/node_modules/traceur/node_modules/q-io/node_modules/collections/list.js +435 -0
- data/vendor/node_modules/traceur/node_modules/q-io/node_modules/collections/listen/array-changes.js +247 -0
- data/vendor/node_modules/traceur/node_modules/q-io/node_modules/collections/listen/map-changes.js +147 -0
- data/vendor/node_modules/traceur/node_modules/q-io/node_modules/collections/listen/property-changes.js +448 -0
- data/vendor/node_modules/traceur/node_modules/q-io/node_modules/collections/listen/range-changes.js +139 -0
- data/vendor/node_modules/traceur/node_modules/q-io/node_modules/collections/lru-map.js +79 -0
- data/vendor/node_modules/traceur/node_modules/q-io/node_modules/collections/lru-set.js +142 -0
- data/vendor/node_modules/traceur/node_modules/q-io/node_modules/collections/map.js +60 -0
- data/vendor/node_modules/traceur/node_modules/q-io/node_modules/collections/multi-map.js +41 -0
- data/vendor/node_modules/traceur/node_modules/q-io/node_modules/collections/node_modules/weak-map/package.json +12 -0
- data/vendor/node_modules/traceur/node_modules/q-io/node_modules/collections/node_modules/weak-map/sync +7 -0
- data/vendor/node_modules/traceur/node_modules/q-io/node_modules/collections/node_modules/weak-map/sync.patch +48 -0
- data/vendor/node_modules/traceur/node_modules/q-io/node_modules/collections/node_modules/weak-map/weak-map.js +590 -0
- data/vendor/node_modules/traceur/node_modules/q-io/node_modules/collections/package.json +49 -0
- data/vendor/node_modules/traceur/node_modules/q-io/node_modules/collections/set.js +173 -0
- data/vendor/node_modules/traceur/node_modules/q-io/node_modules/collections/shim-array.js +274 -0
- data/vendor/node_modules/traceur/node_modules/q-io/node_modules/collections/shim-function.js +59 -0
- data/vendor/node_modules/traceur/node_modules/q-io/node_modules/collections/shim-object.js +538 -0
- data/vendor/node_modules/traceur/node_modules/q-io/node_modules/collections/shim-regexp.js +14 -0
- data/vendor/node_modules/traceur/node_modules/q-io/node_modules/collections/shim.js +6 -0
- data/vendor/node_modules/traceur/node_modules/q-io/node_modules/collections/sorted-array-map.js +49 -0
- data/vendor/node_modules/traceur/node_modules/q-io/node_modules/collections/sorted-array-set.js +51 -0
- data/vendor/node_modules/traceur/node_modules/q-io/node_modules/collections/sorted-array.js +269 -0
- data/vendor/node_modules/traceur/node_modules/q-io/node_modules/collections/sorted-map.js +61 -0
- data/vendor/node_modules/traceur/node_modules/q-io/node_modules/collections/sorted-set.js +736 -0
- data/vendor/node_modules/traceur/node_modules/q-io/node_modules/collections/tree-log.js +40 -0
- data/vendor/node_modules/traceur/node_modules/q-io/node_modules/collections/weak-map.js +1 -0
- data/vendor/node_modules/traceur/node_modules/q-io/node_modules/mime/LICENSE +19 -0
- data/vendor/node_modules/traceur/node_modules/q-io/node_modules/mime/README.md +66 -0
- data/vendor/node_modules/traceur/node_modules/q-io/node_modules/mime/mime.js +114 -0
- data/vendor/node_modules/traceur/node_modules/q-io/node_modules/mime/package.json +35 -0
- data/vendor/node_modules/traceur/node_modules/q-io/node_modules/mime/test.js +84 -0
- data/vendor/node_modules/traceur/node_modules/q-io/node_modules/mime/types/mime.types +1588 -0
- data/vendor/node_modules/traceur/node_modules/q-io/node_modules/mime/types/node.types +77 -0
- data/vendor/node_modules/traceur/node_modules/q-io/node_modules/mimeparse/CHANGES +15 -0
- data/vendor/node_modules/traceur/node_modules/q-io/node_modules/mimeparse/LICENSE +19 -0
- data/vendor/node_modules/traceur/node_modules/q-io/node_modules/mimeparse/README +96 -0
- data/vendor/node_modules/traceur/node_modules/q-io/node_modules/mimeparse/lib/mimeparse.js +166 -0
- data/vendor/node_modules/traceur/node_modules/q-io/node_modules/mimeparse/package.json +43 -0
- data/vendor/node_modules/traceur/node_modules/q-io/node_modules/q/CONTRIBUTING.md +40 -0
- data/vendor/node_modules/traceur/node_modules/q-io/node_modules/q/LICENSE +19 -0
- data/vendor/node_modules/traceur/node_modules/q-io/node_modules/q/README.md +813 -0
- data/vendor/node_modules/traceur/node_modules/q-io/node_modules/q/benchmark/compare-with-callbacks.js +71 -0
- data/vendor/node_modules/traceur/node_modules/q-io/node_modules/q/benchmark/scenarios.js +36 -0
- data/vendor/node_modules/traceur/node_modules/q-io/node_modules/q/package.json +93 -0
- data/vendor/node_modules/traceur/node_modules/q-io/node_modules/q/q.js +1937 -0
- data/vendor/node_modules/traceur/node_modules/q-io/node_modules/q/queue.js +35 -0
- data/vendor/node_modules/traceur/node_modules/q-io/node_modules/qs/.gitmodules +6 -0
- data/vendor/node_modules/traceur/node_modules/q-io/node_modules/qs/History.md +36 -0
- data/vendor/node_modules/traceur/node_modules/q-io/node_modules/qs/Makefile +7 -0
- data/vendor/node_modules/traceur/node_modules/q-io/node_modules/qs/Readme.md +38 -0
- data/vendor/node_modules/traceur/node_modules/q-io/node_modules/qs/benchmark.js +32 -0
- data/vendor/node_modules/traceur/node_modules/q-io/node_modules/qs/examples.js +39 -0
- data/vendor/node_modules/traceur/node_modules/q-io/node_modules/qs/index.js +2 -0
- data/vendor/node_modules/traceur/node_modules/q-io/node_modules/qs/lib/querystring.js +123 -0
- data/vendor/node_modules/traceur/node_modules/q-io/node_modules/qs/package.json +19 -0
- data/vendor/node_modules/traceur/node_modules/q-io/node_modules/qs/support/expresso/.gitmodules +3 -0
- data/vendor/node_modules/traceur/node_modules/q-io/node_modules/qs/support/expresso/.npmignore +3 -0
- data/vendor/node_modules/traceur/node_modules/q-io/node_modules/qs/support/expresso/History.md +128 -0
- data/vendor/node_modules/traceur/node_modules/q-io/node_modules/qs/support/expresso/Makefile +53 -0
- data/vendor/node_modules/traceur/node_modules/q-io/node_modules/qs/support/expresso/Readme.md +61 -0
- data/vendor/node_modules/traceur/node_modules/q-io/node_modules/qs/support/expresso/bin/expresso +856 -0
- data/vendor/node_modules/traceur/node_modules/q-io/node_modules/qs/support/expresso/docs/api.html +1080 -0
- data/vendor/node_modules/traceur/node_modules/q-io/node_modules/qs/support/expresso/docs/index.html +377 -0
- data/vendor/node_modules/traceur/node_modules/q-io/node_modules/qs/support/expresso/docs/index.md +290 -0
- data/vendor/node_modules/traceur/node_modules/q-io/node_modules/qs/support/expresso/docs/layout/foot.html +3 -0
- data/vendor/node_modules/traceur/node_modules/q-io/node_modules/qs/support/expresso/docs/layout/head.html +42 -0
- data/vendor/node_modules/traceur/node_modules/q-io/node_modules/qs/support/expresso/lib/bar.js +4 -0
- data/vendor/node_modules/traceur/node_modules/q-io/node_modules/qs/support/expresso/lib/foo.js +16 -0
- data/vendor/node_modules/traceur/node_modules/q-io/node_modules/qs/support/expresso/package.json +12 -0
- data/vendor/node_modules/traceur/node_modules/q-io/node_modules/qs/support/expresso/test/assert.test.js +91 -0
- data/vendor/node_modules/traceur/node_modules/q-io/node_modules/qs/support/expresso/test/async.test.js +12 -0
- data/vendor/node_modules/traceur/node_modules/q-io/node_modules/qs/support/expresso/test/bar.test.js +13 -0
- data/vendor/node_modules/traceur/node_modules/q-io/node_modules/qs/support/expresso/test/foo.test.js +14 -0
- data/vendor/node_modules/traceur/node_modules/q-io/node_modules/qs/support/expresso/test/http.test.js +146 -0
- data/vendor/node_modules/traceur/node_modules/q-io/node_modules/qs/support/expresso/test/serial/async.test.js +39 -0
- data/vendor/node_modules/traceur/node_modules/q-io/node_modules/qs/support/expresso/test/serial/http.test.js +48 -0
- data/vendor/node_modules/traceur/node_modules/q-io/node_modules/qs/support/should/.gitmodules +3 -0
- data/vendor/node_modules/traceur/node_modules/q-io/node_modules/qs/support/should/History.md +22 -0
- data/vendor/node_modules/traceur/node_modules/q-io/node_modules/qs/support/should/Makefile +6 -0
- data/vendor/node_modules/traceur/node_modules/q-io/node_modules/qs/support/should/Readme.md +248 -0
- data/vendor/node_modules/traceur/node_modules/q-io/node_modules/qs/support/should/examples/runner.js +53 -0
- data/vendor/node_modules/traceur/node_modules/q-io/node_modules/qs/support/should/index.js +2 -0
- data/vendor/node_modules/traceur/node_modules/q-io/node_modules/qs/support/should/lib/eql.js +91 -0
- data/vendor/node_modules/traceur/node_modules/q-io/node_modules/qs/support/should/lib/should.js +548 -0
- data/vendor/node_modules/traceur/node_modules/q-io/node_modules/qs/support/should/package.json +8 -0
- data/vendor/node_modules/traceur/node_modules/q-io/node_modules/qs/support/should/test/should.test.js +358 -0
- data/vendor/node_modules/traceur/node_modules/q-io/node_modules/qs/test/querystring.test.js +133 -0
- data/vendor/node_modules/traceur/node_modules/q-io/node_modules/url2/.npmignore +3 -0
- data/vendor/node_modules/traceur/node_modules/q-io/node_modules/url2/.travis.yml +4 -0
- data/vendor/node_modules/traceur/node_modules/q-io/node_modules/url2/LICENSE.md +20 -0
- data/vendor/node_modules/traceur/node_modules/q-io/node_modules/url2/README.md +33 -0
- data/vendor/node_modules/traceur/node_modules/q-io/node_modules/url2/package.json +37 -0
- data/vendor/node_modules/traceur/node_modules/q-io/node_modules/url2/test/url2-spec.js +125 -0
- data/vendor/node_modules/traceur/node_modules/q-io/node_modules/url2/url2.js +151 -0
- data/vendor/node_modules/traceur/node_modules/q-io/package.json +51 -0
- data/vendor/node_modules/traceur/node_modules/q-io/reader.js +133 -0
- data/vendor/node_modules/traceur/node_modules/q-io/spec/fs/boot-directory-spec.js +47 -0
- data/vendor/node_modules/traceur/node_modules/q-io/spec/fs/contains-spec.js +11 -0
- data/vendor/node_modules/traceur/node_modules/q-io/spec/fs/fixtures/hello.txt +1 -0
- data/vendor/node_modules/traceur/node_modules/q-io/spec/fs/issues/1-spec.js +33 -0
- data/vendor/node_modules/traceur/node_modules/q-io/spec/fs/make-tree-spec.js +92 -0
- data/vendor/node_modules/traceur/node_modules/q-io/spec/fs/mock/append-spec.js +41 -0
- data/vendor/node_modules/traceur/node_modules/q-io/spec/fs/mock/copy-tree-spec.js +57 -0
- data/vendor/node_modules/traceur/node_modules/q-io/spec/fs/mock/fixture/hello.txt +1 -0
- data/vendor/node_modules/traceur/node_modules/q-io/spec/fs/mock/link-spec.js +70 -0
- data/vendor/node_modules/traceur/node_modules/q-io/spec/fs/mock/make-tree-spec.js +109 -0
- data/vendor/node_modules/traceur/node_modules/q-io/spec/fs/mock/merge-spec.js +67 -0
- data/vendor/node_modules/traceur/node_modules/q-io/spec/fs/mock/move-spec.js +219 -0
- data/vendor/node_modules/traceur/node_modules/q-io/spec/fs/mock/object-spec.js +20 -0
- data/vendor/node_modules/traceur/node_modules/q-io/spec/fs/mock/range-spec.js +26 -0
- data/vendor/node_modules/traceur/node_modules/q-io/spec/fs/mock/read-spec.js +40 -0
- data/vendor/node_modules/traceur/node_modules/q-io/spec/fs/mock/remove-directory-spec.js +37 -0
- data/vendor/node_modules/traceur/node_modules/q-io/spec/fs/mock/remove-tree-spec.js +39 -0
- data/vendor/node_modules/traceur/node_modules/q-io/spec/fs/mock/root-spec.js +32 -0
- data/vendor/node_modules/traceur/node_modules/q-io/spec/fs/mock/stat-spec.js +26 -0
- data/vendor/node_modules/traceur/node_modules/q-io/spec/fs/mock/symbolic-link-spec.js +86 -0
- data/vendor/node_modules/traceur/node_modules/q-io/spec/fs/mock/working-directory-spec.js +31 -0
- data/vendor/node_modules/traceur/node_modules/q-io/spec/fs/mock/write-spec.js +73 -0
- data/vendor/node_modules/traceur/node_modules/q-io/spec/fs/range-spec.js +23 -0
- data/vendor/node_modules/traceur/node_modules/q-io/spec/fs/range-spec.txt +1 -0
- data/vendor/node_modules/traceur/node_modules/q-io/spec/fs/read-spec.js +22 -0
- data/vendor/node_modules/traceur/node_modules/q-io/spec/fs/relative-spec.js +25 -0
- data/vendor/node_modules/traceur/node_modules/q-io/spec/fs/reroot-spec.js +45 -0
- data/vendor/node_modules/traceur/node_modules/q-io/spec/fs/write-spec.js +38 -0
- data/vendor/node_modules/traceur/node_modules/q-io/spec/http-apps/cookie-spec.js +52 -0
- data/vendor/node_modules/traceur/node_modules/q-io/spec/http-apps/directory-list-spec.js +86 -0
- data/vendor/node_modules/traceur/node_modules/q-io/spec/http-apps/fixtures/01234.txt +1 -0
- data/vendor/node_modules/traceur/node_modules/q-io/spec/http-apps/fixtures/1234.txt +1 -0
- data/vendor/node_modules/traceur/node_modules/q-io/spec/http-apps/fixtures/5678.txt +0 -0
- data/vendor/node_modules/traceur/node_modules/q-io/spec/http-apps/fixtures/9012/3456.txt +0 -0
- data/vendor/node_modules/traceur/node_modules/q-io/spec/http-apps/hosts-spec.js +49 -0
- data/vendor/node_modules/traceur/node_modules/q-io/spec/http-apps/interpret-range-spec.js +47 -0
- data/vendor/node_modules/traceur/node_modules/q-io/spec/http-apps/partial-range-spec.js +186 -0
- data/vendor/node_modules/traceur/node_modules/q-io/spec/http-apps/proxy-spec.js +82 -0
- data/vendor/node_modules/traceur/node_modules/q-io/spec/http-apps/symbolic-link-spec.js +110 -0
- data/vendor/node_modules/traceur/node_modules/q-io/spec/http/agent-spec.js +96 -0
- data/vendor/node_modules/traceur/node_modules/q-io/spec/http/basic-spec.js +96 -0
- data/vendor/node_modules/traceur/node_modules/q-io/spec/lib/jasmine-promise.js +42 -0
- data/vendor/node_modules/traceur/node_modules/q-io/writer.js +111 -0
- data/vendor/node_modules/traceur/node_modules/semver/.npmignore +1 -0
- data/vendor/node_modules/traceur/node_modules/semver/LICENSE +27 -0
- data/vendor/node_modules/traceur/node_modules/semver/Makefile +24 -0
- data/vendor/node_modules/traceur/node_modules/semver/README.md +158 -0
- data/vendor/node_modules/traceur/node_modules/semver/bin/semver +125 -0
- data/vendor/node_modules/traceur/node_modules/semver/foot.js +6 -0
- data/vendor/node_modules/traceur/node_modules/semver/head.js +2 -0
- data/vendor/node_modules/traceur/node_modules/semver/package.json +31 -0
- data/vendor/node_modules/traceur/node_modules/semver/semver.browser.js +1039 -0
- data/vendor/node_modules/traceur/node_modules/semver/semver.browser.js.gz +0 -0
- data/vendor/node_modules/traceur/node_modules/semver/semver.js +1043 -0
- data/vendor/node_modules/traceur/node_modules/semver/semver.min.js +1 -0
- data/vendor/node_modules/traceur/node_modules/semver/semver.min.js.gz +0 -0
- data/vendor/node_modules/traceur/node_modules/semver/test/amd.js +15 -0
- data/vendor/node_modules/traceur/node_modules/semver/test/gtr.js +173 -0
- data/vendor/node_modules/traceur/node_modules/semver/test/index.js +584 -0
- data/vendor/node_modules/traceur/node_modules/semver/test/ltr.js +174 -0
- data/vendor/node_modules/traceur/node_modules/semver/test/no-module.js +19 -0
- data/vendor/node_modules/traceur/package.json +64 -0
- data/vendor/node_modules/traceur/src/node/System.js +31 -0
- data/vendor/node_modules/traceur/src/node/api.js +124 -0
- data/vendor/node_modules/traceur/src/node/command.js +141 -0
- data/vendor/node_modules/traceur/src/node/compile-single-file.js +69 -0
- data/vendor/node_modules/traceur/src/node/compiler.js +116 -0
- data/vendor/node_modules/traceur/src/node/deferred.js +110 -0
- data/vendor/node_modules/traceur/src/node/file-util.js +73 -0
- data/vendor/node_modules/traceur/src/node/getopt.js +147 -0
- data/vendor/node_modules/traceur/src/node/inline-module.js +149 -0
- data/vendor/node_modules/traceur/src/node/interpreter.js +33 -0
- data/vendor/node_modules/traceur/src/node/nodeLoader.js +41 -0
- data/vendor/node_modules/traceur/src/node/require.js +85 -0
- data/vendor/node_modules/traceur/src/node/to-amd-compiler.js +33 -0
- data/vendor/node_modules/traceur/src/node/to-commonjs-compiler.js +33 -0
- data/vendor/node_modules/traceur/src/node/traceur.js +32 -0
- data/vendor/node_modules/traceur/traceur +3 -0
- metadata +359 -0
@@ -0,0 +1,125 @@
|
|
1
|
+
#!/usr/bin/env node
|
2
|
+
// Standalone semver comparison program.
|
3
|
+
// Exits successfully and prints matching version(s) if
|
4
|
+
// any supplied version is valid and passes all tests.
|
5
|
+
|
6
|
+
var argv = process.argv.slice(2)
|
7
|
+
, versions = []
|
8
|
+
, range = []
|
9
|
+
, gt = []
|
10
|
+
, lt = []
|
11
|
+
, eq = []
|
12
|
+
, inc = null
|
13
|
+
, version = require("../package.json").version
|
14
|
+
, loose = false
|
15
|
+
, semver = require("../semver")
|
16
|
+
, reverse = false
|
17
|
+
|
18
|
+
main()
|
19
|
+
|
20
|
+
function main () {
|
21
|
+
if (!argv.length) return help()
|
22
|
+
while (argv.length) {
|
23
|
+
var a = argv.shift()
|
24
|
+
var i = a.indexOf('=')
|
25
|
+
if (i !== -1) {
|
26
|
+
a = a.slice(0, i)
|
27
|
+
argv.unshift(a.slice(i + 1))
|
28
|
+
}
|
29
|
+
switch (a) {
|
30
|
+
case "-rv": case "-rev": case "--rev": case "--reverse":
|
31
|
+
reverse = true
|
32
|
+
break
|
33
|
+
case "-l": case "--loose":
|
34
|
+
loose = true
|
35
|
+
break
|
36
|
+
case "-v": case "--version":
|
37
|
+
versions.push(argv.shift())
|
38
|
+
break
|
39
|
+
case "-i": case "--inc": case "--increment":
|
40
|
+
switch (argv[0]) {
|
41
|
+
case "major": case "minor": case "patch": case "prerelease":
|
42
|
+
case "premajor": case "preminor": case "prepatch":
|
43
|
+
inc = argv.shift()
|
44
|
+
break
|
45
|
+
default:
|
46
|
+
inc = "patch"
|
47
|
+
break
|
48
|
+
}
|
49
|
+
break
|
50
|
+
case "-r": case "--range":
|
51
|
+
range.push(argv.shift())
|
52
|
+
break
|
53
|
+
case "-h": case "--help": case "-?":
|
54
|
+
return help()
|
55
|
+
default:
|
56
|
+
versions.push(a)
|
57
|
+
break
|
58
|
+
}
|
59
|
+
}
|
60
|
+
|
61
|
+
versions = versions.filter(function (v) {
|
62
|
+
return semver.valid(v, loose)
|
63
|
+
})
|
64
|
+
if (!versions.length) return fail()
|
65
|
+
if (inc && (versions.length !== 1 || range.length))
|
66
|
+
return failInc()
|
67
|
+
|
68
|
+
for (var i = 0, l = range.length; i < l ; i ++) {
|
69
|
+
versions = versions.filter(function (v) {
|
70
|
+
return semver.satisfies(v, range[i], loose)
|
71
|
+
})
|
72
|
+
if (!versions.length) return fail()
|
73
|
+
}
|
74
|
+
return success(versions)
|
75
|
+
}
|
76
|
+
|
77
|
+
function failInc () {
|
78
|
+
console.error("--inc can only be used on a single version with no range")
|
79
|
+
fail()
|
80
|
+
}
|
81
|
+
|
82
|
+
function fail () { process.exit(1) }
|
83
|
+
|
84
|
+
function success () {
|
85
|
+
var compare = reverse ? "rcompare" : "compare"
|
86
|
+
versions.sort(function (a, b) {
|
87
|
+
return semver[compare](a, b, loose)
|
88
|
+
}).map(function (v) {
|
89
|
+
return semver.clean(v, loose)
|
90
|
+
}).map(function (v) {
|
91
|
+
return inc ? semver.inc(v, inc, loose) : v
|
92
|
+
}).forEach(function (v,i,_) { console.log(v) })
|
93
|
+
}
|
94
|
+
|
95
|
+
function help () {
|
96
|
+
console.log(["SemVer " + version
|
97
|
+
,""
|
98
|
+
,"A JavaScript implementation of the http://semver.org/ specification"
|
99
|
+
,"Copyright Isaac Z. Schlueter"
|
100
|
+
,""
|
101
|
+
,"Usage: semver [options] <version> [<version> [...]]"
|
102
|
+
,"Prints valid versions sorted by SemVer precedence"
|
103
|
+
,""
|
104
|
+
,"Options:"
|
105
|
+
,"-r --range <range>"
|
106
|
+
," Print versions that match the specified range."
|
107
|
+
,""
|
108
|
+
,"-i --increment [<level>]"
|
109
|
+
," Increment a version by the specified level. Level can"
|
110
|
+
," be one of: major, minor, patch, or prerelease"
|
111
|
+
," Default level is 'patch'."
|
112
|
+
," Only one version may be specified."
|
113
|
+
,""
|
114
|
+
,"-l --loose"
|
115
|
+
," Interpret versions and ranges loosely"
|
116
|
+
,""
|
117
|
+
,"Program exits successfully if any valid version satisfies"
|
118
|
+
,"all supplied ranges, and prints all satisfying versions."
|
119
|
+
,""
|
120
|
+
,"If no satisfying versions are found, then exits failure."
|
121
|
+
,""
|
122
|
+
,"Versions are printed in ascending order, so supplying"
|
123
|
+
,"multiple versions to the utility will just sort them."
|
124
|
+
].join("\n"))
|
125
|
+
}
|
@@ -0,0 +1,208 @@
|
|
1
|
+
# Commander.js
|
2
|
+
|
3
|
+
The complete solution for [node.js](http://nodejs.org) command-line interfaces, inspired by Ruby's [commander](https://github.com/visionmedia/commander).
|
4
|
+
|
5
|
+
[![Build Status](https://secure.travis-ci.org/visionmedia/commander.js.png)](http://travis-ci.org/visionmedia/commander.js)
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
$ npm install commander
|
10
|
+
|
11
|
+
## Option parsing
|
12
|
+
|
13
|
+
Options with commander are defined with the `.option()` method, also serving as documentation for the options. The example below parses args and options from `process.argv`, leaving remaining args as the `program.args` array which were not consumed by options.
|
14
|
+
|
15
|
+
```js
|
16
|
+
#!/usr/bin/env node
|
17
|
+
|
18
|
+
/**
|
19
|
+
* Module dependencies.
|
20
|
+
*/
|
21
|
+
|
22
|
+
var program = require('commander');
|
23
|
+
|
24
|
+
program
|
25
|
+
.version('0.0.1')
|
26
|
+
.option('-p, --peppers', 'Add peppers')
|
27
|
+
.option('-P, --pineapple', 'Add pineapple')
|
28
|
+
.option('-b, --bbq', 'Add bbq sauce')
|
29
|
+
.option('-c, --cheese [type]', 'Add the specified type of cheese [marble]', 'marble')
|
30
|
+
.parse(process.argv);
|
31
|
+
|
32
|
+
console.log('you ordered a pizza with:');
|
33
|
+
if (program.peppers) console.log(' - peppers');
|
34
|
+
if (program.pineapple) console.log(' - pineapple');
|
35
|
+
if (program.bbq) console.log(' - bbq');
|
36
|
+
console.log(' - %s cheese', program.cheese);
|
37
|
+
```
|
38
|
+
|
39
|
+
Short flags may be passed as a single arg, for example `-abc` is equivalent to `-a -b -c`. Multi-word options such as "--template-engine" are camel-cased, becoming `program.templateEngine` etc.
|
40
|
+
|
41
|
+
## Automated --help
|
42
|
+
|
43
|
+
The help information is auto-generated based on the information commander already knows about your program, so the following `--help` info is for free:
|
44
|
+
|
45
|
+
```
|
46
|
+
$ ./examples/pizza --help
|
47
|
+
|
48
|
+
Usage: pizza [options]
|
49
|
+
|
50
|
+
Options:
|
51
|
+
|
52
|
+
-V, --version output the version number
|
53
|
+
-p, --peppers Add peppers
|
54
|
+
-P, --pineapple Add pineapple
|
55
|
+
-b, --bbq Add bbq sauce
|
56
|
+
-c, --cheese <type> Add the specified type of cheese [marble]
|
57
|
+
-h, --help output usage information
|
58
|
+
|
59
|
+
```
|
60
|
+
|
61
|
+
## Coercion
|
62
|
+
|
63
|
+
```js
|
64
|
+
function range(val) {
|
65
|
+
return val.split('..').map(Number);
|
66
|
+
}
|
67
|
+
|
68
|
+
function list(val) {
|
69
|
+
return val.split(',');
|
70
|
+
}
|
71
|
+
|
72
|
+
function collect(val, memo) {
|
73
|
+
memo.push(val);
|
74
|
+
return memo;
|
75
|
+
}
|
76
|
+
|
77
|
+
function increaseVerbosity(v, total) {
|
78
|
+
return total + 1;
|
79
|
+
}
|
80
|
+
|
81
|
+
program
|
82
|
+
.version('0.0.1')
|
83
|
+
.usage('[options] <file ...>')
|
84
|
+
.option('-i, --integer <n>', 'An integer argument', parseInt)
|
85
|
+
.option('-f, --float <n>', 'A float argument', parseFloat)
|
86
|
+
.option('-r, --range <a>..<b>', 'A range', range)
|
87
|
+
.option('-l, --list <items>', 'A list', list)
|
88
|
+
.option('-o, --optional [value]', 'An optional value')
|
89
|
+
.option('-c, --collect [value]', 'A repeatable value', [])
|
90
|
+
.option('-v, --verbose', 'A value that can be increased', increaseVerbosity, 0)
|
91
|
+
.parse(process.argv);
|
92
|
+
|
93
|
+
console.log(' int: %j', program.integer);
|
94
|
+
console.log(' float: %j', program.float);
|
95
|
+
console.log(' optional: %j', program.optional);
|
96
|
+
program.range = program.range || [];
|
97
|
+
console.log(' range: %j..%j', program.range[0], program.range[1]);
|
98
|
+
console.log(' list: %j', program.list);
|
99
|
+
console.log(' collect: %j', program.collect);
|
100
|
+
console.log(' verbosity: %j', program.verbose);
|
101
|
+
console.log(' args: %j', program.args);
|
102
|
+
```
|
103
|
+
|
104
|
+
## Custom help
|
105
|
+
|
106
|
+
You can display arbitrary `-h, --help` information
|
107
|
+
by listening for "--help". Commander will automatically
|
108
|
+
exit once you are done so that the remainder of your program
|
109
|
+
does not execute causing undesired behaviours, for example
|
110
|
+
in the following executable "stuff" will not output when
|
111
|
+
`--help` is used.
|
112
|
+
|
113
|
+
```js
|
114
|
+
#!/usr/bin/env node
|
115
|
+
|
116
|
+
/**
|
117
|
+
* Module dependencies.
|
118
|
+
*/
|
119
|
+
|
120
|
+
var program = require('../');
|
121
|
+
|
122
|
+
function list(val) {
|
123
|
+
return val.split(',').map(Number);
|
124
|
+
}
|
125
|
+
|
126
|
+
program
|
127
|
+
.version('0.0.1')
|
128
|
+
.option('-f, --foo', 'enable some foo')
|
129
|
+
.option('-b, --bar', 'enable some bar')
|
130
|
+
.option('-B, --baz', 'enable some baz');
|
131
|
+
|
132
|
+
// must be before .parse() since
|
133
|
+
// node's emit() is immediate
|
134
|
+
|
135
|
+
program.on('--help', function(){
|
136
|
+
console.log(' Examples:');
|
137
|
+
console.log('');
|
138
|
+
console.log(' $ custom-help --help');
|
139
|
+
console.log(' $ custom-help -h');
|
140
|
+
console.log('');
|
141
|
+
});
|
142
|
+
|
143
|
+
program.parse(process.argv);
|
144
|
+
|
145
|
+
console.log('stuff');
|
146
|
+
```
|
147
|
+
|
148
|
+
yielding the following help output:
|
149
|
+
|
150
|
+
```
|
151
|
+
|
152
|
+
Usage: custom-help [options]
|
153
|
+
|
154
|
+
Options:
|
155
|
+
|
156
|
+
-h, --help output usage information
|
157
|
+
-V, --version output the version number
|
158
|
+
-f, --foo enable some foo
|
159
|
+
-b, --bar enable some bar
|
160
|
+
-B, --baz enable some baz
|
161
|
+
|
162
|
+
Examples:
|
163
|
+
|
164
|
+
$ custom-help --help
|
165
|
+
$ custom-help -h
|
166
|
+
|
167
|
+
```
|
168
|
+
|
169
|
+
## .outputHelp()
|
170
|
+
|
171
|
+
Output help information without exiting.
|
172
|
+
|
173
|
+
## .help()
|
174
|
+
|
175
|
+
Output help information and exit immediately.
|
176
|
+
|
177
|
+
## Links
|
178
|
+
|
179
|
+
- [API documentation](http://visionmedia.github.com/commander.js/)
|
180
|
+
- [ascii tables](https://github.com/LearnBoost/cli-table)
|
181
|
+
- [progress bars](https://github.com/visionmedia/node-progress)
|
182
|
+
- [more progress bars](https://github.com/substack/node-multimeter)
|
183
|
+
- [examples](https://github.com/visionmedia/commander.js/tree/master/examples)
|
184
|
+
|
185
|
+
## License
|
186
|
+
|
187
|
+
(The MIT License)
|
188
|
+
|
189
|
+
Copyright (c) 2011 TJ Holowaychuk <tj@vision-media.ca>
|
190
|
+
|
191
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
192
|
+
a copy of this software and associated documentation files (the
|
193
|
+
'Software'), to deal in the Software without restriction, including
|
194
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
195
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
196
|
+
permit persons to whom the Software is furnished to do so, subject to
|
197
|
+
the following conditions:
|
198
|
+
|
199
|
+
The above copyright notice and this permission notice shall be
|
200
|
+
included in all copies or substantial portions of the Software.
|
201
|
+
|
202
|
+
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
|
203
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
204
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
205
|
+
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
206
|
+
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
207
|
+
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
208
|
+
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
@@ -0,0 +1,852 @@
|
|
1
|
+
|
2
|
+
/**
|
3
|
+
* Module dependencies.
|
4
|
+
*/
|
5
|
+
|
6
|
+
var EventEmitter = require('events').EventEmitter;
|
7
|
+
var spawn = require('child_process').spawn;
|
8
|
+
var fs = require('fs');
|
9
|
+
var exists = fs.existsSync;
|
10
|
+
var path = require('path');
|
11
|
+
var dirname = path.dirname;
|
12
|
+
var basename = path.basename;
|
13
|
+
|
14
|
+
/**
|
15
|
+
* Expose the root command.
|
16
|
+
*/
|
17
|
+
|
18
|
+
exports = module.exports = new Command;
|
19
|
+
|
20
|
+
/**
|
21
|
+
* Expose `Command`.
|
22
|
+
*/
|
23
|
+
|
24
|
+
exports.Command = Command;
|
25
|
+
|
26
|
+
/**
|
27
|
+
* Expose `Option`.
|
28
|
+
*/
|
29
|
+
|
30
|
+
exports.Option = Option;
|
31
|
+
|
32
|
+
/**
|
33
|
+
* Initialize a new `Option` with the given `flags` and `description`.
|
34
|
+
*
|
35
|
+
* @param {String} flags
|
36
|
+
* @param {String} description
|
37
|
+
* @api public
|
38
|
+
*/
|
39
|
+
|
40
|
+
function Option(flags, description) {
|
41
|
+
this.flags = flags;
|
42
|
+
this.required = ~flags.indexOf('<');
|
43
|
+
this.optional = ~flags.indexOf('[');
|
44
|
+
this.bool = !~flags.indexOf('-no-');
|
45
|
+
flags = flags.split(/[ ,|]+/);
|
46
|
+
if (flags.length > 1 && !/^[[<]/.test(flags[1])) this.short = flags.shift();
|
47
|
+
this.long = flags.shift();
|
48
|
+
this.description = description || '';
|
49
|
+
}
|
50
|
+
|
51
|
+
/**
|
52
|
+
* Return option name.
|
53
|
+
*
|
54
|
+
* @return {String}
|
55
|
+
* @api private
|
56
|
+
*/
|
57
|
+
|
58
|
+
Option.prototype.name = function(){
|
59
|
+
return this.long
|
60
|
+
.replace('--', '')
|
61
|
+
.replace('no-', '');
|
62
|
+
};
|
63
|
+
|
64
|
+
/**
|
65
|
+
* Check if `arg` matches the short or long flag.
|
66
|
+
*
|
67
|
+
* @param {String} arg
|
68
|
+
* @return {Boolean}
|
69
|
+
* @api private
|
70
|
+
*/
|
71
|
+
|
72
|
+
Option.prototype.is = function(arg){
|
73
|
+
return arg == this.short
|
74
|
+
|| arg == this.long;
|
75
|
+
};
|
76
|
+
|
77
|
+
/**
|
78
|
+
* Initialize a new `Command`.
|
79
|
+
*
|
80
|
+
* @param {String} name
|
81
|
+
* @api public
|
82
|
+
*/
|
83
|
+
|
84
|
+
function Command(name) {
|
85
|
+
this.commands = [];
|
86
|
+
this.options = [];
|
87
|
+
this._execs = [];
|
88
|
+
this._args = [];
|
89
|
+
this._name = name;
|
90
|
+
}
|
91
|
+
|
92
|
+
/**
|
93
|
+
* Inherit from `EventEmitter.prototype`.
|
94
|
+
*/
|
95
|
+
|
96
|
+
Command.prototype.__proto__ = EventEmitter.prototype;
|
97
|
+
|
98
|
+
/**
|
99
|
+
* Add command `name`.
|
100
|
+
*
|
101
|
+
* The `.action()` callback is invoked when the
|
102
|
+
* command `name` is specified via __ARGV__,
|
103
|
+
* and the remaining arguments are applied to the
|
104
|
+
* function for access.
|
105
|
+
*
|
106
|
+
* When the `name` is "*" an un-matched command
|
107
|
+
* will be passed as the first arg, followed by
|
108
|
+
* the rest of __ARGV__ remaining.
|
109
|
+
*
|
110
|
+
* Examples:
|
111
|
+
*
|
112
|
+
* program
|
113
|
+
* .version('0.0.1')
|
114
|
+
* .option('-C, --chdir <path>', 'change the working directory')
|
115
|
+
* .option('-c, --config <path>', 'set config path. defaults to ./deploy.conf')
|
116
|
+
* .option('-T, --no-tests', 'ignore test hook')
|
117
|
+
*
|
118
|
+
* program
|
119
|
+
* .command('setup')
|
120
|
+
* .description('run remote setup commands')
|
121
|
+
* .action(function(){
|
122
|
+
* console.log('setup');
|
123
|
+
* });
|
124
|
+
*
|
125
|
+
* program
|
126
|
+
* .command('exec <cmd>')
|
127
|
+
* .description('run the given remote command')
|
128
|
+
* .action(function(cmd){
|
129
|
+
* console.log('exec "%s"', cmd);
|
130
|
+
* });
|
131
|
+
*
|
132
|
+
* program
|
133
|
+
* .command('*')
|
134
|
+
* .description('deploy the given env')
|
135
|
+
* .action(function(env){
|
136
|
+
* console.log('deploying "%s"', env);
|
137
|
+
* });
|
138
|
+
*
|
139
|
+
* program.parse(process.argv);
|
140
|
+
*
|
141
|
+
* @param {String} name
|
142
|
+
* @param {String} [desc]
|
143
|
+
* @return {Command} the new command
|
144
|
+
* @api public
|
145
|
+
*/
|
146
|
+
|
147
|
+
Command.prototype.command = function(name, desc){
|
148
|
+
var args = name.split(/ +/);
|
149
|
+
var cmd = new Command(args.shift());
|
150
|
+
if (desc) cmd.description(desc);
|
151
|
+
if (desc) this.executables = true;
|
152
|
+
if (desc) this._execs[cmd._name] = true;
|
153
|
+
this.commands.push(cmd);
|
154
|
+
cmd.parseExpectedArgs(args);
|
155
|
+
cmd.parent = this;
|
156
|
+
if (desc) return this;
|
157
|
+
return cmd;
|
158
|
+
};
|
159
|
+
|
160
|
+
/**
|
161
|
+
* Add an implicit `help [cmd]` subcommand
|
162
|
+
* which invokes `--help` for the given command.
|
163
|
+
*
|
164
|
+
* @api private
|
165
|
+
*/
|
166
|
+
|
167
|
+
Command.prototype.addImplicitHelpCommand = function() {
|
168
|
+
this.command('help [cmd]', 'display help for [cmd]');
|
169
|
+
};
|
170
|
+
|
171
|
+
/**
|
172
|
+
* Parse expected `args`.
|
173
|
+
*
|
174
|
+
* For example `["[type]"]` becomes `[{ required: false, name: 'type' }]`.
|
175
|
+
*
|
176
|
+
* @param {Array} args
|
177
|
+
* @return {Command} for chaining
|
178
|
+
* @api public
|
179
|
+
*/
|
180
|
+
|
181
|
+
Command.prototype.parseExpectedArgs = function(args){
|
182
|
+
if (!args.length) return;
|
183
|
+
var self = this;
|
184
|
+
args.forEach(function(arg){
|
185
|
+
switch (arg[0]) {
|
186
|
+
case '<':
|
187
|
+
self._args.push({ required: true, name: arg.slice(1, -1) });
|
188
|
+
break;
|
189
|
+
case '[':
|
190
|
+
self._args.push({ required: false, name: arg.slice(1, -1) });
|
191
|
+
break;
|
192
|
+
}
|
193
|
+
});
|
194
|
+
return this;
|
195
|
+
};
|
196
|
+
|
197
|
+
/**
|
198
|
+
* Register callback `fn` for the command.
|
199
|
+
*
|
200
|
+
* Examples:
|
201
|
+
*
|
202
|
+
* program
|
203
|
+
* .command('help')
|
204
|
+
* .description('display verbose help')
|
205
|
+
* .action(function(){
|
206
|
+
* // output help here
|
207
|
+
* });
|
208
|
+
*
|
209
|
+
* @param {Function} fn
|
210
|
+
* @return {Command} for chaining
|
211
|
+
* @api public
|
212
|
+
*/
|
213
|
+
|
214
|
+
Command.prototype.action = function(fn){
|
215
|
+
var self = this;
|
216
|
+
this.parent.on(this._name, function(args, unknown){
|
217
|
+
// Parse any so-far unknown options
|
218
|
+
unknown = unknown || [];
|
219
|
+
var parsed = self.parseOptions(unknown);
|
220
|
+
|
221
|
+
// Output help if necessary
|
222
|
+
outputHelpIfNecessary(self, parsed.unknown);
|
223
|
+
|
224
|
+
// If there are still any unknown options, then we simply
|
225
|
+
// die, unless someone asked for help, in which case we give it
|
226
|
+
// to them, and then we die.
|
227
|
+
if (parsed.unknown.length > 0) {
|
228
|
+
self.unknownOption(parsed.unknown[0]);
|
229
|
+
}
|
230
|
+
|
231
|
+
// Leftover arguments need to be pushed back. Fixes issue #56
|
232
|
+
if (parsed.args.length) args = parsed.args.concat(args);
|
233
|
+
|
234
|
+
self._args.forEach(function(arg, i){
|
235
|
+
if (arg.required && null == args[i]) {
|
236
|
+
self.missingArgument(arg.name);
|
237
|
+
}
|
238
|
+
});
|
239
|
+
|
240
|
+
// Always append ourselves to the end of the arguments,
|
241
|
+
// to make sure we match the number of arguments the user
|
242
|
+
// expects
|
243
|
+
if (self._args.length) {
|
244
|
+
args[self._args.length] = self;
|
245
|
+
} else {
|
246
|
+
args.push(self);
|
247
|
+
}
|
248
|
+
|
249
|
+
fn.apply(this, args);
|
250
|
+
});
|
251
|
+
return this;
|
252
|
+
};
|
253
|
+
|
254
|
+
/**
|
255
|
+
* Define option with `flags`, `description` and optional
|
256
|
+
* coercion `fn`.
|
257
|
+
*
|
258
|
+
* The `flags` string should contain both the short and long flags,
|
259
|
+
* separated by comma, a pipe or space. The following are all valid
|
260
|
+
* all will output this way when `--help` is used.
|
261
|
+
*
|
262
|
+
* "-p, --pepper"
|
263
|
+
* "-p|--pepper"
|
264
|
+
* "-p --pepper"
|
265
|
+
*
|
266
|
+
* Examples:
|
267
|
+
*
|
268
|
+
* // simple boolean defaulting to false
|
269
|
+
* program.option('-p, --pepper', 'add pepper');
|
270
|
+
*
|
271
|
+
* --pepper
|
272
|
+
* program.pepper
|
273
|
+
* // => Boolean
|
274
|
+
*
|
275
|
+
* // simple boolean defaulting to false
|
276
|
+
* program.option('-C, --no-cheese', 'remove cheese');
|
277
|
+
*
|
278
|
+
* program.cheese
|
279
|
+
* // => true
|
280
|
+
*
|
281
|
+
* --no-cheese
|
282
|
+
* program.cheese
|
283
|
+
* // => true
|
284
|
+
*
|
285
|
+
* // required argument
|
286
|
+
* program.option('-C, --chdir <path>', 'change the working directory');
|
287
|
+
*
|
288
|
+
* --chdir /tmp
|
289
|
+
* program.chdir
|
290
|
+
* // => "/tmp"
|
291
|
+
*
|
292
|
+
* // optional argument
|
293
|
+
* program.option('-c, --cheese [type]', 'add cheese [marble]');
|
294
|
+
*
|
295
|
+
* @param {String} flags
|
296
|
+
* @param {String} description
|
297
|
+
* @param {Function|Mixed} fn or default
|
298
|
+
* @param {Mixed} defaultValue
|
299
|
+
* @return {Command} for chaining
|
300
|
+
* @api public
|
301
|
+
*/
|
302
|
+
|
303
|
+
Command.prototype.option = function(flags, description, fn, defaultValue){
|
304
|
+
var self = this
|
305
|
+
, option = new Option(flags, description)
|
306
|
+
, oname = option.name()
|
307
|
+
, name = camelcase(oname);
|
308
|
+
|
309
|
+
// default as 3rd arg
|
310
|
+
if ('function' != typeof fn) defaultValue = fn, fn = null;
|
311
|
+
|
312
|
+
// preassign default value only for --no-*, [optional], or <required>
|
313
|
+
if (false == option.bool || option.optional || option.required) {
|
314
|
+
// when --no-* we make sure default is true
|
315
|
+
if (false == option.bool) defaultValue = true;
|
316
|
+
// preassign only if we have a default
|
317
|
+
if (undefined !== defaultValue) self[name] = defaultValue;
|
318
|
+
}
|
319
|
+
|
320
|
+
// register the option
|
321
|
+
this.options.push(option);
|
322
|
+
|
323
|
+
// when it's passed assign the value
|
324
|
+
// and conditionally invoke the callback
|
325
|
+
this.on(oname, function(val){
|
326
|
+
// coercion
|
327
|
+
if (null !== val && fn) val = fn(val, undefined === self[name] ? defaultValue : self[name]);
|
328
|
+
|
329
|
+
// unassigned or bool
|
330
|
+
if ('boolean' == typeof self[name] || 'undefined' == typeof self[name]) {
|
331
|
+
// if no value, bool true, and we have a default, then use it!
|
332
|
+
if (null == val) {
|
333
|
+
self[name] = option.bool
|
334
|
+
? defaultValue || true
|
335
|
+
: false;
|
336
|
+
} else {
|
337
|
+
self[name] = val;
|
338
|
+
}
|
339
|
+
} else if (null !== val) {
|
340
|
+
// reassign
|
341
|
+
self[name] = val;
|
342
|
+
}
|
343
|
+
});
|
344
|
+
|
345
|
+
return this;
|
346
|
+
};
|
347
|
+
|
348
|
+
/**
|
349
|
+
* Parse `argv`, settings options and invoking commands when defined.
|
350
|
+
*
|
351
|
+
* @param {Array} argv
|
352
|
+
* @return {Command} for chaining
|
353
|
+
* @api public
|
354
|
+
*/
|
355
|
+
|
356
|
+
Command.prototype.parse = function(argv){
|
357
|
+
// implicit help
|
358
|
+
if (this.executables) this.addImplicitHelpCommand();
|
359
|
+
|
360
|
+
// store raw args
|
361
|
+
this.rawArgs = argv;
|
362
|
+
|
363
|
+
// guess name
|
364
|
+
this._name = this._name || basename(argv[1], '.js');
|
365
|
+
|
366
|
+
// process argv
|
367
|
+
var parsed = this.parseOptions(this.normalize(argv.slice(2)));
|
368
|
+
var args = this.args = parsed.args;
|
369
|
+
|
370
|
+
var result = this.parseArgs(this.args, parsed.unknown);
|
371
|
+
|
372
|
+
// executable sub-commands
|
373
|
+
var name = result.args[0];
|
374
|
+
if (this._execs[name]) return this.executeSubCommand(argv, args, parsed.unknown);
|
375
|
+
|
376
|
+
return result;
|
377
|
+
};
|
378
|
+
|
379
|
+
/**
|
380
|
+
* Execute a sub-command executable.
|
381
|
+
*
|
382
|
+
* @param {Array} argv
|
383
|
+
* @param {Array} args
|
384
|
+
* @param {Array} unknown
|
385
|
+
* @api private
|
386
|
+
*/
|
387
|
+
|
388
|
+
Command.prototype.executeSubCommand = function(argv, args, unknown) {
|
389
|
+
args = args.concat(unknown);
|
390
|
+
|
391
|
+
if (!args.length) this.help();
|
392
|
+
if ('help' == args[0] && 1 == args.length) this.help();
|
393
|
+
|
394
|
+
// <cmd> --help
|
395
|
+
if ('help' == args[0]) {
|
396
|
+
args[0] = args[1];
|
397
|
+
args[1] = '--help';
|
398
|
+
}
|
399
|
+
|
400
|
+
// executable
|
401
|
+
var dir = dirname(argv[1]);
|
402
|
+
var bin = basename(argv[1], '.js') + '-' + args[0];
|
403
|
+
|
404
|
+
// check for ./<bin> first
|
405
|
+
var local = path.join(dir, bin);
|
406
|
+
|
407
|
+
// run it
|
408
|
+
args = args.slice(1);
|
409
|
+
args.unshift(local);
|
410
|
+
var proc = spawn('node', args, { stdio: 'inherit', customFds: [0, 1, 2] });
|
411
|
+
proc.on('error', function(err){
|
412
|
+
if (err.code == "ENOENT") {
|
413
|
+
console.error('\n %s(1) does not exist, try --help\n', bin);
|
414
|
+
} else if (err.code == "EACCES") {
|
415
|
+
console.error('\n %s(1) not executable. try chmod or run with root\n', bin);
|
416
|
+
}
|
417
|
+
});
|
418
|
+
|
419
|
+
this.runningCommand = proc;
|
420
|
+
};
|
421
|
+
|
422
|
+
/**
|
423
|
+
* Normalize `args`, splitting joined short flags. For example
|
424
|
+
* the arg "-abc" is equivalent to "-a -b -c".
|
425
|
+
* This also normalizes equal sign and splits "--abc=def" into "--abc def".
|
426
|
+
*
|
427
|
+
* @param {Array} args
|
428
|
+
* @return {Array}
|
429
|
+
* @api private
|
430
|
+
*/
|
431
|
+
|
432
|
+
Command.prototype.normalize = function(args){
|
433
|
+
var ret = []
|
434
|
+
, arg
|
435
|
+
, lastOpt
|
436
|
+
, index;
|
437
|
+
|
438
|
+
for (var i = 0, len = args.length; i < len; ++i) {
|
439
|
+
arg = args[i];
|
440
|
+
i > 0 && (lastOpt = this.optionFor(args[i-1]));
|
441
|
+
|
442
|
+
if (lastOpt && lastOpt.required) {
|
443
|
+
ret.push(arg);
|
444
|
+
} else if (arg.length > 1 && '-' == arg[0] && '-' != arg[1]) {
|
445
|
+
arg.slice(1).split('').forEach(function(c){
|
446
|
+
ret.push('-' + c);
|
447
|
+
});
|
448
|
+
} else if (/^--/.test(arg) && ~(index = arg.indexOf('='))) {
|
449
|
+
ret.push(arg.slice(0, index), arg.slice(index + 1));
|
450
|
+
} else {
|
451
|
+
ret.push(arg);
|
452
|
+
}
|
453
|
+
}
|
454
|
+
|
455
|
+
return ret;
|
456
|
+
};
|
457
|
+
|
458
|
+
/**
|
459
|
+
* Parse command `args`.
|
460
|
+
*
|
461
|
+
* When listener(s) are available those
|
462
|
+
* callbacks are invoked, otherwise the "*"
|
463
|
+
* event is emitted and those actions are invoked.
|
464
|
+
*
|
465
|
+
* @param {Array} args
|
466
|
+
* @return {Command} for chaining
|
467
|
+
* @api private
|
468
|
+
*/
|
469
|
+
|
470
|
+
Command.prototype.parseArgs = function(args, unknown){
|
471
|
+
var cmds = this.commands
|
472
|
+
, len = cmds.length
|
473
|
+
, name;
|
474
|
+
|
475
|
+
if (args.length) {
|
476
|
+
name = args[0];
|
477
|
+
if (this.listeners(name).length) {
|
478
|
+
this.emit(args.shift(), args, unknown);
|
479
|
+
} else {
|
480
|
+
this.emit('*', args);
|
481
|
+
}
|
482
|
+
} else {
|
483
|
+
outputHelpIfNecessary(this, unknown);
|
484
|
+
|
485
|
+
// If there were no args and we have unknown options,
|
486
|
+
// then they are extraneous and we need to error.
|
487
|
+
if (unknown.length > 0) {
|
488
|
+
this.unknownOption(unknown[0]);
|
489
|
+
}
|
490
|
+
}
|
491
|
+
|
492
|
+
return this;
|
493
|
+
};
|
494
|
+
|
495
|
+
/**
|
496
|
+
* Return an option matching `arg` if any.
|
497
|
+
*
|
498
|
+
* @param {String} arg
|
499
|
+
* @return {Option}
|
500
|
+
* @api private
|
501
|
+
*/
|
502
|
+
|
503
|
+
Command.prototype.optionFor = function(arg){
|
504
|
+
for (var i = 0, len = this.options.length; i < len; ++i) {
|
505
|
+
if (this.options[i].is(arg)) {
|
506
|
+
return this.options[i];
|
507
|
+
}
|
508
|
+
}
|
509
|
+
};
|
510
|
+
|
511
|
+
/**
|
512
|
+
* Parse options from `argv` returning `argv`
|
513
|
+
* void of these options.
|
514
|
+
*
|
515
|
+
* @param {Array} argv
|
516
|
+
* @return {Array}
|
517
|
+
* @api public
|
518
|
+
*/
|
519
|
+
|
520
|
+
Command.prototype.parseOptions = function(argv){
|
521
|
+
var args = []
|
522
|
+
, len = argv.length
|
523
|
+
, literal
|
524
|
+
, option
|
525
|
+
, arg;
|
526
|
+
|
527
|
+
var unknownOptions = [];
|
528
|
+
|
529
|
+
// parse options
|
530
|
+
for (var i = 0; i < len; ++i) {
|
531
|
+
arg = argv[i];
|
532
|
+
|
533
|
+
// literal args after --
|
534
|
+
if ('--' == arg) {
|
535
|
+
literal = true;
|
536
|
+
continue;
|
537
|
+
}
|
538
|
+
|
539
|
+
if (literal) {
|
540
|
+
args.push(arg);
|
541
|
+
continue;
|
542
|
+
}
|
543
|
+
|
544
|
+
// find matching Option
|
545
|
+
option = this.optionFor(arg);
|
546
|
+
|
547
|
+
// option is defined
|
548
|
+
if (option) {
|
549
|
+
// requires arg
|
550
|
+
if (option.required) {
|
551
|
+
arg = argv[++i];
|
552
|
+
if (null == arg) return this.optionMissingArgument(option);
|
553
|
+
this.emit(option.name(), arg);
|
554
|
+
// optional arg
|
555
|
+
} else if (option.optional) {
|
556
|
+
arg = argv[i+1];
|
557
|
+
if (null == arg || ('-' == arg[0] && '-' != arg)) {
|
558
|
+
arg = null;
|
559
|
+
} else {
|
560
|
+
++i;
|
561
|
+
}
|
562
|
+
this.emit(option.name(), arg);
|
563
|
+
// bool
|
564
|
+
} else {
|
565
|
+
this.emit(option.name());
|
566
|
+
}
|
567
|
+
continue;
|
568
|
+
}
|
569
|
+
|
570
|
+
// looks like an option
|
571
|
+
if (arg.length > 1 && '-' == arg[0]) {
|
572
|
+
unknownOptions.push(arg);
|
573
|
+
|
574
|
+
// If the next argument looks like it might be
|
575
|
+
// an argument for this option, we pass it on.
|
576
|
+
// If it isn't, then it'll simply be ignored
|
577
|
+
if (argv[i+1] && '-' != argv[i+1][0]) {
|
578
|
+
unknownOptions.push(argv[++i]);
|
579
|
+
}
|
580
|
+
continue;
|
581
|
+
}
|
582
|
+
|
583
|
+
// arg
|
584
|
+
args.push(arg);
|
585
|
+
}
|
586
|
+
|
587
|
+
return { args: args, unknown: unknownOptions };
|
588
|
+
};
|
589
|
+
|
590
|
+
/**
|
591
|
+
* Argument `name` is missing.
|
592
|
+
*
|
593
|
+
* @param {String} name
|
594
|
+
* @api private
|
595
|
+
*/
|
596
|
+
|
597
|
+
Command.prototype.missingArgument = function(name){
|
598
|
+
console.error();
|
599
|
+
console.error(" error: missing required argument `%s'", name);
|
600
|
+
console.error();
|
601
|
+
process.exit(1);
|
602
|
+
};
|
603
|
+
|
604
|
+
/**
|
605
|
+
* `Option` is missing an argument, but received `flag` or nothing.
|
606
|
+
*
|
607
|
+
* @param {String} option
|
608
|
+
* @param {String} flag
|
609
|
+
* @api private
|
610
|
+
*/
|
611
|
+
|
612
|
+
Command.prototype.optionMissingArgument = function(option, flag){
|
613
|
+
console.error();
|
614
|
+
if (flag) {
|
615
|
+
console.error(" error: option `%s' argument missing, got `%s'", option.flags, flag);
|
616
|
+
} else {
|
617
|
+
console.error(" error: option `%s' argument missing", option.flags);
|
618
|
+
}
|
619
|
+
console.error();
|
620
|
+
process.exit(1);
|
621
|
+
};
|
622
|
+
|
623
|
+
/**
|
624
|
+
* Unknown option `flag`.
|
625
|
+
*
|
626
|
+
* @param {String} flag
|
627
|
+
* @api private
|
628
|
+
*/
|
629
|
+
|
630
|
+
Command.prototype.unknownOption = function(flag){
|
631
|
+
console.error();
|
632
|
+
console.error(" error: unknown option `%s'", flag);
|
633
|
+
console.error();
|
634
|
+
process.exit(1);
|
635
|
+
};
|
636
|
+
|
637
|
+
|
638
|
+
/**
|
639
|
+
* Set the program version to `str`.
|
640
|
+
*
|
641
|
+
* This method auto-registers the "-V, --version" flag
|
642
|
+
* which will print the version number when passed.
|
643
|
+
*
|
644
|
+
* @param {String} str
|
645
|
+
* @param {String} flags
|
646
|
+
* @return {Command} for chaining
|
647
|
+
* @api public
|
648
|
+
*/
|
649
|
+
|
650
|
+
Command.prototype.version = function(str, flags){
|
651
|
+
if (0 == arguments.length) return this._version;
|
652
|
+
this._version = str;
|
653
|
+
flags = flags || '-V, --version';
|
654
|
+
this.option(flags, 'output the version number');
|
655
|
+
this.on('version', function(){
|
656
|
+
console.log(str);
|
657
|
+
process.exit(0);
|
658
|
+
});
|
659
|
+
return this;
|
660
|
+
};
|
661
|
+
|
662
|
+
/**
|
663
|
+
* Set the description `str`.
|
664
|
+
*
|
665
|
+
* @param {String} str
|
666
|
+
* @return {String|Command}
|
667
|
+
* @api public
|
668
|
+
*/
|
669
|
+
|
670
|
+
Command.prototype.description = function(str){
|
671
|
+
if (0 == arguments.length) return this._description;
|
672
|
+
this._description = str;
|
673
|
+
return this;
|
674
|
+
};
|
675
|
+
|
676
|
+
/**
|
677
|
+
* Set / get the command usage `str`.
|
678
|
+
*
|
679
|
+
* @param {String} str
|
680
|
+
* @return {String|Command}
|
681
|
+
* @api public
|
682
|
+
*/
|
683
|
+
|
684
|
+
Command.prototype.usage = function(str){
|
685
|
+
var args = this._args.map(function(arg){
|
686
|
+
return arg.required
|
687
|
+
? '<' + arg.name + '>'
|
688
|
+
: '[' + arg.name + ']';
|
689
|
+
});
|
690
|
+
|
691
|
+
var usage = '[options'
|
692
|
+
+ (this.commands.length ? '] [command' : '')
|
693
|
+
+ ']'
|
694
|
+
+ (this._args.length ? ' ' + args : '');
|
695
|
+
|
696
|
+
if (0 == arguments.length) return this._usage || usage;
|
697
|
+
this._usage = str;
|
698
|
+
|
699
|
+
return this;
|
700
|
+
};
|
701
|
+
|
702
|
+
/**
|
703
|
+
* Return the largest option length.
|
704
|
+
*
|
705
|
+
* @return {Number}
|
706
|
+
* @api private
|
707
|
+
*/
|
708
|
+
|
709
|
+
Command.prototype.largestOptionLength = function(){
|
710
|
+
return this.options.reduce(function(max, option){
|
711
|
+
return Math.max(max, option.flags.length);
|
712
|
+
}, 0);
|
713
|
+
};
|
714
|
+
|
715
|
+
/**
|
716
|
+
* Return help for options.
|
717
|
+
*
|
718
|
+
* @return {String}
|
719
|
+
* @api private
|
720
|
+
*/
|
721
|
+
|
722
|
+
Command.prototype.optionHelp = function(){
|
723
|
+
var width = this.largestOptionLength();
|
724
|
+
|
725
|
+
// Prepend the help information
|
726
|
+
return [pad('-h, --help', width) + ' ' + 'output usage information']
|
727
|
+
.concat(this.options.map(function(option){
|
728
|
+
return pad(option.flags, width)
|
729
|
+
+ ' ' + option.description;
|
730
|
+
}))
|
731
|
+
.join('\n');
|
732
|
+
};
|
733
|
+
|
734
|
+
/**
|
735
|
+
* Return command help documentation.
|
736
|
+
*
|
737
|
+
* @return {String}
|
738
|
+
* @api private
|
739
|
+
*/
|
740
|
+
|
741
|
+
Command.prototype.commandHelp = function(){
|
742
|
+
if (!this.commands.length) return '';
|
743
|
+
return [
|
744
|
+
''
|
745
|
+
, ' Commands:'
|
746
|
+
, ''
|
747
|
+
, this.commands.map(function(cmd){
|
748
|
+
var args = cmd._args.map(function(arg){
|
749
|
+
return arg.required
|
750
|
+
? '<' + arg.name + '>'
|
751
|
+
: '[' + arg.name + ']';
|
752
|
+
}).join(' ');
|
753
|
+
|
754
|
+
return pad(cmd._name
|
755
|
+
+ (cmd.options.length
|
756
|
+
? ' [options]'
|
757
|
+
: '') + ' ' + args, 22)
|
758
|
+
+ (cmd.description()
|
759
|
+
? ' ' + cmd.description()
|
760
|
+
: '');
|
761
|
+
}).join('\n').replace(/^/gm, ' ')
|
762
|
+
, ''
|
763
|
+
].join('\n');
|
764
|
+
};
|
765
|
+
|
766
|
+
/**
|
767
|
+
* Return program help documentation.
|
768
|
+
*
|
769
|
+
* @return {String}
|
770
|
+
* @api private
|
771
|
+
*/
|
772
|
+
|
773
|
+
Command.prototype.helpInformation = function(){
|
774
|
+
return [
|
775
|
+
''
|
776
|
+
, ' Usage: ' + this._name + ' ' + this.usage()
|
777
|
+
, '' + this.commandHelp()
|
778
|
+
, ' Options:'
|
779
|
+
, ''
|
780
|
+
, '' + this.optionHelp().replace(/^/gm, ' ')
|
781
|
+
, ''
|
782
|
+
, ''
|
783
|
+
].join('\n');
|
784
|
+
};
|
785
|
+
|
786
|
+
/**
|
787
|
+
* Output help information for this command
|
788
|
+
*
|
789
|
+
* @api public
|
790
|
+
*/
|
791
|
+
|
792
|
+
Command.prototype.outputHelp = function(){
|
793
|
+
process.stdout.write(this.helpInformation());
|
794
|
+
this.emit('--help');
|
795
|
+
};
|
796
|
+
|
797
|
+
/**
|
798
|
+
* Output help information and exit.
|
799
|
+
*
|
800
|
+
* @api public
|
801
|
+
*/
|
802
|
+
|
803
|
+
Command.prototype.help = function(){
|
804
|
+
this.outputHelp();
|
805
|
+
process.exit();
|
806
|
+
};
|
807
|
+
|
808
|
+
/**
|
809
|
+
* Camel-case the given `flag`
|
810
|
+
*
|
811
|
+
* @param {String} flag
|
812
|
+
* @return {String}
|
813
|
+
* @api private
|
814
|
+
*/
|
815
|
+
|
816
|
+
function camelcase(flag) {
|
817
|
+
return flag.split('-').reduce(function(str, word){
|
818
|
+
return str + word[0].toUpperCase() + word.slice(1);
|
819
|
+
});
|
820
|
+
}
|
821
|
+
|
822
|
+
/**
|
823
|
+
* Pad `str` to `width`.
|
824
|
+
*
|
825
|
+
* @param {String} str
|
826
|
+
* @param {Number} width
|
827
|
+
* @return {String}
|
828
|
+
* @api private
|
829
|
+
*/
|
830
|
+
|
831
|
+
function pad(str, width) {
|
832
|
+
var len = Math.max(0, width - str.length);
|
833
|
+
return str + Array(len + 1).join(' ');
|
834
|
+
}
|
835
|
+
|
836
|
+
/**
|
837
|
+
* Output help information if necessary
|
838
|
+
*
|
839
|
+
* @param {Command} command to output help for
|
840
|
+
* @param {Array} array of options to search for -h or --help
|
841
|
+
* @api private
|
842
|
+
*/
|
843
|
+
|
844
|
+
function outputHelpIfNecessary(cmd, options) {
|
845
|
+
options = options || [];
|
846
|
+
for (var i = 0; i < options.length; i++) {
|
847
|
+
if (options[i] == '--help' || options[i] == '-h') {
|
848
|
+
cmd.outputHelp();
|
849
|
+
process.exit(0);
|
850
|
+
}
|
851
|
+
}
|
852
|
+
}
|