cordova-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From an-s...@apache.org
Subject cordova-windows git commit: CB-9159 Fix WP8.1 deploy when 'window-target-version' is 10.0.
Date Tue, 21 Jul 2015 13:37:17 GMT
Repository: cordova-windows
Updated Branches:
  refs/heads/master fe43cb3e0 -> f2040afe6


CB-9159 Fix WP8.1 deploy when 'window-target-version' is 10.0.

This closes #91


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

Branch: refs/heads/master
Commit: f2040afe6a3679a0e89d315aa027620383b2820a
Parents: fe43cb3
Author: sgrebnov <v-segreb@microsoft.com>
Authored: Mon Jun 15 13:11:26 2015 +0300
Committer: Vladimir Kotikov <v-vlkoti@microsoft.com>
Committed: Tue Jul 21 16:38:28 2015 +0300

----------------------------------------------------------------------
 spec/unit/build.spec.js       |  19 +++++
 template/cordova/lib/build.js | 137 ++++++++++++++++++-------------------
 template/cordova/lib/run.js   |  74 ++++----------------
 3 files changed, 102 insertions(+), 128 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cordova-windows/blob/f2040afe/spec/unit/build.spec.js
----------------------------------------------------------------------
diff --git a/spec/unit/build.spec.js b/spec/unit/build.spec.js
index f698205..44f0a08 100644
--- a/spec/unit/build.spec.js
+++ b/spec/unit/build.spec.js
@@ -321,4 +321,23 @@ describe('run method', function() {
             done();
         });
     });
+
+    it('spec.13 should be able to override target via --appx parameter', function(done) {
+        var buildSpy = jasmine.createSpy().andCallFake(function(solutionFile, buildType,
buildArch) {
+                // check that we build Windows 10 and not Windows 8.1
+                expect(solutionFile.toLowerCase().indexOf('cordovaapp.windows10.jsproj')
>=0).toBe(true);
+            });
+
+        build.__set__('utils.isCordovaProject', isCordovaProjectTrue);
+        createFindAvailableVersionMock('14.0', testPath, buildSpy);
+        build.__set__('prepare.applyPlatformConfig', function() {} );
+        // provision config to target Windows 8.1
+        createConfigParserMock('8.1', '8.1');
+        // explicitly specify Windows 10 as target
+        build.run([ 'node', buildPath, '--appx=uap' ])
+        .finally(function() {
+            expect(buildSpy).toHaveBeenCalled();
+            done();
+        });
+    });
 });

http://git-wip-us.apache.org/repos/asf/cordova-windows/blob/f2040afe/template/cordova/lib/build.js
----------------------------------------------------------------------
diff --git a/template/cordova/lib/build.js b/template/cordova/lib/build.js
index 2313a70..b6eeff9 100644
--- a/template/cordova/lib/build.js
+++ b/template/cordova/lib/build.js
@@ -99,6 +99,72 @@ module.exports.help = function help() {
     process.exit(0);
 };
 
