You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cordova.apache.org by ag...@apache.org on 2014/04/23 18:35:51 UTC

[1/2] git commit: CB-6329 improve 'cordova info' command

Repository: cordova-cli
Updated Branches:
  refs/heads/master c7ac042fc -> cdb5deff9


CB-6329 improve 'cordova info' command

info.js file has been modified to work mainly asynchronous.
Added info-utils, which contains several useful functions required by
info.js
-It doesn't require a template to set an output.
-getNode, getCordova, doPlatforms works asynchronous, works with
callbacks and deals with errors.
-it writes a report (info.txt) in rootProject.

This changes are required for futures improvements.


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

Branch: refs/heads/master
Commit: 9372f0dd3ca9d9bc8982d0aaae7ee11ff1e58b9e
Parents: c7ac042
Author: Martin Gonzalez <ma...@gmail.com>
Authored: Wed Mar 26 12:48:08 2014 -0600
Committer: Andrew Grieve <ag...@chromium.org>
Committed: Wed Apr 23 12:34:36 2014 -0400

----------------------------------------------------------------------
 doc/info.txt      |  21 ------
 doc/platforms.txt |   7 --
 src/info-utils.js |  50 ++++++++++++++
 src/info.js       | 172 +++++++++++++++++++++----------------------------
 4 files changed, 123 insertions(+), 127 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cordova-cli/blob/9372f0dd/doc/info.txt
----------------------------------------------------------------------
diff --git a/doc/info.txt b/doc/info.txt
deleted file mode 100644
index ad3b665..0000000
--- a/doc/info.txt
+++ /dev/null
@@ -1,21 +0,0 @@
-Useful Information For Submitting Bug Reports and Getting Help
-
-Current Node Version
-
-    %Node
-
-Current Cordova CLI Version
-
-    %Cordova
-
-Current Config.xml
-
-    %Config
-
-Currently Installed Platforms
-
-    %Platforms
-
-Currently Installed Plugins
-
-    %Plugins

http://git-wip-us.apache.org/repos/asf/cordova-cli/blob/9372f0dd/doc/platforms.txt
----------------------------------------------------------------------
diff --git a/doc/platforms.txt b/doc/platforms.txt
deleted file mode 100644
index 58689f7..0000000
--- a/doc/platforms.txt
+++ /dev/null
@@ -1,7 +0,0 @@
-----------------------------------------
-
-    %Platform
-
-    %OtherGoodies
-
-----------------------------------------

http://git-wip-us.apache.org/repos/asf/cordova-cli/blob/9372f0dd/src/info-utils.js
----------------------------------------------------------------------
diff --git a/src/info-utils.js b/src/info-utils.js
new file mode 100644
index 0000000..607e922
--- /dev/null
+++ b/src/info-utils.js
@@ -0,0 +1,50 @@
+    /**
+    Licensed to the Apache Software Foundation (ASF) under one
+    or more contributor license agreements.  See the NOTICE file
+    distributed with this work for additional information
+    regarding copyright ownership.  The ASF licenses this file
+    to you under the Apache License, Version 2.0 (the
+    "License"); you may not use this file except in compliance
+    with the License.  You may obtain a copy of the License at
+
+    http://www.apache.org/licenses/LICENSE-2.0
+
+    Unless required by applicable law or agreed to in writing,
+    software distributed under the License is distributed on an
+    "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+    KIND, either express or implied.  See the License for the
+    specific language governing permissions and limitations
+    under the License.
+     */
+var superspawn    = require('./superspawn'),
+    Q             = require('q'),
+    _self;
+
+_self = {
+    getNodeInfo : function () {
+        return _self.execSpawn("node", "--version", "Node version: ", "Error retrieving Node version: ");
+    },
+    getCordovaInfo : function () {
+        return _self.execSpawn("Cordova", "--version", "Cordova version: ", "Error retrieving Cordova version: ");
+    },
+    getPlatformInfo : function (platform, projectRoot) {
+        switch (platform) {
+        case "ios":
+            return _self.execSpawn("xcodebuild", "-version", "iOS platform:\n\n", "Error retrieving iOS platform information: ");
+            break;
+        case "android":
+            return _self.execSpawn("android list target", "", "Android platform:\n\n", "Error retrieving Android platform information: ");
+            break;
+        }
+    },
+    // Execute using a child_process exec, for any async command
+    execSpawn : function (command, args, resultMsg, errorMsg) {
+        return Q.when(superspawn.spawn(command, args), function (result) {
+            return resultMsg + result;
+        }, function (error) {
+            return errorMsg + error;
+        });
+    }
+};
+
+module.exports = _self;

http://git-wip-us.apache.org/repos/asf/cordova-cli/blob/9372f0dd/src/info.js
----------------------------------------------------------------------
diff --git a/src/info.js b/src/info.js
index 0668cd5..a61d88e 100644
--- a/src/info.js
+++ b/src/info.js
@@ -1,4 +1,4 @@
-/**
+    /**
     Licensed to the Apache Software Foundation (ASF) under one
     or more contributor license agreements.  See the NOTICE file
     distributed with this work for additional information
@@ -15,124 +15,98 @@
     KIND, either express or implied.  See the License for the
     specific language governing permissions and limitations
     under the License.
-*/
-var cordova_util  = require('./util'),
-    shell         = require('shelljs'),
-    path          = require('path'),
-    fs            = require('fs'),
-    Q             = require('q'),
-    events        = require('./events');
-
-/*
+     */
+     
+    /*
     A utility funciton to help output the information needed
     when submitting a help request.
-
     Outputs to a file
-*/
-module.exports = function info() {
-
-    //Get the template
-    var projectRoot = cordova_util.cdProjectRoot();
+     */
+var cordova_util = require('./util'),
+    path         = require('path'),
+    fs           = require('fs'),
+    Q            = require('q'),
+    info_utils   = require('./info-utils');
 
-    var raw = fs.readFileSync(path.join(__dirname, '..', 'doc', 'info.txt'), 'utf-8').split("\n"),
-        output;
 
-    output = raw.map(function(line) {
-        if(line.match('    %') ) {
-            var type = (line.substr(5)).replace("\r",""),
-                out = "";
+module.exports = function info() {
+    //Get projectRoot
+    var projectRoot = cordova_util.cdProjectRoot(),output = "";
+    if (!projectRoot) {
+        return Q.reject(new Error('Current working directory is not a Cordova-based project.'));
+    }
 
-            switch(type) {
-            case "Node":
-                out = shell.exec('node --version',{silent:true}).output;
-                break;
-            case "Cordova":
-                out = require('../package').version;
-                break;
-            case "Config":
-                out = fs.readFileSync( cordova_util.projectConfig(projectRoot) );
-                break;
-            case "Platforms":
-                out = doPlatforms( projectRoot );
-                break;
-            case "Plugins":
-                out = doPlugins( projectRoot );
-                break;
-            default:
-                break;
+    //Array of functions, Q.allSettled
+    console.log("Collecting Data...\n\n");
+    return Q.allSettled([
+            //Get Node version
+            info_utils.getNodeInfo(),
+            //Get Cordova version
+            info_utils.getCordovaInfo(),
+            //Get project config.xml file using ano
+             getProjectConfig(projectRoot),
+            //Get list of plugins
+            listPlugins(projectRoot), 
+            //Get Platforms information
+            getPlatforms(projectRoot)
+        ]).then(function (promises) {
+        promises.forEach(function (p) {
+            output += (function () {
+                return p.state === "fulfilled" ? p.value + "\n\n" : p.state === "rejected" ? p.reason + "\n\n" : "Still working"
             }
-            return line.replace( "%"+type, out );
-        } else {
-            return line;
-        }
-    }).join("\n");
-
-    // /*
-    //     Write to File;
-    // */
-    events.emit('results', output);
-    fs.writeFileSync('info.txt', output );
-    return Q();
+                ());
+        });
+        print_SaveMsg(projectRoot, output);
+    });
 };
 
-function doPlatform( currentPlatform ) {
-    var output = "";
-    switch( currentPlatform ){
-    case "ios":
-        output = shell.exec('xcodebuild -version',{silent:true} ).output;
-        break;
-    case "android":
-        output = shell.exec('android list target',{silent:true} ).output;
-    }
-
-    return output;
+function print_SaveMsg(projectRoot, data) {
+    console.info(data);
+    fs.writeFile(path.join(projectRoot, "info.txt"), data, "utf-8", function (err) {
+        if (err)
+            throw err;
+    });
 }
 
-function doPlatforms( projectRoot ){
-    var platforms = cordova_util.listPlatforms(projectRoot);
-
-    if( platforms.length ) {
+function getPlatforms(projectRoot) {
+    var platforms = cordova_util.listPlatforms(projectRoot),
+        promises  = [];
 
-        var raw = fs.readFileSync(path.join(__dirname, '..', 'doc', 'platforms.txt')).toString('utf8').split("\n"),
-            output = "",
-            i;
+    if (platforms.length) {
+        platforms.forEach(function (platform) {
+            var deferred = Q.defer();
+            deferred.resolve(info_utils.getPlatformInfo(platform, projectRoot));
+            promises.push(deferred.promise);
+        });
+    } else {
+        var deferred = Q.defer()
+            deferred.reject("No Platforms Currently Installed");
+        promises.push(deferred.promise);
+    }
 
-        for(i=0; i<platforms.length; i++){
-            output += raw.map(function(line) {
-                if(line.match('    %') ) {
-                    var type = (line.substr(5)).replace("\r",""),
-                        out = "";
+    return Q.all(promises)
+}
 
-                    switch(type) {
-                    case "OtherGoodies":
-                        out = doPlatform( platforms[ i ] );
-                        break;
-                    case "Platform":
-                        out = platforms[ i ];
-                        break;
-                    default:
-                        break;
-                    }
-                        return line.replace( "%"+type, out );
-                    } else {
-                        return line.magenta;
-                }
-            }).join("\n");
-        }
+function listPlugins(projectRoot) {
+    var pluginPath = path.join(projectRoot, "plugins"),
+        plugins    = cordova_util.findPlugins(pluginPath),
+        deferred   = Q.defer();
 
-        return output;
+    if (!plugins.length) {
+        deferred.reject("No Plugins Currently Installed");
     } else {
-        return "No Platforms Currently Installed";
+        deferred.resolve("Plugins: \n\n" + plugins);
     }
+    return deferred.promise
 }
 
-function doPlugins( projectRoot ){
-    var pluginPath = path.join(projectRoot, 'plugins'),
-        plugins = cordova_util.findPlugins(pluginPath);
+function getProjectConfig(projectRoot) {
+    var deferred = Q.defer();
 
-    if( !plugins.length ) {
-        return "No Plugins Currently Installed";
+    if (!fs.existsSync(projectRoot)  ) {
+        deferred.reject("Config.xml file not found");
     } else {
-        return plugins;
+        deferred.resolve("Config.xml file: \n\n" + (fs.readFileSync(cordova_util.projectConfig(projectRoot), "utf-8")));
     }
+    return deferred.promise
 }


[2/2] git commit: CB-6329 Clean-up of cordova info changes previously merged.

Posted by ag...@apache.org.
CB-6329 Clean-up of cordova info changes previously merged.

github: close #151


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

Branch: refs/heads/master
Commit: cdb5deff99f60c0e10d44d49de63bd07ce2e5ca1
Parents: 9372f0d
Author: Andrew Grieve <ag...@chromium.org>
Authored: Wed Apr 23 12:33:56 2014 -0400
Committer: Andrew Grieve <ag...@chromium.org>
Committed: Wed Apr 23 12:35:05 2014 -0400

----------------------------------------------------------------------
 src/info.js | 141 +++++++++++++++++++++++++++----------------------------
 1 file changed, 70 insertions(+), 71 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cordova-cli/blob/cdb5deff/src/info.js
----------------------------------------------------------------------
diff --git a/src/info.js b/src/info.js
index a61d88e..c8b8e24 100644
--- a/src/info.js
+++ b/src/info.js
@@ -1,112 +1,111 @@
-    /**
-    Licensed to the Apache Software Foundation (ASF) under one
-    or more contributor license agreements.  See the NOTICE file
-    distributed with this work for additional information
-    regarding copyright ownership.  The ASF licenses this file
-    to you under the Apache License, Version 2.0 (the
-    "License"); you may not use this file except in compliance
-    with the License.  You may obtain a copy of the License at
+/**
+Licensed to the Apache Software Foundation (ASF) under one
+or more contributor license agreements.  See the NOTICE file
+distributed with this work for additional information
+regarding copyright ownership.  The ASF licenses this file
+to you under the Apache License, Version 2.0 (the
+'License'); you may not use this file except in compliance
+with the License.  You may obtain a copy of the License at
 
-    http://www.apache.org/licenses/LICENSE-2.0
+http://www.apache.org/licenses/LICENSE-2.0
 
-    Unless required by applicable law or agreed to in writing,
-    software distributed under the License is distributed on an
-    "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-    KIND, either express or implied.  See the License for the
-    specific language governing permissions and limitations
-    under the License.
-     */
-     
-    /*
-    A utility funciton to help output the information needed
-    when submitting a help request.
-    Outputs to a file
-     */
+Unless required by applicable law or agreed to in writing,
+software distributed under the License is distributed on an
+'AS IS' BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+KIND, either express or implied.  See the License for the
+specific language governing permissions and limitations
+under the License.
+ */
+
+/*
+A utility funciton to help output the information needed
+when submitting a help request.
+Outputs to a file
+ */
 var cordova_util = require('./util'),
+    superspawn   = require('./superspawn'),
+    package      = require('../package'),
     path         = require('path'),
     fs           = require('fs'),
-    Q            = require('q'),
-    info_utils   = require('./info-utils');
+    Q            = require('q');
+
+// Execute using a child_process exec, for any async command
+function execSpawn(command, args, resultMsg, errorMsg) {
+    return superspawn.spawn(command, args).then(function(result) {
+        return resultMsg + result;
+    }, function(error) {
+        return errorMsg + error;
+    });
+}
+
+function getPlatformInfo(platform, projectRoot) {
+    switch (platform) {
+    case 'ios':
+        return execSpawn('xcodebuild', ['-version'], 'iOS platform:\n\n', 'Error retrieving iOS platform information: ');
+    case 'android':
+        return execSpawn('android', ['list', 'target'], 'Android platform:\n\n', 'Error retrieving Android platform information: ');
+    }
+}
 
 
 module.exports = function info() {
     //Get projectRoot
-    var projectRoot = cordova_util.cdProjectRoot(),output = "";
+    var projectRoot = cordova_util.cdProjectRoot();
+    var output = '';
     if (!projectRoot) {
         return Q.reject(new Error('Current working directory is not a Cordova-based project.'));
     }
 
     //Array of functions, Q.allSettled
-    console.log("Collecting Data...\n\n");
+    console.log('Collecting Data...\n\n');
     return Q.allSettled([
             //Get Node version
-            info_utils.getNodeInfo(),
+            Q('Node version: ' + process.version),
             //Get Cordova version
-            info_utils.getCordovaInfo(),
+            Q('Cordova version: ' + package.version),
             //Get project config.xml file using ano
-             getProjectConfig(projectRoot),
+            getProjectConfig(projectRoot),
             //Get list of plugins
-            listPlugins(projectRoot), 
+            listPlugins(projectRoot),
             //Get Platforms information
             getPlatforms(projectRoot)
-        ]).then(function (promises) {
-        promises.forEach(function (p) {
-            output += (function () {
-                return p.state === "fulfilled" ? p.value + "\n\n" : p.state === "rejected" ? p.reason + "\n\n" : "Still working"
-            }
-                ());
+        ]).then(function(promises) {
+        promises.forEach(function(p) {
+            output += p.state === 'fulfilled' ? p.value + '\n\n' : p.reason + '\n\n';
+        });
+        console.info(output);
+        fs.writeFile(path.join(projectRoot, 'info.txt'), output, 'utf-8', function (err) {
+            if (err)
+                throw err;
         });
-        print_SaveMsg(projectRoot, output);
     });
 };
 
-function print_SaveMsg(projectRoot, data) {
-    console.info(data);
-    fs.writeFile(path.join(projectRoot, "info.txt"), data, "utf-8", function (err) {
-        if (err)
-            throw err;
-    });
-}
-
 function getPlatforms(projectRoot) {
-    var platforms = cordova_util.listPlatforms(projectRoot),
-        promises  = [];
-
+    var platforms = cordova_util.listPlatforms(projectRoot);
     if (platforms.length) {
-        platforms.forEach(function (platform) {
-            var deferred = Q.defer();
-            deferred.resolve(info_utils.getPlatformInfo(platform, projectRoot));
-            promises.push(deferred.promise);
+        return Q.all(platforms.map(function(p) {
+            return getPlatformInfo(p, projectRoot);
+        })).then(function(outs) {
+          return outs.join('\n\n');
         });
-    } else {
-        var deferred = Q.defer()
-            deferred.reject("No Platforms Currently Installed");
-        promises.push(deferred.promise);
     }
-
-    return Q.all(promises)
+    return Q.reject('No Platforms Currently Installed');
 }
 
 function listPlugins(projectRoot) {
-    var pluginPath = path.join(projectRoot, "plugins"),
-        plugins    = cordova_util.findPlugins(pluginPath),
-        deferred   = Q.defer();
+    var pluginPath = path.join(projectRoot, 'plugins'),
+        plugins    = cordova_util.findPlugins(pluginPath);
 
     if (!plugins.length) {
-        deferred.reject("No Plugins Currently Installed");
-    } else {
-        deferred.resolve("Plugins: \n\n" + plugins);
+        return Q.reject('No Plugins Currently Installed');
     }
-    return deferred.promise
+    return Q('Plugins: \n\n' + plugins);
 }
 
 function getProjectConfig(projectRoot) {
-    var deferred = Q.defer();
-
     if (!fs.existsSync(projectRoot)  ) {
-        deferred.reject("Config.xml file not found");
-    } else {
-        deferred.resolve("Config.xml file: \n\n" + (fs.readFileSync(cordova_util.projectConfig(projectRoot), "utf-8")));
+        return Q.reject('Config.xml file not found');
     }
-    return deferred.promise
+    return Q('Config.xml file: \n\n' + (fs.readFileSync(cordova_util.projectConfig(projectRoot), 'utf-8')));
 }