cordova-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From an-s...@apache.org
Subject ios commit: CB-8954 Adds `requirements` command support to check_reqs module
Date Fri, 29 May 2015 09:56:00 GMT
Repository: cordova-ios
Updated Branches:
  refs/heads/master 27679a398 -> f9c6249f4


CB-8954 Adds `requirements` command support to check_reqs module


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

Branch: refs/heads/master
Commit: f9c6249f45dfdf71fd5346a549318d5c9ee335d9
Parents: 27679a3
Author: Vladimir Kotikov <v-vlkoti@microsoft.com>
Authored: Thu May 28 13:28:31 2015 +0300
Committer: Vladimir Kotikov <v-vlkoti@microsoft.com>
Committed: Fri May 29 12:55:43 2015 +0300

----------------------------------------------------------------------
 bin/lib/check_reqs.js | 108 ++++++++++++++++++++++++++++++++++++---------
 bin/lib/create.js     |   2 +-
 2 files changed, 88 insertions(+), 22 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cordova-ios/blob/f9c6249f/bin/lib/check_reqs.js
----------------------------------------------------------------------
diff --git a/bin/lib/check_reqs.js b/bin/lib/check_reqs.js
index 2f5897e..d1f6333 100644
--- a/bin/lib/check_reqs.js
+++ b/bin/lib/check_reqs.js
@@ -17,34 +17,30 @@
        under the License.
 */
 
-/* jshint node:true, bitwise:true, undef:true, trailing:true, quotmark:true,
-          indent:4, unused:vars, latedef:nofunc,
-          sub:true, laxcomma:true, laxbreak:true
-*/
-
 var Q     = require('q'),
-    os    = require('os'),
     shell = require('shelljs'),
     versions = require('./versions');
 
 var XCODEBUILD_MIN_VERSION = '4.6.0';
+var XCODEBUILD_NOT_FOUND_MESSAGE =
+    'Please install version ' + XCODEBUILD_MIN_VERSION + ' or greater from App Store';
 
 var IOS_SIM_MIN_VERSION = '3.0.0';
-var IOS_SIM_NOT_FOUND_MESSAGE = 'ios-sim was not found. Please download, build and install
version ' + IOS_SIM_MIN_VERSION +
-    ' or greater from https://github.com/phonegap/ios-sim into your path.' +
-    ' Or \'npm install -g ios-sim\' using node.js: http://nodejs.org';
+var IOS_SIM_NOT_FOUND_MESSAGE =
+    'Please download, build and install version ' + IOS_SIM_MIN_VERSION + ' or greater' +
+    ' from https://github.com/phonegap/ios-sim into your path, or do \'npm install -g ios-sim\'';
 
 var IOS_DEPLOY_MIN_VERSION = '1.4.0';
-var IOS_DEPLOY_NOT_FOUND_MESSAGE = 'ios-deploy was not found. Please download, build and
install version ' + IOS_DEPLOY_MIN_VERSION +
-    ' or greater from https://github.com/phonegap/ios-deploy into your path.' +
-    ' Or \'npm install -g ios-deploy\' using node.js: http://nodejs.org';
+var IOS_DEPLOY_NOT_FOUND_MESSAGE =
+    'Please download, build and install version ' + IOS_DEPLOY_MIN_VERSION + ' or greater'
+
+    ' from https://github.com/phonegap/ios-deploy into your path, or do \'npm install -g
ios-deploy\'';
 
 /**
  * Checks if xcode util is available
  * @return {Promise} Returns a promise either resolved with xcode version or rejected
  */
 module.exports.run = module.exports.check_xcodebuild = function () {
-    return checkTool('xcodebuild', XCODEBUILD_MIN_VERSION);
+    return checkTool('xcodebuild', XCODEBUILD_MIN_VERSION, XCODEBUILD_NOT_FOUND_MESSAGE);
 };
 
 /**
@@ -63,6 +59,13 @@ module.exports.check_ios_sim = function () {
     return checkTool('ios-sim', IOS_SIM_MIN_VERSION, IOS_SIM_NOT_FOUND_MESSAGE);
 };
 
+module.exports.check_os = function () {
+    // Build iOS apps available for OSX platform only, so we reject on others platforms
+    return process.platform === 'darwin' ?
+        Q.resolve(process.platform) :
+        Q.reject('Cordova tooling for iOS requires Apple OS X');
+};
+
 module.exports.help = function () {
     console.log('Usage: check_reqs or node check_reqs');
 };
@@ -71,24 +74,87 @@ module.exports.help = function () {
  * Checks if specific tool is available.
  * @param  {String} tool       Tool name to check. Known tools are 'xcodebuild', 'ios-sim'
and 'ios-deploy'
  * @param  {Number} minVersion Min allowed tool version.
- * @param  {String} optMessage Message that will be used to reject promise.
+ * @param  {String} message    Message that will be used to reject promise.
  * @return {Promise}           Returns a promise either resolved with tool version or rejected
  */