+// returns list of projects to be built based on config.xml and additional parameters (-appx)
+module.exports.getBuildTargets  = function(isWinSwitch, isPhoneSwitch, projOverride) {
+
+    // apply build target override if one was specified
+    if (projOverride) {
+        switch (projOverride.toLowerCase()) {
+            case '8.1-phone':
+                return [projFiles.phone];
+            case '8.1-win':
+                return [projFiles.win];
+            case 'uap':
+                return [projFiles.win10];
+            default:
+                console.warn('Unrecognized --appx parameter passed to build: "' + projOverride
+ '", ignoring.');
+                break;
+        }
+    }
+    
+    var configXML = new ConfigParser(path.join(ROOT, 'config.xml'));
+    var targets = [];
+    var noSwitches = !(isPhoneSwitch || isWinSwitch);
+
+    // Windows
+    if (isWinSwitch || noSwitches) { // if --win or no arg
+        var windowsTargetVersion = configXML.getWindowsTargetVersion();
+        switch(windowsTargetVersion.toLowerCase()) {
+        case '8':
+        case '8.0':
+            targets.push(projFiles.win80);
+            break;
+        case '8.1':
+            targets.push(projFiles.win);
+            break;
+        case '10.0':
+        case 'uap':
+            targets.push(projFiles.win10);
+            break;
+        default:
+            throw new Error('Unsupported windows-target-version value: ' + windowsTargetVersion);
+        }
+    }
+
+    // Windows Phone
+    if (isPhoneSwitch || noSwitches) { // if --phone or no arg
+        var windowsPhoneTargetVersion = configXML.getWindowsPhoneTargetVersion();
+        switch(windowsPhoneTargetVersion.toLowerCase()) {
+        case '8.1':
+            targets.push(projFiles.phone);
+            break;
+        case '10.0':
+        case 'uap':
+            if (targets.indexOf(projFiles.win10) < 0) {
+                // Already built due to --win or no switches
+                // and since the same thing can be run on Phone as Windows,
+                // we can skip this one.
+                targets.push(projFiles.win10);
+            }
+            break;
+        default:
+            throw new Error('Unsupported windows-phone-target-version value: ' + windowsPhoneTargetVersion);
+        }
+    }
+
+    return targets;
+};
+
 function parseAndValidateArgs(argv) {
     return Q.promise(function(resolve, reject) {
         // parse and validate args
@@ -133,7 +199,7 @@ function parseAndValidateArgs(argv) {
         config.buildArchs = args.archs ? args.archs.split(' ') : ['anycpu'];
         config.phone = args.phone ? true : false;
         config.win = args.win ? true : false;
-        config.projVerOverride = args.appx;
+        config.projOverride = args.appx;
 
         // if build.json is provided, parse it
         var buildConfigPath = args.buildConfig;
@@ -204,7 +270,7 @@ function parseBuildConfig(buildConfigPath, config) {
 
 function buildTargets(msbuild, config) {
     // filter targets to make sure they are supported on this development machine
-    var myBuildTargets = filterSupportedTargets(getBuildTargets(config), msbuild);
+    var myBuildTargets = filterSupportedTargets(module.exports.getBuildTargets(config.win,
config.phone, config.projOverride), msbuild);
 
     var buildConfigs = [];
 
@@ -234,73 +300,6 @@ function buildTargets(msbuild, config) {
     }, Q());
 }
 
-function getBuildTargets(buildConfig) {
-    var configXML = new ConfigParser(path.join(ROOT, 'config.xml'));
-    var targets = [];
-    var noSwitches = !(buildConfig.phone || buildConfig.win);
-
-    // Windows
-    if (buildConfig.win || noSwitches) { // if --win or no arg
-        var windowsTargetVersion = configXML.getWindowsTargetVersion();
-        switch(windowsTargetVersion) {
-        case '8':
-        case '8.0':
-            targets.push(projFiles.win80);
-            break;
-        case '8.1':
-            targets.push(projFiles.win);
-            break;
-        case '10.0':
-        case 'UAP':
-            targets.push(projFiles.win10);
-            break;
-        default:
-            throw new Error('Unsupported windows-target-version value: ' + windowsTargetVersion);
-        }
-    }
-
-    // Windows Phone
-    if (buildConfig.phone || noSwitches) { // if --phone or no arg
-        var windowsPhoneTargetVersion = configXML.getWindowsPhoneTargetVersion();
-        switch(windowsPhoneTargetVersion) {
-        case '8.1':
-            targets.push(projFiles.phone);
-            break;
-        case '10.0':
-        case 'UAP':
-            if (!buildConfig.win && !noSwitches) {
-                // Already built due to --win or no switches
-                // and since the same thing can be run on Phone as Windows,
-                // we can skip this one.
-                targets.push(projFiles.win10);
-            }
-            break;
-        default:
-            throw new Error('Unsupported windows-phone-target-version value: ' + windowsPhoneTargetVersion);
-        }
-    }
-
-    // apply build target override if one was specified
-    if (buildConfig.projVerOverride) {
-        switch (buildConfig.projVerOverride) {
-            case '8.1-phone':
-                targets = [projFiles.phone];
-                break;
-            case '8.1-win':
-                targets = [projFiles.win];
-                break;
-            case 'uap':
-                targets = [projFiles.win10];
-                break;
-            default:
-                console.warn('Unrecognized --appx parameter passed to build: "' + buildConfig.projVerOverride
+ '", ignoring.');
-                break;
-        }
-    }
-
-    return targets;
-}
-
 // TODO: Fix this so that it outlines supported versions based on version criteria:
 // - v14: Windows 8.1, Windows 10
 // - v12: Windows 8.1, Windows 8.0

http://git-wip-us.apache.org/repos/asf/cordova-windows/blob/f2040afe/template/cordova/lib/run.js
----------------------------------------------------------------------
diff --git a/template/cordova/lib/run.js b/template/cordova/lib/run.js
index 14f5a6e..0988cf9 100644
--- a/template/cordova/lib/run.js
+++ b/template/cordova/lib/run.js
@@ -22,7 +22,6 @@ var Q = require('q'),
     path  = require('path'),
     build = require('./build'),
     utils = require('./utils'),
-    ConfigParser = require('./ConfigParser'),
     packages = require('./package'),
     execSync = require('child_process').execSync;
 
@@ -59,50 +58,17 @@ module.exports.run = function (argv) {
     // Get build/deploy options
     var buildType    = args.release ? 'release' : 'debug',
         buildArchs   = args.archs ? args.archs.split(' ') : ['anycpu'],
-        projectType  = args.phone ? 'phone' : 'windows',
-        deployTarget = args.target ? args.target : (args.emulator ? 'emulator' : 'device'),
-        projOverride = args.appx;
-
-    // for win switch we should correctly handle 8.0 and 8.1 version as per configuration
-    // as well as 10
-    var targetWindowsVersion = getWindowsTargetVersion();
-    if (projectType == 'windows') {
-        if (targetWindowsVersion == '8.0') {
-            projectType = 'windows80';
-        }
-        else if (targetWindowsVersion === '10.0') {
-            projectType = 'windows10';
-        }
-    }
-    else if (projectType === 'phone') {
-        if (targetWindowsVersion === '10.0' || targetWindowsVersion === 'UAP') {
-            projectType = 'windows10';
-        }
-    }
+        deployTarget = args.target ? args.target : (args.emulator ? 'emulator' : 'device');
 
-    if (projOverride) {
-        switch (projOverride) {
-            case '8.1-phone':
-                projectType = 'phone';
-                targetWindowsVersion = '8.1';
-                break;
-            case '8.1-win':
-                projectType = 'windows';
-                targetWindowsVersion = '8.1';
-                break;
-            case 'uap':
-                projectType = 'windows10';
-                break;
-            default:
-                console.warn('Unrecognized --appx parameter passed to run: "' + projOverride
+ '", ignoring.');
-                break;
-        }
-    }
+     var buildTargets = build.getBuildTargets(args.win, args.phone, args.appx);
 
-    if (projectType == 'windows' && getWindowsTargetVersion() == '8.0') {
-        console.log('Warning: windows8 has been deprecated.  Please update you project to
target windows8.1');
-        projectType = 'windows80';
-    }
+     if (!buildTargets || buildTargets.lenght <= 0) {
+         return Q.reject('Unable to determine deploy target.');
+     }
+
+     // we deploy the first build target so we use buildTargets[0] to determine
+     // what project type we should deploy
+     var projectType = projFileToType(buildTargets[0]);
 
     // if --nobuild isn't specified then build app first
     var buildPackages = args.nobuild ? Q() : build.run(argv);
@@ -172,20 +138,10 @@ module.exports.help = function () {
     process.exit(0);
 };
 
-
-function getWindowsTargetVersion() {
-    var config = new ConfigParser(path.join(ROOT, 'config.xml'));
-    var windowsTargetVersion = config.getWindowsTargetVersion();
-    switch(windowsTargetVersion) {
-        case '8':
-        case '8.0':
-            return '8.0';
-        case '8.1':
-            return '8.1';
-        case '10.0':
-        case 'UAP':
-            return '10.0';
-        default:
-            throw new Error('Unsupported windows-target-version value: ' + windowsTargetVersion);
-    }
+// Retrieves project type for the project file specified.
+// @param   {String}  projFile Project file, for example 'CordovaApp.Windows10.jsproj'
+// @returns {String}  Proejct type, for example 'windows10'
+function projFileToType(projFile) 
+{
+    return projFile.replace(/CordovaApp|jsproj|\./gi, '').toLowerCase();
 }


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


Mime
View raw message