Github user martincgg commented on a diff in the pull request: https://github.com/apache/cordova-cli/pull/152#discussion_r11086870 --- Diff: src/info-utils.js --- @@ -0,0 +1,150 @@ +/** + 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 cordova_util = require('./util'), +child_process = require('child_process'), +path = require('path'), +fs = require('fs'), +_self; + +_self = { +getNodeInfo: function( callback ){ + callback(_self.execFunc('node', '--version', function(call){callback(call);})); + }, + +getCordovaInfo: function( callback ){ + callback(_self.execFunc('cordova', '--version', function(call){callback(call);})); + }, + +getPlatformInfo: function(platform, projectRoot, callback ){ + var command="", args=""; + switch( platform ){ + case "ios": + _self.execFunc('xcodebuild', '-version', function(call){callback('iOS Platform:\r\r' +call);}); + break; + case "android": + _self.execFunc('android', 'list target', function(call){callback('Android Platform:\r\r' +call);}); + break; + case "blackberry10": + var bbUtilsPath = path.join(projectRoot, 'platforms', platform, 'cordova'), + bbBuildPath= path.join(projectRoot, 'platforms', platform, 'build'), + bbresults="", + varState; + //get CORDOVA_BBTOOLS environment variable. + _self.get_pathEnv( ['blackberry-nativepackager', 'blackberry-deploy'], function (path){ + if(path){ + //s et CORDOVA_BBTOOLS environment variable. + varState = _self.setEnv_Var('CORDOVA_BBTOOLS', path, false); + // Get BB10 SDK Version + _self.getSDKinfo(bbUtilsPath, function(result){ + if(result){bbresults+="Blackberry 10 Native SDK version: "+result+"\r"; + // Get BB10 deployed and stored devices + _self.deployedDevices(bbUtilsPath, 'device', false, function(result){ + if(result){bbresults+="\rBlackberry 10 deployed devices:\r"+result+"\r"; + // Get BB10 deployed and stored emulators + _self.deployedDevices(bbUtilsPath, 'emulator', false, function (result){ + if(result){bbresults+="\rBlackberry deployed emulator:\r"+result+"\r"; + if(!varState){_self.delEnv_Var('CORDOVA_BBTOOLS');} + callback('Blackberry 10 Platform:\r\r' +bbresults); + }}); + }}); + }}); + } + else{callback("Blackberry 10 Native SDK path not found");} + }); + break; + } + }, + // Execute using a child_process exec, for any async command +execFunc: function(command, args, callback){ + child_process.exec(command + ' ' +args, + function (error, stdout, stderr) { + callback(stdout); + if (error !== null) { + callback('Error performing command: ' + error + "\n" +stderr); + } + }); + }, + //Uses Library to get Native SDK version +getSDKinfo: function ( utilsPath, callback) { + _self.execFunc("\"" +path.join(utilsPath,'bb10-ndk-version')+"\"" , '' ,function(output){callback(output);}); + }, + // It explores the json file to get deployed devices or emulators. +deployedDevices: function ( utilsPath, type, flag, callback) { + var collection=""; + require(path.join(utilsPath,'lib', 'target-utils')).getTargetList( type, flag, function (resultList) { + if(resultList.length>0){ + for (var t in resultList) { + if (resultList.hasOwnProperty(t)) { + collection+= resultList[t].name + ' ip: ' + resultList[t].ip+"\r"; + } + } + }else{collection+='No registered emulators or devices\r';} + }); + callback(collection); + }, + + delEnv_Var: function (ENV_VAR){ + delete process.env[ENV_VAR]; + }, + //Sets an environmental variable, determining first if exists or not + //uses boolean 'override' to decide if override the value or not. + setEnv_Var: function ( ENV_VAR, value, override) { + //Check if Env varible exists first + if(_self.determineEnv_Var(ENV_VAR)){ + console.log("CORDOVA_BBTOOLS env variable is present\r"); + if(override){ + console.log("\rOverriding... "); + process.env[ENV_VAR] = value;} + return true; + }else{ process.env[ENV_VAR] = value; return false;} + }, + //Determine if an environmental variable exists + determineEnv_Var: function ( ENV_VAR ){ + if(process.env[ENV_VAR]){ + return true; + }else{ return false; } + return false; + }, + + get_pathEnv: function (files, callback) { --- End diff -- Well, I'm setting or adjusting that variable 'CORDOVA_BBTOOLS', because is used by a file called 'target-utils.js', which belongs to the blackberry library, if it were my call, I rather to use just the path with what I need to do, instead of set a variable, but to do so I need to modify the logic in the blackberry library, that's why I'm doing it in that way. target-utils.js reference. https://github.com/apache/cordova-blackberry/blob/master/blackberry10/bin/templates/project/cordova/lib/target-utils.js#L86 https://github.com/apache/cordova-blackberry/blob/master/blackberry10/bin/templates/project/cordova/lib/target-utils.js#L247 I'm using that file, which contains logic to get some information, instead of duplicate code, I'm adjusting my program to it. I know that shelljs.which it looks for the for an exe, bat, or cmd file in the whole path, which is really good, I've create my own function because I didn't know about shelljs.which. get_pathEnv, it gets the Env path, and it looks for files which should be located in that path. https://github.com/martincgg/cordova-cli/blob/CB-5082/src/info-utils.js#L125 Those files it can be sent in an array: https://github.com/martincgg/cordova-cli/blob/CB-5082/src/info-utils.js#L49 In the code, I've set two files as you can see in the line, I just want to make sure that is the right file. determine_Env_Var it only looks if the variable is set or not, just that. Here, I determine if the variable is currently set: https://github.com/martincgg/cordova-cli/blob/CB-5082/src/info-utils.js#L118 If that variable is already set, I'm not going to touch it. Here, is deciding if is going to be erased or not: https://github.com/martincgg/cordova-cli/blob/CB-5082/src/info-utils.js#L62 If the variable it was set before the program executions, is not going to erase it, but if it was set just to execute this js file, is going to erase it in order to not affect or impact in any other process. Here's going to delete the variable https://github.com/martincgg/cordova-cli/blob/CB-5082/src/info-utils.js#L102 Is going to unset the variable. Most of those functions, I've added them like part of the object, because it can useful for another js file. Well, Andrew what are my options with this, go to blackberry library and change the target-utils.js file and set that instead of use an environmental variable it uses just the path, and also set the function to accept an argument as the path?
--- If your project is set up for it, you can reply to this email and have your reply appear on GitHub as well. If your project does not have this feature enabled and wishes so, or if the feature is enabled but not working, please contact infrastructure at infrastruct...@apache.org or file a JIRA ticket with INFRA. ---