This repository has been archived by the owner on Aug 11, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #263 from daserge/check-arch
Adds a windows pre compile/run hook to ensure an arch is specified
- Loading branch information
Showing
2 changed files
with
54 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
module.exports = function(ctx) { | ||
if (ctx.opts && ctx.opts.platforms && ctx.opts.platforms.indexOf('windows') > -1 | ||
&& ctx.opts.options) { | ||
var path = require('path'); | ||
var shell = ctx.requireCordovaModule('shelljs'); | ||
var nopt = ctx.requireCordovaModule('nopt'); | ||
|
||
// parse and validate args | ||
var args = nopt({ | ||
'archs': [String], | ||
'appx': String, | ||
'phone': Boolean, | ||
'win': Boolean, | ||
'bundle': Boolean, | ||
'packageCertificateKeyFile': String, | ||
'packageThumbprint': String, | ||
'publisherId': String, | ||
'buildConfig': String | ||
}, {}, ctx.opts.options.argv, 0); | ||
|
||
// Check if --appx flag is passed so that we have a project build version override: | ||
var isWin10 = args.appx && args.appx.toLowerCase() === 'uap'; | ||
|
||
// Else check "windows-target-version" preference: | ||
if (!isWin10) { | ||
var configXml = shell.ls(path.join(ctx.opts.projectRoot, 'config.xml'))[0]; | ||
|
||
var reTargetVersion = /<preference\s+name="windows-target-version"\s+value="(.+)"\s*\/>/i; | ||
var targetVersion = shell.grep(reTargetVersion, configXml); | ||
|
||
var result = reTargetVersion.exec(targetVersion); | ||
if (result !== null) { | ||
var match = result[1]; | ||
isWin10 = parseInt(match.split('.'), 10) > 8; | ||
} | ||
} | ||
|
||
// Non-AnyCPU arch is required for Windows 10 (UWP) projects only: | ||
if (isWin10) { | ||
var rawArchs = ctx.opts.options.archs || args.archs; | ||
var archs = rawArchs ? rawArchs.split(' ') : []; | ||
|
||
// Avoid "anycpu" arch: | ||
if (archs.length === 0 || archs.some(function (item) { | ||
return item.toLowerCase() === 'anycpu'; | ||
})) { | ||
throw new Error('You must specify an architecture to include the proper ZXing library version.' | ||
+ '\nUse \'cordova run windows -- --arch="x64"\' or \'cordova run windows -- --arch="arm" --phone --device\' for example.'); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters