You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cordova.apache.org by an...@apache.org on 2015/05/29 12:03:50 UTC

cordova-wp8 git commit: CB-8954 Adds `requirements` command support to check_reqs module

Repository: cordova-wp8
Updated Branches:
  refs/heads/master 9abd0115a -> a90d167d6


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


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

Branch: refs/heads/master
Commit: a90d167d6f2b8bda87ab45825563656a54561f5d
Parents: 9abd011
Author: Vladimir Kotikov <v-...@microsoft.com>
Authored: Fri May 29 09:52:06 2015 +0300
Committer: Vladimir Kotikov <v-...@microsoft.com>
Committed: Fri May 29 09:52:36 2015 +0300

----------------------------------------------------------------------
 bin/lib/check_reqs.js | 107 +++++++++++++++++++++++++++++++++++++++++----
 bin/lib/create.js     |   6 ++-
 2 files changed, 104 insertions(+), 9 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cordova-wp8/blob/a90d167d/bin/lib/check_reqs.js
----------------------------------------------------------------------
diff --git a/bin/lib/check_reqs.js b/bin/lib/check_reqs.js
index c87a06f..31252b8 100644
--- a/bin/lib/check_reqs.js
+++ b/bin/lib/check_reqs.js
@@ -17,17 +17,108 @@
     under the License.
 */
 
-var Q     = require('Q'),
-    os    = require('os'),
+var Q = require('Q');
+
+var MSBuildTools;
+try {
     MSBuildTools = require('../../template/cordova/lib/MSBuildTools');
+} catch (ex) {
+    // If previous import fails, we're probably running this script
+    // from installed platform and the module location is different.
+    MSBuildTools = require('./MSBuildTools');
+}
+
+/**
+ * Check if current OS is supports building windows platform
+ * @return {Promise} Promise either fullfilled or rejected with error message.
+ */
+var checkOS = function () {
+    var platform = process.platform;
+    return (platform === 'win32') ?
+        Q.resolve(platform):
+        // Build Universal windows apps available for windows platform only, so we reject on others platforms
+        Q.reject('Cordova tooling for Windows requires Windows OS to build project');
+};
+
+/**
+ * Checks if MSBuild tools is available.
+ * @return {Promise} Promise either fullfilled with MSBuild version
+ *                           or rejected with error message.
+ */
+var checkMSBuild = function () {
+    return MSBuildTools.findAvailableVersion()
+    .then(function (msbuildTools) {
+        return Q.resolve(msbuildTools.version);
+    }, function () {
+        return Q.reject('MSBuild tools not found. Please install MSBuild tools or VS 2013 from ' +
+            'https://www.visualstudio.com/downloads/download-visual-studio-vs');
+    });
+};
 
 module.exports.run = function () {
-    if (os.platform() != 'win32'){
-      // Build Universal windows apps available for windows platform only, so we reject on others platforms
-        return Q.reject('ERROR: Cordova tooling for Windows requires Windows OS');
-    }
-    // Check whther MSBuild Tools are available
-    return MSBuildTools.findAvailableVersion();
+    return checkOS().then(function () {
+        // Check whether MSBuild Tools are available
+        return MSBuildTools.findAvailableVersion();
+    });
+};
+
+/**
+ * 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', 'Windows OS', true),
+        new Requirement('msbuild', 'MSBuild Tools')
+    ];
+
+    var result = [];
+    var fatalIsHit = false;
+
+    // Define list of checks needs to be performed
+    var checkFns = [checkOS, checkMSBuild];
+    // 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;
+    });
 };
 
 module.exports.help = function () {

http://git-wip-us.apache.org/repos/asf/cordova-wp8/blob/a90d167d/bin/lib/create.js
----------------------------------------------------------------------
diff --git a/bin/lib/create.js b/bin/lib/create.js
index ae11869..281cd00 100644
--- a/bin/lib/create.js
+++ b/bin/lib/create.js
@@ -70,6 +70,10 @@ module.exports.run = function (argv) {
     // CB-7618 node_modules must be copied to project folder
     shell.cp('-r', path.join(platformRoot, 'node_modules'), path.join(projectPath, 'cordova'));
 
+    // CB-8954 Copy check_reqs module, since it will be required by 'requirements' command
+    shell.cp('-r', path.join(platformRoot, 'bin', 'check_reqs*'), path.join(projectPath, 'cordova'));
+    shell.cp('-r', path.join(platformRoot, 'bin', 'lib', 'check_reqs*'), path.join(projectPath, 'cordova', 'lib'));
+
     // if any custom template is provided, just copy it over created project
     if (customTemplate && fs.existsSync(customTemplate)) {
         console.log('Copying template overrides from ' + customTemplate + ' to ' + projectPath);
@@ -122,4 +126,4 @@ module.exports.help = function () {
     console.log('examples:');
     console.log('    create C:\\Users\\anonymous\\Desktop\\MyProject');
     console.log('    create C:\\Users\\anonymous\\Desktop\\MyProject io.Cordova.Example AnApp');
-};
\ No newline at end of file
+};


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