[ 
https://issues.apache.org/jira/browse/CB-6329?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13959046#comment-13959046
 ] 

ASF GitHub Bot commented on CB-6329:
------------------------------------

Github user martincgg commented on a diff in the pull request:

    https://github.com/apache/cordova-cli/pull/151#discussion_r11264328
  
    --- Diff: src/info.js ---
    @@ -16,123 +16,99 @@
         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
    -*/
    +    var cordova_util  = require('./util'),
    +        path          = require('path'),
    +        fs            = require('fs'),
    +        child_process = require('child_process'),
    +        Q             = require('q'),
    +        info_utils           = require('./info-utils');
    +
    +    /*
    +        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 raw = fs.readFileSync(path.join(__dirname, '..', 'doc', 
'info.txt'), 'utf-8').split("\n"),
    +        //Get projectRoot 
    +        var projectRoot = cordova_util.cdProjectRoot(),
             output;
    -
    -    output = raw.map(function(line) {
    -        if(line.match('    %') ) {
    -            var type = (line.substr(5)).replace("\r",""),
    -                out = "";
    -
    -            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;
    -            }
    -            return line.replace( "%"+type, out );
    -        } else {
    -            return line;
    +        if (!projectRoot) {
    +            return Q.reject( new Error('Current working directory is not a 
Cordova-based project.') );
             }
    -    }).join("\n");
     
    -    // /*
    -    //     Write to File;
    -    // */
    -    events.emit('results', output);
    -    fs.writeFileSync('info.txt', output );
    -    return Q();
    +        delLog(projectRoot);
    +        //Array of functions, Q.allSettled
    +        return Q.allSettled([ (function (){
    +            console.log("Collecting Data...");
    +            //Get Node version
    +            return (Q.denodeify (info_utils.getNodeInfo)());
    +        }()), (function (){
    +            //Get Cordova version
    +            return (Q.denodeify (info_utils.getCordovaInfo)());
    +        }()), (function (){
    +           //Get project config.xml file
    +           return 'Config.xml File: \n\n'+ 
(fs.readFileSync(cordova_util.projectConfig(projectRoot), 'utf-8')) +'\n\n\n'
    +        }()), (function (){
    +             //Get list of plugins
    +            return 'Plugins: \n\n' + doPlugins( projectRoot ) +'\n\n\n';
    +        }()), (function (){
    +            //Get Platforms information
    +            return (Q.denodeify (doPlatforms)(projectRoot));
    +        }())]).then(function (promises){
    +            for(var t in promises)
    +            print_SaveMsg( projectRoot, (function (){ return 
promises[t].state==='fulfilled' ? promises[t].value : 
promises[t].state==='rejected' ? promises[t].reason : 'Still working' }()) );
    +       });
     };
     
    -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;
    +    function delLog(projectRoot){
    +        if(fs.existsSync(path.join(projectRoot,'info.txt'))){
    +            fs.unlink(path.join(projectRoot,'info.txt'), function (err) {
    +                if (err) {throw err; console.log("Unable to delete 
info.txt file \n");}
    +                writeLog(projectRoot, '');
    +            });
    +        }else{writeLog(projectRoot, '');}
         }
    +    function writeLog (projectRoot, data){
    +        //Successfully deleted, writing new one
    +        fs.writeFile(path.join(projectRoot,'info.txt'), data, 'utf-8', 
function (err) {
    +            if (err) throw err;
    +        });
    +    }
    +    function print_SaveMsg(projectRoot, data){
    +        console.info(data);
    +        appendLog(projectRoot,data)
    +    }
    +    function appendLog(projectRoot, data){
    --- End diff --
    
    Well, I'm wrong, I cannot delete appendLog function, each promise result is 
store one at the time, so I'm sending to print into console and to write it 
into the fille as well.
    What do you recommend? save all promises values/reasons into a temporal 
value and then writeFileSync(path, alldata, utf-8); ??
    I can do it without any problem.


> [cordova-cli] improve 'cordova info' command to work asynchronous
> -----------------------------------------------------------------
>
>                 Key: CB-6329
>                 URL: https://issues.apache.org/jira/browse/CB-6329
>             Project: Apache Cordova
>          Issue Type: Improvement
>          Components: CLI
>    Affects Versions: 3.4.0
>            Reporter: Martin Gonzalez
>            Assignee: Martin Gonzalez
>              Labels: blackberry, cordova-cli, environment, info, wp8
>             Fix For: 3.5.0
>
>
> The 'cordova info' command it works in total sync, it takes some time to pull 
> and push all data from the environment, so in order to use callbacks more 
> friendly, I'd like to modify the flow structure of the file and improve it to 
> use get callback outputs, write summary or log file without templates.
> I also, I'd like to add a secondary file that holds all specific functions 
> related with 'get information about the dev environment'.



--
This message was sent by Atlassian JIRA
(v6.2#6252)

Reply via email to