Skip to content

Commit

Permalink
Merge pull request #130 from appcelerator/timob-16052
Browse files Browse the repository at this point in the history
[TIMOB-16052] Added support for Titanium SDKs that can be named anything...
  • Loading branch information
skypanther committed May 9, 2014
2 parents 6a7e952 + 548fb30 commit e8ff06f
Show file tree
Hide file tree
Showing 6 changed files with 73 additions and 59 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Expand Up @@ -7,6 +7,7 @@
* Added conflicting hook detection and improved hook error reporting [TIMOB-13847]
* Added support for an array of hook events to emit; needed for [TIMOB-10752]
* Updated Appcelerator API URLs to api.appcelerator.com [TIMOB-16282]
* Added support for Titanium SDKs that can be named anything [TIMOB-16052]

3.2.3 (5/1/2014)
-------------------
Expand Down
6 changes: 3 additions & 3 deletions hooks/tisdk3fixes.js
Expand Up @@ -17,7 +17,7 @@ exports.cliVersion = '>=3.2';

exports.init = function (logger, config, cli) {
cli.on('cli:go', function () {
var sdk = (cli.sdk && cli.sdk.name) || (cli.manifest && cli.manifest.version);
var sdk = (cli.sdk && (cli.sdk.manifest && cli.sdk.manifest.version || cli.sdk.name)) || (cli.manifest && cli.manifest.version);

// starting in 3.2.1, we "fixed" the hook system, but 3.2.0 and older use the
// old hook syntax, so we need to preserve it
Expand All @@ -33,7 +33,7 @@ exports.init = function (logger, config, cli) {
});

cli.on('cli:pre-validate', function (data) {
var sdk = (cli.sdk && cli.sdk.name) || (cli.manifest && cli.manifest.version);
var sdk = (cli.sdk && (cli.sdk.manifest && cli.sdk.manifest.version || cli.sdk.name)) || (cli.manifest && cli.manifest.version);

// there was a bug in 3.2.0 where the --store-password was being forced to
// --password when forking the correct SDK command with a SDK >= 3.2.0, so we
Expand All @@ -44,7 +44,7 @@ exports.init = function (logger, config, cli) {
});

cli.on('cli:post-validate', function (data) {
var sdk = (cli.sdk && cli.sdk.name) || (cli.manifest && cli.manifest.version);
var sdk = (cli.sdk && (cli.sdk.manifest && cli.sdk.manifest.version || cli.sdk.name)) || (cli.manifest && cli.manifest.version);

if (sdk && appc.version.gte(sdk, '3.0.0') && appc.version.lt(sdk, '3.2.0') && data.command.platform && /^ios|iphone$/.test(data.command.platform.name)) {
// in the iOS build for SDK 3.0.0 through 3.1.x, the valid deploy types
Expand Down
29 changes: 16 additions & 13 deletions lib/commands/info.js
Expand Up @@ -171,15 +171,17 @@ exports.run = function (logger, config, cli, finished) {
result.titaniumCLI.nodeAppcVer = require('node-appc/package.json').version;
} catch (e) {}

Object.keys(env.sdks).forEach(function (ver) {
var n = env.sdks[ver];
v = result.titanium[ver] = {
path: n.path,
platforms: Object.keys(n.platforms),
githash: n.manifest ? n.manifest.githash : null,
timestamp: n.manifest ? n.manifest.timestamp : null,
nodeAppcVer: null
};
Object.keys(env.sdks).forEach(function (name) {
var n = env.sdks[name],
ver = n.manifest && n.manifest.version || name,
v = result.titanium[name] = {
version: ver,
path: n.path,
platforms: Object.keys(n.platforms),
githash: n.manifest ? n.manifest.githash : null,
timestamp: n.manifest ? n.manifest.timestamp : null,
nodeAppcVer: null
};
try {
v.nodeAppcVer = require(path.join(v.path, 'node_modules', 'node-appc', 'package.json')).version;
} catch (e) {}
Expand All @@ -200,15 +202,16 @@ exports.run = function (logger, config, cli, finished) {

logger.log(styleHeading(__('Titanium SDKs')));
if (Object.keys(this.data.titanium).length) {
Object.keys(this.data.titanium).sort().reverse().forEach(function (ver) {
var x = this.data.titanium[ver];
Object.keys(this.data.titanium).sort().reverse().forEach(function (name) {
var x = this.data.titanium[name];
logger.log(
' ' + ver.cyan + '\n' +
' ' + name.cyan + '\n' +
' ' + rpad(' ' + __('Version')) + ' = ' + styleValue(x.version) + '\n' +
' ' + rpad(' ' + __('Install Location')) + ' = ' + styleValue(x.path) + '\n' +
' ' + rpad(' ' + __('Platforms')) + ' = ' + styleValue(x.platforms.join(', ')) + '\n' +
' ' + rpad(' ' + __('git Hash')) + ' = ' + styleValue(x.githash || 'unknown') + '\n' +
' ' + rpad(' ' + __('git Timestamp')) + ' = ' + styleValue(x.timestamp || 'unknown') + '\n' +
' ' + rpad(' ' + __('node-appc Version')) + ' = ' + styleValue(appc.version.lt(ver, '3.0.0') ? 'n/a' : x.nodeAppcVer || 'unknown')
' ' + rpad(' ' + __('node-appc Version')) + ' = ' + styleValue(appc.version.lt(x.version, '3.0.0') ? 'n/a' : x.nodeAppcVer || 'unknown')
);
}, this);
logger.log();
Expand Down
3 changes: 2 additions & 1 deletion lib/commands/sdk.js
Expand Up @@ -329,7 +329,8 @@ SdkSubcommands.select = {
var selectedSDK = cli.argv.version,
// we only care about SDKs that are 3.0 or newer
vers = Object.keys(cli.env.sdks).filter(function (v) {
return appc.version.gte(v, '3.0.0');
var s = cli.env.sdks[v];
return appc.version.gte(s.manifest && s.manifest.version || s.name, '3.0.0');
}).sort().reverse(),
activeSDK = config.get('sdk.selected', config.get('app.sdk', 'latest')) == 'latest' && vers.length ? vers[0] : config.get('sdk.selected', config.get('app.sdk')),
activeLabel = ' [' + __('selected') + ']',
Expand Down
88 changes: 47 additions & 41 deletions lib/commands/setup.js
Expand Up @@ -187,11 +187,8 @@ function SetupScreens(logger, config, cli) {
var activeSdk = cli.env.getSDK(config.get('sdk.selected', config.get('app.sdk', 'latest'))),
activeSdkLabel = ' [' + __('active') + ']',
sdkVersions = Object.keys(cli.env.sdks).filter(function (v) {
return appc.version.gte(v, '3.0.0');
}).sort().reverse(),
sdkVersionMaxlen = sdkVersions.reduce(function (a, b) {
return Math.max(a, b.length + (activeSdk && b == activeSdk.name ? activeSdkLabel.length : 0));
}, 0);
return appc.version.gte(cli.env.sdks[v].manifest && cli.env.sdks[v].manifest.version || v, '3.0.0');
}).sort().reverse();

this._registry = {
'user': {
Expand Down Expand Up @@ -248,36 +245,43 @@ function SetupScreens(logger, config, cli) {
})
},
'sdk': {
'selected': sdkVersions.length && fields.select({
default: activeSdk && activeSdk.name || 'latest',
label: __('What Titanium SDK would you like to use by default?'),
complete: true,
completeIgnoreCase: true,
suggest: true,
suggestThreshold: 2,
numbered: true,
margin: '',
formatters: {
option: function (opt, idx, num) {
var d = activeSdk && opt.value == activeSdk.name ? activeSdkLabel : '',
n = sdkVersionMaxlen + 2 - opt.value.length - d.length;
return num + opt.value.cyan + d.grey + new Array(n + 1).join(' ') + opt.path;
}
},
promptLabel: __('Enter # or SDK name'),
optionLabel: 'value',
options: sdkVersions.map(function (sdk) {
return { path: cli.env.sdks[sdk].path, value: sdk };
}.bind(this)),
validate: function (value) {
if (sdkVersions.indexOf(value) == -1) {
throw new Error(__('Invalid Titanium SDK'));
'selected': function () {
var selectedSdk = cli.env.getSDK(config.get('sdk.selected', config.get('app.sdk', 'latest'))),
sdkVersionMaxlen = sdkVersions.reduce(function (a, b) {
return Math.max(a, b.length + (activeSdk && b == activeSdk.name ? activeSdkLabel.length : 0));
}, 0);

return sdkVersions.length && fields.select({
default: selectedSdk && selectedSdk.name || 'latest',
label: __('What Titanium SDK would you like to use by default?'),
complete: true,
completeIgnoreCase: true,
suggest: true,
suggestThreshold: 2,
numbered: true,
margin: '',
formatters: {
option: function (opt, idx, num) {
var d = selectedSdk && opt.value == selectedSdk.name ? activeSdkLabel : '',
n = sdkVersionMaxlen + 2 - opt.value.length - d.length;
return num + opt.value.cyan + d.grey + new Array(n + 1).join(' ') + opt.path;
}
},
promptLabel: __('Enter # or SDK name'),
optionLabel: 'value',
options: sdkVersions.map(function (sdk) {
return { path: cli.env.sdks[sdk].path, value: sdk };
}),
validate: function (value) {
if (sdkVersions.indexOf(value) == -1) {
throw new Error(__('Invalid Titanium SDK'));
}
// set the new sdk
cli.sdk = cli.env.sdks[value];
return true;
}
// set the new sdk
cli.sdk = cli.env.sdks[value];
return true;
}
})
});
}
},
'android': {
'sdkPath': function (defaultValue) {
Expand Down Expand Up @@ -407,7 +411,7 @@ SetupScreens.prototype.quick = function quick(callback) {
'name': this._registry.user.name,
'email': this._registry.user.email,
'locale': this._registry.user.locale,
'sdk': this._registry.sdk.selected,
'sdk': this._registry.sdk.selected(),
'workspace': this._registry.app.workspace,
'using android': !androidSdkPath && fields.select({
promptLabel: __('Do you plan to build your app for Android?'),
Expand Down Expand Up @@ -790,16 +794,18 @@ SetupScreens.prototype.check = function check(callback) {
}
var selectedSdk = config.get('sdk.selected');
if (r.current) {
if (selectedSdk) {
var selected = cli.env.sdks[selectedSdk],
current = cli.env.sdks[r.current];
if (!selected) {
// bad, invalid selected sdk, select an sdk
bad(__('selected sdk'), __('selected Titanium SDK "v%s" is not installed', selectedSdk));
} else if (selectedSdk) {
// make sure the selected is >= current
if (appc.version.gte(selectedSdk, r.current)) {
if (appc.version.gte(selected.manifest && selected.manifest.version || selected.name, current.manifest && current.manifest.version || current.name)) {
ok(__('selected sdk'), __('up-to-date'),'(v' + r.current + ')');
} else {
warn(__('selected sdk'), __('latest Titanium SDK "v%s" is not the selected SDK', r.latest), __('(currently v%s)', selectedSdk));
}
} else if (!cli.env.sdks[selectedSdk]) {
// bad, invalid selected sdk, select an sdk
bad(__('selected sdk'), __('selected Titanium SDK "v%s" is not installed', selectedSdk));
} else {
// bad, no selected sdk, select an sdk
bad(__('selected sdk'), __('no selected Titanium SDK'));
Expand Down Expand Up @@ -1294,7 +1300,7 @@ SetupScreens.prototype.cli = function cli(callback) {
SetupScreens.prototype.sdk = function sdk(callback) {
this._title(__('Titanium SDK Settings'));
fields.set({
'selected': this._registry.sdk.selected,
'selected': this._registry.sdk.selected(),
'defaultInstallLocation': fields.file({
default: this._config.get('sdk.defaultInstallLocation', this._cli.env.installPath),
title: __('Path to find and install Titanium SDKs:'),
Expand Down
5 changes: 4 additions & 1 deletion lib/titanium.js
Expand Up @@ -287,7 +287,7 @@ function run(locale) {
// get a list of all valid sdks 3.0 and newer
var sdks = Object.keys(env.sdks).filter(function (v) {
try {
return appc.version.gte(v, '3.0.0');
return appc.version.gte(env.sdks[v].manifest && env.sdks[v].manifest.version || v, '3.0.0');
} catch (e) {
return false;
}
Expand Down Expand Up @@ -320,6 +320,7 @@ function run(locale) {
cli.on('cli:check-plugins', function (data) {
if (cli.hooks.incompatibleFilenames.length) {
// display all hooks for debugging
logger.banner();
logger.warn(__('Incompatible plugin hooks:').yellow.bold);
cli.hooks.incompatibleFilenames.forEach(function (f) {
logger.warn(f);
Expand All @@ -328,6 +329,7 @@ function run(locale) {
}

if (Object.keys(cli.hooks.errors).length) {
logger.banner();
logger.warn(__('Bad plugin hooks that failed to load:').yellow.bold);
Object.keys(cli.hooks.errors).forEach(function (f) {
logger.warn(f);
Expand All @@ -340,6 +342,7 @@ function run(locale) {
}

if (Object.keys(cli.hooks.ids).some(function (id) { return cli.hooks.ids[id].length > 1; })) {
logger.banner();
logger.warn(__('Conflicting plugins that were not loaded:').yellow.bold);
Object.keys(cli.hooks.ids).forEach(function (id) {
logger.warn(__('Hook ID: %s', id.cyan));
Expand Down

0 comments on commit e8ff06f

Please sign in to comment.