Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[TIMOB-17346] Fixed issues with config.json being overwritten at the same time. #152

Merged
merged 1 commit into from
Aug 30, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 6 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
3.3.1
3.4.0
-------------------
* Added support for selecting latest stable SDK [TIMOB-17378]
* Fixed issues with config.json being overwritten at the same time [TIMOB-17346]
* Improved handling of corrupt a config.json file [TIMOB-17346]
* Fixed backwards compatibility with Titanium SDK 3.3.0 and older when building an iOS app and Xcode 6 or newer is installed
* Added support for a "helpNoPrompt()" callback when a missing option is encountered
* Fixed bug with abbreviated options that don't have a value being set to true

3.3.0 (7/17/14)
-------------------
Expand Down
32 changes: 29 additions & 3 deletions hooks/tisdk3fixes.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,20 @@
* commands and hooks.
*
* @copyright
* Copyright (c) 2009-2013 by Appcelerator, Inc. All Rights Reserved.
* Copyright (c) 2009-2014 by Appcelerator, Inc. All Rights Reserved.
*
* @license
* Licensed under the terms of the Apache Public License
* Please see the LICENSE included with this distribution for details.
*/

var appc = require('node-appc');
var appc = require('node-appc'),
fs = require('fs'),
path = require('path');

exports.cliVersion = '>=3.2';

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

Expand Down Expand Up @@ -58,4 +60,28 @@ exports.init = function (logger, config, cli) {
}
}
});

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

if (cli.sdk && appc.version.lt(sdk, '3.4.0') && /^(ios|iphone|ipad)$/.test(cli.argv.platform || cli.argv.p)) {
// Titanium SDK 3.3.x and older does not support Xcode 6, so we try to remove it as if it never existed
var detectFile = path.join(cli.sdk.platforms.iphone.path, 'cli', 'lib', 'detect.js');
if (fs.existsSync(detectFile)) {
require(detectFile).detect(config, null, function (iosInfo) {
Object.keys(iosInfo.xcode).forEach(function (ver) {
if (appc.version.gte(iosInfo.xcode[ver].version, '6.0.0')) {
delete iosInfo.xcode[ver];
}
});
done();
});
return;
}
}

done();
}
});
};
18 changes: 13 additions & 5 deletions lib/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* @module cli
*
* @copyright
* Copyright (c) 2009-2013 by Appcelerator, Inc. All Rights Reserved.
* Copyright (c) 2009-2014 by Appcelerator, Inc. All Rights Reserved.
*
* Copyright (c) 2010 hij1nx <http://www.twitter.com/hij1nx>
* {@link https://github.com/hij1nx/complete}
Expand Down Expand Up @@ -679,9 +679,12 @@ CLI.prototype.validate = function validate(next) {

if (Object.keys(invalid).length) {
Object.keys(invalid).forEach(function (name) {
var opt = invalid[name];
this.logger.error(__('Invalid "%s" value "%s"', (opt.label || '--' + name), argv[opt.name]) + '\n');
if (opt.values) {
var opt = invalid[name],
msg = __('Invalid "%s" value "%s"', (opt.label || '--' + name), argv[opt.name]);
if (typeof opt.helpNoPrompt === 'function') {
opt.helpNoPrompt(this.logger, msg);
} else if (opt.values) {
this.logger.error(msg + '\n');
this.logger.log(__('Accepted values:'));
opt.values.forEach(function (v) {
this.logger.log(' ' + v.cyan);
Expand All @@ -694,7 +697,12 @@ CLI.prototype.validate = function validate(next) {
if (Object.keys(missing).length) {
// if prompting is disabled, then we just print all the problems we encountered
Object.keys(missing).forEach(function (name) {
this.logger.error(__('Missing required option: %s', '--' + name + ' <' + (missing[name].hint || __('value')) + '>') + '\n');
var msg = __('Missing required option: %s', '--' + name + ' <' + (missing[name].hint || __('value')) + '>');
if (typeof missing[name].helpNoPrompt === 'function') {
missing[name].helpNoPrompt(this.logger, msg);
} else {
this.logger.error(msg + '\n');
}
}, this);
}

Expand Down
8 changes: 5 additions & 3 deletions lib/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* @module config
*
* @copyright
* Copyright (c) 2009-2013 by Appcelerator, Inc. All Rights Reserved.
* Copyright (c) 2009-2014 by Appcelerator, Inc. All Rights Reserved.
*
* @license
* Licensed under the terms of the Apache Public License
Expand Down Expand Up @@ -219,7 +219,7 @@ Object.defineProperty(config, 'load', {

mixObj(config, values);
} catch (ex) {
throw new Error(__('Unable to parse config file'));
throw new Error(__('Unable to parse config file "%s"', configFile));
}
}

Expand All @@ -236,7 +236,9 @@ Object.defineProperty(config, 'save', {
if (!fs.existsSync(titaniumConfigFolder)) {
wrench.mkdirSyncRecursive(titaniumConfigFolder);
}
fs.writeFileSync(configFile, JSON.stringify(config, null, '\t'));
var tmpFile = configFile + '.' + Date.now() + '.tmp';
fs.writeFileSync(tmpFile, JSON.stringify(config, null, '\t'));
fs.renameSync(tmpFile, configFile);
} catch (e) {
if (e.code == 'EACCES') {
console.error(__('Unable to write config file %s', configFile));
Expand Down
8 changes: 5 additions & 3 deletions lib/context.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* @module context
*
* @copyright
* Copyright (c) 2009-2013 by Appcelerator, Inc. All Rights Reserved.
* Copyright (c) 2009-2014 by Appcelerator, Inc. All Rights Reserved.
*
* Copyright 2010 James Halliday (mail@substack.net)
* {@link https://github.com/substack/node-optimist}
Expand Down Expand Up @@ -736,9 +736,9 @@ Context.prototype.parse = function parse(args, commands, skipCallbacks) {
// no next value, just set it to an empty string
setArg(name, '');
}
} else if (/true|false/.test(next)) {
} else if (/^true|false$/.test(next)) {
// --flag true
setArg(name, next == 'true');
setArg(name, next === 'true');
i++;
} else {
// --flag
Expand Down Expand Up @@ -768,6 +768,8 @@ Context.prototype.parse = function parse(args, commands, skipCallbacks) {
} else if (next && /true|false/.test(next)) {
setArg(name, next == 'true');
i++;
} else if (!next && !this.flags[name] && (!this.aliases[name] || !this.flags[this.aliases[name]])) {
setArg(name);
} else {
setArg(name, true);
}
Expand Down
14 changes: 12 additions & 2 deletions lib/titanium.js
Original file line number Diff line number Diff line change
Expand Up @@ -113,8 +113,18 @@ function run(locale) {
try {
config.load(getArg('--config-file'));
} catch (ex) {
console.error(('FATAL ERROR: ' + ex.toString().trim()).red + '\n');
process.exit(1);
console.error(('[ERROR] ' + (ex.message || ex.toString()).trim()).red);
try {
var backup = config.getConfigPath() + '.' + Date.now() + '.json';
fs.writeFileSync(backup, fs.readFileSync(config.getConfigPath()));
fs.unlinkSync(config.getConfigPath());
console.error(('[ERROR] The bad config file has been renamed to ' + backup).red);
} catch (ex2) {
console.error('[ERROR] Failed to backup the config file, please manually rename/remove it'.red);
process.exit(1);
}
console.error('[ERROR] Using default config'.red);
console.error('[ERROR] Run "titanium setup" to reconfigure'.red + '\n');
}

// if there's a --config, mix it into our config
Expand Down