cordova-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From omef...@apache.org
Subject [5/6] cordova-cli git commit: Telemetry: Refactor telemetry calls into a single spot, Change prompt, More documentation, etc...
Date Thu, 12 May 2016 19:48:49 GMT
Telemetry: Refactor telemetry calls into a single spot, Change prompt, More documentation,
etc...


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

Branch: refs/heads/master
Commit: 39e5f17cd91c4990a98deec02743de4e3371874b
Parents: 50016c9
Author: Omar Mefire <omefire@gmail.com>
Authored: Mon May 9 19:41:02 2016 -0700
Committer: Omar Mefire <omefire@gmail.com>
Committed: Thu May 12 11:14:55 2016 -0700

----------------------------------------------------------------------
 doc/cordova.txt   |  12 +---
 doc/readme.md     |  18 ++++++
 doc/telemetry.txt |   5 +-
 package.json      |   2 +-
 spec/cli.spec.js  | 156 +++++++++++++---------------------------------
 src/cli.js        | 165 +++++++++++++++++++++++++------------------------
 src/telemetry.js  |  35 +++++------
 7 files changed, 166 insertions(+), 227 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cordova-cli/blob/39e5f17c/doc/cordova.txt
----------------------------------------------------------------------
diff --git a/doc/cordova.txt b/doc/cordova.txt
index 459fd65..630d5d4 100644
--- a/doc/cordova.txt
+++ b/doc/cordova.txt
@@ -5,6 +5,7 @@ Synopsis
 Global Commands
     create ............................. Create a project
     help ............................... Get help for a command
+    telemetry .......................... Turn telemetry collection on or off
 
 Project Commands
     info ............................... Generate project information
@@ -23,12 +24,6 @@ Project Commands
     serve .............................. Run project with a local webserver
                                             (including prepare)
 
-Telemetry Commands
-    telemetry on ....................... Turn telemetry collection on
-    telemetry off ...................... Turn telemetry collection off 
-    <cordova-cmd> --no-telemetry ............... Turn telemetry collection off only
for the command being run
-    For details, see our privacy notice: https://cordova.apache.org/privacy-notice.html 
                                         
-
 Learn more about command options using 'cordova-cli help <command>'
 
 Aliases
@@ -49,7 +44,4 @@ Examples
     cordova-cli requirements android    
     cordova-cli build android --verbose
     cordova-cli run android
-    cordova-cli build android --release -- --keystore="..\android.keystore" --storePassword=android
--alias=mykey
-    cordova-cli telemetry on
-    cordova-cli telemetry off
-    cordova-cli build --no-telemetry
\ No newline at end of file
+    cordova-cli build android --release -- --keystore="..\android.keystore" --storePassword=android
--alias=mykey
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/cordova-cli/blob/39e5f17c/doc/readme.md
----------------------------------------------------------------------
diff --git a/doc/readme.md b/doc/readme.md
index 1321dc2..4383359 100644
--- a/doc/readme.md
+++ b/doc/readme.md
@@ -40,6 +40,7 @@ These commands are available at all times.
 |----------|--------------
 | create | Create a project
 | help <command> | Get help for a command
+| telemetry | Turn telemetry collection on or off
 
 ## Project Command List
 
