Skip to content

Instantly share code, notes, and snippets.

@FokkeZB
Last active November 20, 2015 08:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save FokkeZB/6a8c503d2c3ce69d11bb to your computer and use it in GitHub Desktop.
Save FokkeZB/6a8c503d2c3ce69d11bb to your computer and use it in GitHub Desktop.
Check for minimum Alloy version needed to compile a (sample) project

Set minVersion in app/config.json and it will fail with:

[INFO]  Found Alloy app in /Users/fokkezb/dev/samples/appc-sample-3dtouch/app
[INFO]  Executing Alloy compile: /usr/local/bin/node /Users/fokkezb/.appcelerator/install/5.0.4/package/node_modules/appc-cli-titanium/node_modules/alloy/bin/alloy compile /Users/fokkezb/dev/samples/appc-sample-3dtouch/app --config platform=ios,version=0,simtype=none,devicefamily=iphone,deploytype=development,target=simulator
[INFO]   [config.json] regenerating CFG.js from config.json...
[ERROR] ------------------------------------------
[ERROR] This sample requires Alloy 1.7.25 or later
[ERROR] ------------------------------------------
[ERROR] Alloy compiler failed
ERROR  | ti run exited with error code 1
var path = require('path');
task('pre:load', function(event, logger) {
if (!event.minVersion) {
return;
}
var minVersion = splitVersion(event.minVersion);
var binPath = process.mainModule.filename;
var pkgPath = path.join(binPath, '..', '..', 'package.json');
var pkg = require(pkgPath);
var version = splitVersion(pkg.version);
if (version[0] < minVersion[0] || version[1] < minVersion[1] || version[2] < minVersion[2]) {
var error = 'This sample requires Alloy ' + minVersion.join('.') + ' or later';
var line = (new Array(error.length + 1)).join('-');
logger.error(line);
logger.error(error);
logger.error(line);
process.exit(1);
}
});
function splitVersion(version) {
return version.split(/[^0-9]+/).map(function(element) {
return parseInt(element, 10);
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment