cordova-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From fil...@apache.org
Subject [1/2] git commit: bumped to plugman 0.10.0. added optimist. refactored cli shim into own module.
Date Wed, 31 Jul 2013 17:38:55 GMT
Updated Branches:
  refs/heads/master bd1e9c8d6 -> 4c9bbbc0a


bumped to plugman 0.10.0. added optimist. refactored cli shim into own module.


Project: http://git-wip-us.apache.org/repos/asf/cordova-cli/repo
Commit: http://git-wip-us.apache.org/repos/asf/cordova-cli/commit/4c9bbbc0
Tree: http://git-wip-us.apache.org/repos/asf/cordova-cli/tree/4c9bbbc0
Diff: http://git-wip-us.apache.org/repos/asf/cordova-cli/diff/4c9bbbc0

Branch: refs/heads/master
Commit: 4c9bbbc0ae8b00ccffa566c32c96a60db3dcf022
Parents: c39b701
Author: Fil Maj <maj.fil@gmail.com>
Authored: Tue Jul 30 17:01:23 2013 -0700
Committer: Fil Maj <maj.fil@gmail.com>
Committed: Wed Jul 31 10:37:42 2013 -0700

----------------------------------------------------------------------
 bin/cordova  | 68 ++--------------------------------------------------
 package.json |  5 ++--
 src/cli.js   | 72 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 77 insertions(+), 68 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cordova-cli/blob/4c9bbbc0/bin/cordova
----------------------------------------------------------------------
diff --git a/bin/cordova b/bin/cordova
index 63a3a90..4b0c4de 100755
--- a/bin/cordova
+++ b/bin/cordova
@@ -1,68 +1,4 @@
 #!/usr/bin/env node
-var tokens = process.argv.slice(2, process.argv.length),
-    cordova= require('../cordova'),
-    plugman= require('plugman'),
-    platforms= require("../platforms"),
-    opts = {
-        platforms: [],
-        options: [],
-        verbose: false
-    },
-    cmd,
-    version = false,
-    current;
+var CLI = require('../src/cli');
 
-while (current = tokens.shift()) {
-    if (current[0] == '-') {
-        if (current.indexOf('version') > -1 || current[1] == 'v') version = true;
-        if (current.indexOf('verbose') > -1 || current[1] == 'd') opts.verbose = true;
-    } else {
-        cmd = current;
-        break;
-    }
-}
-
-// provide clean output on exceptions rather than dumping a stack trace
-process.on('uncaughtException', function(err){
-    if (opts.verbose) {
-        console.error(err.stack);
-    } else {
-        console.error(err);
-    }
-    process.exit(1);
-});
-cordova.on('results', console.log);
-
-if (opts.verbose) {
-    cordova.on('log', console.log);
-    cordova.on('warn', console.warn);
-    plugman.on('log', console.log);
-    plugman.on('warn', console.warn);
-}
-
-if (version) {
-    console.log(require('../package').version);
-} else if (cmd === undefined) {
-    cordova.help();
-} else if (cordova.hasOwnProperty(cmd)) {
-    if (cmd == 'create' || cmd == 'serve') {
-        opts = Array.prototype.slice.call(tokens, 0);
-        cordova[cmd].apply(this, opts);
-    } else if (cmd == 'emulate' || cmd == 'build' || cmd == 'prepare' || cmd == 'compile'
|| cmd == 'run') {
-        //Filter all non-platforms into options
-        Array.prototype.slice.call(tokens, 0).forEach(function(option, index) {
-            if (platforms.hasOwnProperty(option)) {
-                opts.platforms.push(option);
-            } else {
-                opts.options.push(option);
-            }
-        });
-        cordova[cmd].call(this, opts);
-    } else {
-        // platform or plugin cmds
-        opts = Array.prototype.slice.call(tokens, 0);
-        cordova[cmd].apply(this, opts);
-    }
-} else {
-    throw new Error('Cordova does not know ' + cmd + '; try help for a list of all the available
commands.');
-}
+new CLI(process.argv);

http://git-wip-us.apache.org/repos/asf/cordova-cli/blob/4c9bbbc0/package.json
----------------------------------------------------------------------
diff --git a/package.json b/package.json
index c1c7509..8e2d31c 100644
--- a/package.json
+++ b/package.json
@@ -30,7 +30,7 @@
   "dependencies": {
     "colors":">=0.6.0",
     "elementtree":"0.1.3",
-    "plugman":"0.9.23",
+    "plugman":"0.10.0",
     "plist":"0.4.x",
     "xcode":"0.5.1",
     "express":"3.0.0",
@@ -44,7 +44,8 @@
     "prompt":"0.2.7",
     "tar":"0.1.x",
     "open": "0.0.3",
-    "npm":"1.3.x"
+    "npm":"1.3.x",
+    "optimist":"0.6.0"
   },
   "devDependencies": {
     "jasmine-node":"1.8.x"

http://git-wip-us.apache.org/repos/asf/cordova-cli/blob/4c9bbbc0/src/cli.js
----------------------------------------------------------------------
diff --git a/src/cli.js b/src/cli.js
new file mode 100755
index 0000000..16c818c
--- /dev/null
+++ b/src/cli.js
@@ -0,0 +1,72 @@
+var optimist  = require('optimist'),
+    cordova   = require('../cordova'),
+    plugman   = require('plugman'),
+    platforms = require("../platforms");
+
+module.exports = function CLI(args) {
+    args = optimist(args)
+        .boolean('d')
+        .boolean('verbose')
+        .boolean('v')
+        .boolean('version')
+        .argv;
+
+    if (args.v || args.version) {
+        return console.log(require('../package').version);
+    }
+
+    var tokens = args._.slice(2),
+        opts = {
+            platforms: [],
+            options: [],
+            verbose: (args.d || args.verbose)
+        },
+        cmd = tokens && tokens.length ? tokens[0] : undefined;
+
+    // provide clean output on exceptions rather than dumping a stack trace
+    process.on('uncaughtException', function(err){
+        if (opts.verbose) {
+            console.error(err.stack);
+        } else {
+            console.error(err);
+        }
+        process.exit(1);
+    });
+    cordova.on('results', console.log);
+
+    if (opts.verbose) {
+        cordova.on('log', console.log);
+        cordova.on('warn', console.warn);
+        plugman.on('log', console.log);
+        plugman.on('warn', console.warn);
+    }
+
+    if (cmd === undefined) {
+        return cordova.help();
+    }
+
+    tokens = tokens.slice(1);
+    if (cordova.hasOwnProperty(cmd)) {
+        if (cmd == 'emulate' || cmd == 'build' || cmd == 'prepare' || cmd == 'compile' ||
cmd == 'run') {
+            // Filter all non-platforms into options
+            tokens.forEach(function(option, index) {
+                if (platforms.hasOwnProperty(option)) {
+                    opts.platforms.push(option);
+                } else {
+                    opts.options.push(option);
+                }
+            });
+            cordova[cmd].call(this, opts);
+        } else if (cmd == 'create' || cmd == 'serve') {
+            cordova[cmd].apply(this, tokens);
+        } else {
+            // platform/plugins add/rm [target(s)]
+            var invocation = tokens.slice(0,1); // this has the sub-command, i.e. "platform
add" or "plugin rm"
+            var targets = tokens.slice(1); // this should be an array of targets, be it platforms
or plugins
+            invocation.push(targets);
+            cordova[cmd].apply(this, invocation);
+        }
+    } else {
+        throw new Error('Cordova does not know ' + cmd + '; try help for a list of all the
available commands.');
+    }
+}


Mime
View raw message