@@ -611,6 +612,23 @@ Run a local web server for www/ assets using specified `port` or default
of 8000
 cordova serve [port]
 ```
 
+## cordova telemetry command
+
+### Synopsis
+
+Turns telemetry collection on or off.
+
+### Syntax
+
+```
+cordova telemetry [STATE]
+```
+
+| Option      | Description
+|-------------|------------------
+| on          | Turn telemetry collection on.
+| off         | Turn telemetry collection off.
+
 ## cordova help command
 
 ### Synopsis

http://git-wip-us.apache.org/repos/asf/cordova-cli/blob/39e5f17c/doc/telemetry.txt
----------------------------------------------------------------------
diff --git a/doc/telemetry.txt b/doc/telemetry.txt
index 2672ed5..40ac9a4 100644
--- a/doc/telemetry.txt
+++ b/doc/telemetry.txt
@@ -13,12 +13,11 @@ Details
     A timed prompt asking the user to opt-in or out is displayed the first time cordova is
run.
     It lasts for 30 seconds, after which the user is automatically opted-out if he doesn't
provide any answer.
     In CI environments, the `CI` environment variable can be set, which will prevent the
prompt from showing up.
-    Telemetry collection can also be turned off on a single command by using the `--no-telemetry-flag`.
+    Telemetry collection can also be turned off on a single command by using the `--no-telemetry`
flag.
 
 Examples
     cordova-cli telemetry on
     cordova-cli telemetry off
     cordova-cli build --no-telemetry
 
-For details, see our privacy notice: https://cordova.apache.org/privacy-notice.html 
-and the proposal: https://github.com/cordova/cordova-discuss/pull/43
\ No newline at end of file
+For details, see our privacy notice: https://cordova.apache.org/privacy
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/cordova-cli/blob/39e5f17c/package.json
----------------------------------------------------------------------
diff --git a/package.json b/package.json
index 8a42b53..a5c788a 100644
--- a/package.json
+++ b/package.json
@@ -35,7 +35,7 @@
         "nopt": "3.0.1",
         "underscore": "1.7.0",
         "update-notifier": "^0.5.0",
-        "insight": "~0.8.1"
+        "insight": "~0.8.2"
     },
     "devDependencies": {
         "istanbul": "^0.3.4",

http://git-wip-us.apache.org/repos/asf/cordova-cli/blob/39e5f17c/spec/cli.spec.js
----------------------------------------------------------------------
diff --git a/spec/cli.spec.js b/spec/cli.spec.js
index c8b1e9a..011734d 100644
--- a/spec/cli.spec.js
+++ b/spec/cli.spec.js
@@ -57,32 +57,23 @@ describe("cordova cli", function () {
             });
             
             it("will spit out the version with -v", function (done) {
-                cli(["node", "cordova", "-v"]).then(function() {
+                cli(["node", "cordova", "-v"], function() {
                     expect(console.log.mostRecentCall.args[0]).toMatch(version);
                     done();
-                }).fail(function() {
-                    expect(true).toBe(false);
-                    done();
                 });
             });
 
             it("will spit out the version with --version", function (done) {
-                cli(["node", "cordova", "--version"]).then(function() {
+                cli(["node", "cordova", "--version"], function () {
                     expect(console.log.mostRecentCall.args[0]).toMatch(version);
-                    done();
-                }).fail(function() {
-                    assert(true).toBe(false);
-                    done();
+                    done()
                 });
             });
 
             it("will spit out the version with -v anywhere", function (done) {
-                cli(["node", "cordova", "one", "-v", "three"]).then(function() {
+                cli(["node", "cordova", "one", "-v", "three"], function () {
                     expect(console.log.mostRecentCall.args[0]).toMatch(version);
                     done();
-                }).fail(function() {
-                    expect(true).toBe(false);
-                    done();
                 });
             });
         });
@@ -94,61 +85,43 @@ describe("cordova cli", function () {
         });
 
         it("will call command with all arguments passed through", function (done) {
-            cli(["node", "cordova", "build", "blackberry10", "--", "-k", "abcd1234"]).then(function
() {
-                expect(cordova.raw.build).toHaveBeenCalledWith({ platforms: ['blackberry10'],
options: { argv: ['-k', 'abcd1234'] }, verbose: false, silent: false, browserify: false, nohooks:
[], searchpath: undefined });
-                done();
-            }).fail(function () {
-                expect(true).toBe(false);
+            cli(["node", "cordova", "build", "blackberry10", "--", "-k", "abcd1234"], function
() {
+                expect(cordova.raw.build).toHaveBeenCalledWith({ platforms: ['blackberry10'],
options: { argv: ['-k', 'abcd1234'] }, verbose: false, silent: false, browserify: false, nohooks:
[], searchpath: undefined, fetch: false });
                 done();
             });
         });
 
         it("will consume the first instance of -d", function (done) {
-            cli(["node", "cordova", "-d", "build", "blackberry10", "--", "-k", "abcd1234",
"-d"]).then(function () {
-                expect(cordova.raw.build).toHaveBeenCalledWith({ platforms: ['blackberry10'],
options: { verbose: true, argv: ['-k', 'abcd1234', '-d'] }, verbose: true, silent: false,
browserify: false, nohooks: [], searchpath: undefined });
-                done();
-            }).fail(function () {
-                expect(true).toBe(false);
+            cli(["node", "cordova", "-d", "build", "blackberry10", "--", "-k", "abcd1234",
"-d"], function () {
+                expect(cordova.raw.build).toHaveBeenCalledWith({ platforms: ['blackberry10'],
options: { verbose: true, argv: ['-k', 'abcd1234', '-d'] }, verbose: true, silent: false,
browserify: false, nohooks: [], searchpath: undefined, fetch: false });
                 done();
             });
         });
 
         it("will consume the first instance of --verbose", function (done) {
-            cli(["node", "cordova", "--verbose", "build", "blackberry10", "--", "-k", "abcd1234",
"--verbose"]).then(function () {
-                expect(cordova.raw.build).toHaveBeenCalledWith({ platforms: ['blackberry10'],
options: { verbose: true, argv: ['-k', 'abcd1234', '--verbose'] }, verbose: true, silent:
false, browserify: false, nohooks: [], searchpath: undefined });
-                done();
-            }).fail(function () {
-                expect(true).toBe(false);
+            cli(["node", "cordova", "--verbose", "build", "blackberry10", "--", "-k", "abcd1234",
"--verbose"], function () {
+                expect(cordova.raw.build).toHaveBeenCalledWith({ platforms: ['blackberry10'],
options: { verbose: true, argv: ['-k', 'abcd1234', '--verbose'] }, verbose: true, silent:
false, browserify: false, nohooks: [], searchpath: undefined, fetch: false });
                 done();
             });
         });
 
         it("will consume the first instance of either --verbose or -d", function (done) {
-            cli(["node", "cordova", "--verbose", "build", "blackberry10", "--", "-k", "abcd1234",
"-d"]).then(function () {
-                expect(cordova.raw.build).toHaveBeenCalledWith({ platforms: ['blackberry10'],
options: { verbose: true, argv: ['-k', 'abcd1234', '-d'] }, verbose: true, silent: false,
browserify: false, nohooks: [], searchpath: undefined });
-                done();
-            }).fail(function () {
-                expect(true).toBe(false);
+            cli(["node", "cordova", "--verbose", "build", "blackberry10", "--", "-k", "abcd1234",
"-d"], function () {
+                expect(cordova.raw.build).toHaveBeenCalledWith({ platforms: ['blackberry10'],
options: { verbose: true, argv: ['-k', 'abcd1234', '-d'] }, verbose: true, silent: false,
browserify: false, nohooks: [], searchpath: undefined, fetch: false });
                 done();
             });
         });
 
         it("will consume the first instance of either --verbose or -d", function (done) {
-            cli(["node", "cordova", "-d", "build", "blackberry10", "--", "-k", "abcd1234",
"--verbose"]).then(function () {
-                expect(cordova.raw.build).toHaveBeenCalledWith({ platforms: ['blackberry10'],
options: { verbose: true, argv: ['-k', 'abcd1234', '--verbose'] }, verbose: true, silent:
false, browserify: false, nohooks: [], searchpath: undefined });
-                done();
-            }).fail(function () {
-                expect(true).toBe(false);
+            cli(["node", "cordova", "-d", "build", "blackberry10", "--", "-k", "abcd1234",
"--verbose"], function () {
+                expect(cordova.raw.build).toHaveBeenCalledWith({ platforms: ['blackberry10'],
options: { verbose: true, argv: ['-k', 'abcd1234', '--verbose'] }, verbose: true, silent:
false, browserify: false, nohooks: [], searchpath: undefined, fetch: false });
                 done();
             });
         });
 
         it("will consume the first instance of --silent", function (done) {
-            cli(["node", "cordova", "--silent", "build", "blackberry10", "--", "-k", "abcd1234",
"--silent"]).then(function () {
-                expect(cordova.raw.build).toHaveBeenCalledWith({ platforms: ['blackberry10'],
options: { silent: true, argv: ['-k', 'abcd1234', '--silent'] }, verbose: false, silent: true,
browserify: false, nohooks: [], searchpath: undefined });
-                done();
-            }).fail(function () {
-                expect(true).toBe(false);
+            cli(["node", "cordova", "--silent", "build", "blackberry10", "--", "-k", "abcd1234",
"--silent"], function () {
+                expect(cordova.raw.build).toHaveBeenCalledWith({ platforms: ['blackberry10'],
options: { silent: true, argv: ['-k', 'abcd1234', '--silent'] }, verbose: false, silent: true,
browserify: false, nohooks: [], searchpath: undefined, fetch: false });
                 done();
             });
         });
@@ -161,12 +134,9 @@ describe("cordova cli", function () {
         });
 
         it("calls cordova raw create", function (done) {
-            cli(["node", "cordova", "create", "a", "b", "c", "--link-to", "c:\\personalWWW"]).then(function
() {
+            cli(["node", "cordova", "create", "a", "b", "c", "--link-to", "c:\\personalWWW"],
function () {
                 expect(cordova.raw.create).toHaveBeenCalledWith("a", "b", "c", jasmine.any(Object));
                 done();
-            }).fail(function () {
-                expect(true).toBe(false);
-                done();
             });
         });
     });
@@ -177,7 +147,7 @@ describe("cordova cli", function () {
         });
 
         it("will pass variables", function (done) {
-            cli(["node", "cordova", "plugin", "add", "facebook", "--variable", "FOO=foo"]).then(function
() {
+            cli(["node", "cordova", "plugin", "add", "facebook", "--variable", "FOO=foo"],
function () {
                 expect(cordova.raw.plugin).toHaveBeenCalledWith(
                     "add",
                     ["facebook"],
@@ -186,15 +156,11 @@ describe("cordova cli", function () {
                 var opts = cordova.raw.plugin.calls[0].args[2];
                 expect(opts.cli_variables.FOO).toBe('foo');
                 done();
-            }).fail(function() {
-                expect(true).toBe(false);
-                done();
             });
-
         });
 
         it("will  support variables with =", function (done) {
-            cli(["node", "cordova", "plugin", "add", "facebook", "--variable", "MOTO=DELTA=WAS=HERE"]).then(function
() {
+            cli(["node", "cordova", "plugin", "add", "facebook", "--variable", "MOTO=DELTA=WAS=HERE"],
function () {
                 expect(cordova.raw.plugin).toHaveBeenCalledWith(
                     "add",
                     ["facebook"],
@@ -203,14 +169,11 @@ describe("cordova cli", function () {
                 var opts = cordova.raw.plugin.calls[0].args[2];
                 expect(opts.cli_variables.MOTO).toBe('DELTA=WAS=HERE');
                 done();
-            }).fail(function () {
-                expect(true).toBe(false);
-                done();
             });
         });
 
         it("will pass hook patterns to suppress", function (done) {
-            cli(["node", "cordova", "plugin", "add", "facebook", "--nohooks", "before_plugin_add"]).then(function
() {
+            cli(["node", "cordova", "plugin", "add", "facebook", "--nohooks", "before_plugin_add"],
function () {
                 expect(cordova.raw.plugin).toHaveBeenCalledWith(
                     "add",
                     ["facebook"],
@@ -219,10 +182,7 @@ describe("cordova cli", function () {
                 var opts = cordova.raw.plugin.calls[0].args[2];
                 expect(opts.nohooks[0]).toBe("before_plugin_add");
                 done();
-            }).fail(function () {
-                expect(true).toBe(false);
-                done();
-            });  
+            });
         });
 
     });
@@ -234,15 +194,12 @@ describe("cordova cli", function () {
                wasPromptShown = true;
            });
 
-           cli(["node", "cordova", "telemetry", "on"]).then(function (done) {
-               return cli(["node", "cordova", "telemetry", "off"])
-           }).then(function () {
-               expect(wasPromptShown).toBeFalsy();
-               done();
-           }).fail(function () {
-               expect(true).toBe(false);
-               done();
-           });           
+           cli(["node", "cordova", "telemetry", "on"], function () {
+               cli(["node", "cordova", "telemetry", "off"], function () {
+                   expect(wasPromptShown).toBeFalsy();
+                   done();
+               });
+           });         
        });
        
        it("is NOT collected when user runs 'cordova telemetry on' while NOT opted-in", function(done)
{
@@ -251,13 +208,10 @@ describe("cordova cli", function () {
            
            spyOn(telemetry, "track");
            
-           cli(["node", "cordova", "telemetry", "on"]).then(function () {
+           cli(["node", "cordova", "telemetry", "on"], function () {
                expect(telemetry.track).not.toHaveBeenCalled();
                done();
-           }).fail(function () {
-               expect(true).toBe(false);
-               done();
-           });  
+           });
        });
        
        it("is collected when user runs 'cordova telemetry off' while opted-in", function(done)
{
@@ -266,13 +220,10 @@ describe("cordova cli", function () {
            
            spyOn(telemetry, "track");
            
-           cli(["node", "cordova", "telemetry", "off"]).then(function () {
-               expect(telemetry.track).toHaveBeenCalledWith("telemetry-opt-out", "via-cordova-telemetry-off");
+           cli(["node", "cordova", "telemetry", "off"], function () {
+               expect(telemetry.track).toHaveBeenCalledWith("telemetry", "off", "via-cordova-telemetry-cmd",
"successful");
                done();
-           }).fail(function () {
-               expect(true).toBe(false);
-               done();
-           });  
+           });
        });
        
        it("shows prompt if user neither opted in or out yet", function(done) {
@@ -283,12 +234,9 @@ describe("cordova cli", function () {
            spyOn(telemetry, "isNoTelemetryFlag").andReturn(false);
            spyOn(telemetry, "showPrompt").andReturn(Q(false));
            
-           return cli(["node", "cordova", "prepare"]).then(function() {
+           cli(["node", "cordova", "prepare"], function () {
                expect(telemetry.showPrompt).toHaveBeenCalled();
                done();
-           }).fail(function() {
-               expect(true).toBe(false);
-               done();
            });
        });
 
@@ -302,12 +250,9 @@ describe("cordova cli", function () {
            spyOn(telemetry, "isCI").andReturn(false);
            spyOn(telemetry, "track");
            
-           cli(["node", "cordova", "--version"]).then(function() {
+           cli(["node", "cordova", "--version"], function () {
                expect(telemetry.isOptedIn()).toBeFalsy();
-               expect(telemetry.track).toHaveBeenCalledWith('telemetry-opt-out', 'via-cli-prompt-choice');
-               done();
-           }).fail(function() {
-               expect(true).toBe(false);
+               expect(telemetry.track).toHaveBeenCalledWith("telemetry", "off", "via-cli-prompt-choice",
"successful");
                done();
            });
        }/*, 45000*/);
@@ -320,13 +265,10 @@ describe("cordova cli", function () {
            spyOn(telemetry, "showPrompt");
            spyOn(telemetry, "track");
            
-           cli(["node", "cordova", "--version"]).then(function() {
+           cli(["node", "cordova", "--version"], function () {
                expect(telemetry.showPrompt).not.toHaveBeenCalled();
                expect(telemetry.track).not.toHaveBeenCalled();
                done();
-           }).fail(function() {
-               expect(true).toBe(false);
-               done();
            });
        });
        
@@ -338,13 +280,10 @@ describe("cordova cli", function () {
            spyOn(telemetry, "showPrompt");
            spyOn(telemetry, "track");
            
-           cli(["node", "cordova", "--version", "--no-telemetry"]).then(function() {
+           cli(["node", "cordova", "--version", "--no-telemetry"], function () {
                expect(telemetry.showPrompt).not.toHaveBeenCalled();
                expect(telemetry.track).not.toHaveBeenCalled();
                done();
-           }).fail(function() {
-               expect(true).toBe(false);
-               done();
            });
        });
        
@@ -356,13 +295,10 @@ describe("cordova cli", function () {
            spyOn(telemetry, "showPrompt");
            spyOn(telemetry, "track");
            
-           cli(["node", "cordova", "--version"]).then(function() {
+           cli(["node", "cordova", "--version"], function () {
                expect(telemetry.showPrompt).not.toHaveBeenCalled();
                expect(telemetry.track).not.toHaveBeenCalled();
                done();
-           }).fail(function() {
-               expect(true).toBe(false);
-               done();
            });
        });
        
@@ -374,13 +310,10 @@ describe("cordova cli", function () {
            spyOn(telemetry, "showPrompt");
            spyOn(telemetry, "track");
            
-           cli(["node", "cordova", "--version"]).then(function() {
+           cli(["node", "cordova", "--version"], function () {
                expect(telemetry.showPrompt).not.toHaveBeenCalled();
                expect(telemetry.track).toHaveBeenCalled();
                done();
-           }).fail(function() {
-               expect(true).toBe(false);
-               done();
            });
        });
        
@@ -391,15 +324,12 @@ describe("cordova cli", function () {
            spyOn(telemetry, "track");
 
            expect(telemetry.isOptedIn()).toBeFalsy();
-           
-           cli(["node", "cordova", "telemetry", "off"]).then(function() {
+
+           cli(["node", "cordova", "telemetry", "off"], function () {
                expect(telemetry.isOptedIn()).toBeFalsy();
-               expect(telemetry.track).toHaveBeenCalledWith("telemetry-opt-out", "via-cordova-telemetry-off");
+               expect(telemetry.track).toHaveBeenCalledWith("telemetry", "off", "via-cordova-telemetry-cmd",
"successful");
                done();
-           }).fail(function() {
-               expect(true).toBe(false);
-               done();
-           });;
+           });
        });
     });
 });

http://git-wip-us.apache.org/repos/asf/cordova-cli/blob/39e5f17c/src/cli.js
----------------------------------------------------------------------
diff --git a/src/cli.js b/src/cli.js
index 9ed849f..91b918f 100644
--- a/src/cli.js
+++ b/src/cli.js
@@ -81,17 +81,32 @@ function checkForUpdates() {
     }
 }
 
-module.exports = function(inputArgs) {
+var shouldCollectTelemetry = false;
+module.exports = function (inputArgs, cb) {
+    
+    /**
+     * mainly used for testing.
+     */
+    cb = cb || function(){};
     
     init();
     
     // If no inputArgs given, use process.argv.
     inputArgs = inputArgs || process.argv;
-        
-    return Q().then(function() {
+    var cmd = inputArgs[2]; // e.g: inputArgs= 'node cordova run ios'
+    var isTelemetryCmd = (cmd === 'telemetry');
+
+    // ToDO: Move nopt-based parsing of args up here
+    if(cmd === '--version' || cmd === '-v') {
+        cmd = 'version';
+    } else if(!cmd || cmd === '--help' || cmd === 'h') {
+        cmd = 'help';
+    }
+            
+    Q().then(function() {
         
         /**
-         * 1- Skip telemetry prompt if:
+         * Skip telemetry prompt if:
          * - CI environment variable is present
          * - Command is run with `--no-telemetry` flag
          * - Command ran is: `cordova telemetry on | off | ...`
@@ -102,30 +117,79 @@ module.exports = function(inputArgs) {
         }
         
         /**
-         * 2- We shouldn't prompt for telemetry if user issues a command of the form: `cordova
telemetry on | off | ...x`
+         * We shouldn't prompt for telemetry if user issues a command of the form: `cordova
telemetry on | off | ...x`
+         * Also, if the user has already been prompted and made a decision, use his saved
answer
          */
-        var isTelemetryCmd = inputArgs[2] === 'telemetry';
         if(isTelemetryCmd) {
-            return Q(telemetry.isOptedIn());
+            var subcommand = inputArgs[3];
+            var isOptedIn = telemetry.isOptedIn();
+            return handleTelemetryCmd(subcommand, isOptedIn);
         }
         
-        // 3- If user has already been prompted and made a decision, use his saved answer
         if(telemetry.hasUserOptedInOrOut()) {
             return Q(telemetry.isOptedIn());
         }
         
         /**
-         * 4- Otherwise, prompt user to opt-in or out
+         * Otherwise, prompt user to opt-in or out
          * Note: the prompt is shown for 30 seconds. If no choice is made by that time, User
is considered to have opted out.
          */
         return telemetry.showPrompt();
-        
-    }).then(function(shouldCollectTelemetry) { 
-        cli(inputArgs, shouldCollectTelemetry);
-    });
+    }).then(function (collectTelemetry) {
+        shouldCollectTelemetry = collectTelemetry;
+        if(isTelemetryCmd) {
+            return Q();
+        }
+        return cli(inputArgs);
+    }).then(function () {
+        if (shouldCollectTelemetry && !isTelemetryCmd) {
+            telemetry.track(cmd, 'successful');
+        }
+        // call cb with error as arg if something failed
+        cb(null);
+    }).fail(function (err) {
+        if (shouldCollectTelemetry && !isTelemetryCmd) {
+            telemetry.track(cmd, 'unsuccessful');
+        }
+        // call cb with error as arg if something failed
+        cb(err);
+        throw err;
+    }).done();
 };
 
-function cli(inputArgs, shouldCollectTelemetry) {
+function handleTelemetryCmd(subcommand, isOptedIn) {
+    var turnOn = subcommand === 'on' ? true : false;
+    var cmdSuccess = true;
+
+    // turn telemetry on or off
+    try {
+        if (turnOn) {
+            telemetry.turnOn();
+            console.log("Thanks for opting into telemetry to help us improve cordova.");
+        } else {
+            telemetry.turnOff();
+            console.log("You have been opted out of telemetry. To change this, run: cordova
telemetry on.");
+        }
+    } catch (ex) {
+        cmdSuccess = false;
+    }
+
+    // track or not track ?, that is the question
+
+    if (!turnOn) {
+        // Always track telemetry opt-outs (whether user opted out or not!)
+        telemetry.track('telemetry', 'off', 'via-cordova-telemetry-cmd', cmdSuccess ? 'successful':
'unsuccessful');
+        return Q();
+    }
+    
+    if(isOptedIn) {
+        telemetry.track('telemetry', 'on', 'via-cordova-telemetry-cmd', cmdSuccess ? 'successful'
: 'unsuccessful');
+    }
+    
+    return Q();
+}
+
+function cli(inputArgs) {
     // When changing command line arguments, update doc/help.txt accordingly.
     var knownOpts =
         { 'verbose' : Boolean
@@ -178,10 +242,6 @@ function cli(inputArgs, shouldCollectTelemetry) {
             toPrint += ' (cordova-lib@' + libVersion + ')';
         }
         console.log(toPrint);
-        if(shouldCollectTelemetry) {
-            var cmd = 'version';
-            telemetry.track(cmd, args.version);
-        }
         return Q();
     }
 
@@ -234,30 +294,8 @@ function cli(inputArgs, shouldCollectTelemetry) {
         if (!args.help && remain[0] == 'help') {
             remain.shift();
         }
-        if(shouldCollectTelemetry) {
-            telemetry.track(cmd); 
-        }
         return help(remain);
     }
-    
-    if (cmd === 'telemetry') {
-        if (undashed[1] === 'on') {
-            telemetry.turnOn();
-            if (shouldCollectTelemetry) {
-                telemetry.track(cmd, 'on');
-            }
-            console.log("Thanks for opting into telemetry to help us better cordova");
-        } else if (undashed[1] === 'off') {
-            telemetry.turnOff();
-            // Always track telemetry opt-outs (whether user opted out or not!)
-            telemetry.track('telemetry-opt-out', 'via-cordova-telemetry-off'); 
-            console.log("You have been opted out of telemetry. To change this, run: cordova
telemetry on");
-        } else {
-            return help(['telemetry']); 
-        }
-
-        return Q();
-    }
 
     if ( !cordova.hasOwnProperty(cmd) ) {
         msg =
@@ -292,22 +330,10 @@ function cli(inputArgs, shouldCollectTelemetry) {
         opts.options.argv = unparsedArgs;
 
         if (cmd === 'run' && args.list && cordova.raw.targets) {
-            var result = cordova.raw.targets.call(null, opts);
-            return result.finally(function() {
-                if (shouldCollectTelemetry) {
-                    telemetry.track(cmd, result.isFulfilled() ? 'successful' : 'unsuccessful');
-                }
-                return result;
-            });
+            return cordova.raw.targets.call(null, opts);
         }
 
-        var result = cordova.raw[cmd].call(null, opts);
-        return result.finally(function() {
-            if (shouldCollectTelemetry) {
-                telemetry.track(cmd, result.isFulfilled() ? 'successful' : 'unsuccessful');
-            }
-            return result;
-        });
+        return cordova.raw[cmd].call(null, opts);
     } else if (cmd === 'requirements') {
         // All options without dashes are assumed to be platform names
         opts.platforms = undashed.slice(1);
@@ -317,7 +343,7 @@ function cli(inputArgs, shouldCollectTelemetry) {
             throw new CordovaError(msg);
         }
 
-        var result = cordova.raw[cmd].call(null, opts.platforms)
+        return cordova.raw[cmd].call(null, opts.platforms)
             .then(function(platformChecks) {
 
                 var someChecksFailed = Object.keys(platformChecks).map(function(platformName)
{
@@ -347,28 +373,11 @@ function cli(inputArgs, shouldCollectTelemetry) {
 
                 if (someChecksFailed) throw new CordovaError('Some of requirements check
failed');
             });
-        return result.finally(function() {
-            if (shouldCollectTelemetry) {
-                telemetry.track(cmd, result.isFulfilled() ? 'successful' : 'unsuccessful');
-            }
-            return result;
-        });   
     } else if (cmd == 'serve') {
         var port = undashed[1];
-        var result = cordova.raw.serve(port);
-        return result.finally(function() {
-            if(shouldCollectTelemetry) {
-                telemetry.track(cmd, result.isFulfilled() ? 'successful' : 'unsuccessful');
-            }
-        });
+        return cordova.raw.serve(port);
     } else if (cmd == 'create') {
-        var result = create();
-        return result.finally(function() {
-            if (shouldCollectTelemetry) {
-                telemetry.track(cmd, result.isFulfilled() ? 'successful' : 'unsuccessful');
-            }
-            return result;
-        });
+        return create();
     } else {
         // platform/plugins add/rm [target(s)]
         subcommand = undashed[1]; // sub-command like "add", "ls", "rm" etc.
@@ -396,13 +405,7 @@ function cli(inputArgs, shouldCollectTelemetry) {
                             , shrinkwrap: args.shrinkwrap || false
                             , force: args.force || false
                             };
-        var result = cordova.raw[cmd](subcommand, targets, download_opts);
-        return result.finally(function() {
-            if (shouldCollectTelemetry) {
-                telemetry.track(cmd, result.isFulfilled() ? 'successful' : 'unsuccessful');
-            }
-            return result;
-        });
+        return cordova.raw[cmd](subcommand, targets, download_opts);
     }
 
     function create() {

http://git-wip-us.apache.org/repos/asf/cordova-cli/blob/39e5f17c/src/telemetry.js
----------------------------------------------------------------------
diff --git a/src/telemetry.js b/src/telemetry.js
index 4505163..f80e2d4 100644
--- a/src/telemetry.js
+++ b/src/telemetry.js
@@ -22,6 +22,11 @@
           laxcomma:true
 */
 
+
+
+// For further details on telemetry, see:
+// https://github.com/cordova/cordova-discuss/pull/43
+
 var Q = require('q');
 
 // Google Analytics tracking code
@@ -41,17 +46,19 @@ function showPrompt() {
 
     var deferred = Q.defer();
     
-    var msg = 'Do you want to prevent cordova from anonymously collecting usage statitics
to improve the tool over time ?';
-    insight.askPermission(msg, function (unused, optOut) {
-        if (optOut) {
-            console.log("You have been opted out of telemetry. To change this, run: cordova
telemetry on");
-            // Always track telemetry opt-outs! (whether opted-in or opted-out)
-            track('telemetry-opt-out', 'via-cli-prompt-choice');
+    var msg = "May Cordova anonymously report usage statistics to improve the tool over time?";
+    insight.askPermission(msg, function (unused, optIn) {
+        var EOL = require('os').EOL;
+        if (optIn) {
+            console.log(EOL + "Thanks for opting into telemetry to help us improve cordova.");
+            track('telemetry', 'on', 'via-cli-prompt-choice', 'successful');
         } else {
-            console.log("Thanks for opting into telemetry to help us better cordova");
+            console.log(EOL + "You have been opted out of telemetry. To change this, run:
cordova telemetry on.");
+            // Always track telemetry opt-outs! (whether opted-in or opted-out)
+            track('telemetry', 'off', 'via-cli-prompt-choice', 'successful');
         }
-
-        deferred.resolve(!optOut); 
+        
+        deferred.resolve(optIn); 
     });
     
     return deferred.promise;
@@ -61,15 +68,6 @@ function track() {
     insight.track.apply(insight, arguments);
 }
 
-function trackEvent(category, action, label, value) {
-    insight.trackEvent({
-        category: category,
-        action: action,
-        label: label,
-        value: value
-    });
-}
-
 function turnOn() {
     insight.optOut = false;
 }
@@ -114,7 +112,6 @@ function isNoTelemetryFlag(args) {
 
 module.exports = {
     track: track,
-    trackEvent: trackEvent,
     turnOn: turnOn,
     turnOff: turnOff,
     clear: clear,


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@cordova.apache.org
For additional commands, e-mail: commits-help@cordova.apache.org


Mime
View raw message