-function checkTool (tool, minVersion, optMessage) {
-    if (os.platform() !== 'darwin'){
-        // Build iOS apps available for OSX platform only, so we reject on others platforms
-        return Q.reject('Cordova tooling for iOS requires Apple OS X');
-    }
+function checkTool (tool, minVersion, message) {
     // Check whether tool command is available at all
     var tool_command = shell.which(tool);
     if (!tool_command) {
-        return Q.reject(optMessage || (tool + 'command is unavailable.'));
+        return Q.reject(tool + ' was not found. ' + (message || ''));
     }
     // check if tool version is greater than specified one
     return versions.get_tool_version(tool).then(function (version) {
+        version = version.trim();
         return versions.compareVersions(version, minVersion) >= 0 ?
             Q.resolve(version) :
             Q.reject('Cordova needs ' + tool + ' version ' + minVersion +
-              ' or greater, you have version ' + version + '.');
+              ' or greater, you have version ' + version + '. ' + (message || ''));
     });
 }
+
+/**
+ * Object that represents one of requirements for current platform.
+ * @param {String}  id        The unique identifier for this requirements.
+ * @param {String}  name      The name of requirements. Human-readable field.
+ * @param {Boolean} isFatal   Marks the requirement as fatal. If such requirement will fail
+ *                            next requirements' checks will be skipped.
+ */
+var Requirement = function (id, name, isFatal) {
+    this.id = id;
+    this.name = name;
+    this.installed = false;
+    this.metadata = {};
+    this.isFatal = isFatal || false;
+};
+
+/**
+ * Methods that runs all checks one by one and returns a result of checks
+ * as an array of Requirement objects. This method intended to be used by cordova-lib check_reqs
method
+ *
+ * @return Promise<Requirement[]> Array of requirements. Due to implementation, promise
is always fulfilled.
+ */
+module.exports.check_all = function() {
+
+    var requirements = [
+        new Requirement('os', 'Apple OS X', true),
+        new Requirement('xcode', 'Xcode'),
+        new Requirement('ios-deploy', 'ios-deploy'),
+        new Requirement('ios-sim', 'ios-sim')
+    ];
+
+    var result = [];
+    var fatalIsHit = false;
+
+    var checkFns = [
+        module.exports.check_os,
+        module.exports.check_xcodebuild,
+        module.exports.check_ios_deploy,
+        module.exports.check_ios_sim
+    ];
+
+    // Then execute requirement checks one-by-one
+    return checkFns.reduce(function (promise, checkFn, idx) {
+        return promise.then(function () {
+            // If fatal requirement is failed,
+            // we don't need to check others
+            if (fatalIsHit) return Q();
+
+            var requirement = requirements[idx];
+            return checkFn()
+            .then(function (version) {
+                requirement.installed = true;
+                requirement.metadata.version = version;
+                result.push(requirement);
+            }, function (err) {
+                if (requirement.isFatal) fatalIsHit = true;
+                requirement.metadata.reason = err;
+                result.push(requirement);
+            });
+        });
+    }, Q())
+    .then(function () {
+        // When chain is completed, return requirements array to upstream API
+        return result;
+    });
+};

http://git-wip-us.apache.org/repos/asf/cordova-ios/blob/f9c6249f/bin/lib/create.js
----------------------------------------------------------------------
diff --git a/bin/lib/create.js b/bin/lib/create.js
index cbffd63..fa8dd38 100755
--- a/bin/lib/create.js
+++ b/bin/lib/create.js
@@ -83,7 +83,7 @@ function copyScripts(projectPath) {
     shell.cp('-r', path.join(binDir, 'node_modules'), destScriptsDir);
 
     // Copy the check_reqs script
-    shell.cp(path.join(binDir, 'check_reqs'), destScriptsDir);
+    shell.cp(path.join(binDir, 'check_reqs*'), destScriptsDir);
     shell.cp(path.join(binDir, 'lib', 'check_reqs.js'), path.join(destScriptsDir, 'lib'));
 
     // Copy the version scripts


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


Mime
View raw message