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:52 UTC
[2/2] git commit: CB-6329 Clean-up of cordova info changes previously
merged.
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')));
}