Untitled diff

Created Diff never expires
0 removals
717 lines
1 addition
717 lines
/**
/**
* Titanium SDK Library for Node.js
* Titanium SDK Library for Node.js
* Copyright (c) 2012-2013 by Appcelerator, Inc. All Rights Reserved.
* Copyright (c) 2012-2013 by Appcelerator, Inc. All Rights Reserved.
* Please see the LICENSE file for information about licensing.
* Please see the LICENSE file for information about licensing.
*/
*/
var fs = require('fs'),
var fs = require('fs'),
path = require('path'),
path = require('path'),
async = require('async'),
async = require('async'),
appc = require('node-appc'),
appc = require('node-appc'),
__ = appc.i18n(__dirname).__,
__ = appc.i18n(__dirname).__,
spawn = require('child_process').spawn,
spawn = require('child_process').spawn,
afs = appc.fs,
afs = appc.fs,
version = appc.version,
version = appc.version,
manifest = appc.pkginfo.manifest(module),
manifest = appc.pkginfo.manifest(module),
platformAliases = {
platformAliases = {
// add additional aliases here for new platforms
// add additional aliases here for new platforms
'ipad': 'iphone',
'ipad': 'iphone',
'ios': 'iphone'
'ios': 'iphone'
};
};


exports.i18n = require('./i18n');
exports.i18n = require('./i18n');
exports.jss = require('./jss');
exports.jss = require('./jss');
exports.tiappxml = require('./tiappxml');
exports.tiappxml = require('./tiappxml');


exports.manifest = manifest;
exports.manifest = manifest;
exports.platforms = [].concat(manifest.platforms);
exports.platforms = [].concat(manifest.platforms);
exports.targetPlatforms = (manifest.platforms || []).map(function (p) {
exports.targetPlatforms = (manifest.platforms || []).map(function (p) {
return p == 'iphone' ? 'ios' : p;
return p == 'iphone' ? 'ios' : p;
}).sort();
}).sort();
exports.availablePlatforms = (manifest.platforms || []).sort();
exports.availablePlatforms = (manifest.platforms || []).sort();
exports.availablePlatformsNames = function (platforms) {
exports.availablePlatformsNames = function (platforms) {
Object.keys(platformAliases).forEach(function (alias) {
Object.keys(platformAliases).forEach(function (alias) {
if (platforms.indexOf(platformAliases[alias]) != -1) {
if (platforms.indexOf(platformAliases[alias]) != -1) {
platforms.push(alias);
platforms.push(alias);
}
}
});
});
return platforms.sort();
return platforms.sort();
}(manifest.platforms || []);
}(manifest.platforms || []);


exports.commonOptions = function (logger, config) {
exports.commonOptions = function (logger, config) {
return {
return {
'log-level': {
'log-level': {
callback: function (value) {
callback: function (value) {
logger.levels.hasOwnProperty(value) && logger.setLevel(value);
logger.levels.hasOwnProperty(value) && logger.setLevel(value);
},
},
desc: __('minimum logging level'),
desc: __('minimum logging level'),
default: config.cli.logLevel || 'trace',
default: config.cli.logLevel || 'trace',
hint: __('level'),
hint: __('level'),
values: logger.getLevels()
values: logger.getLevels()
}
}
};
};
};
};


exports.platformOptions = function (logger, config, cli, commandName, finished) {
exports.platformOptions = function (logger, config, cli, commandName, finished) {
var result = {};
var result = {};


if (!commandName) {
if (!commandName) {
finished(result);
finished(result);
return;
return;
}
}


function set(obj, title, platform) {
function set(obj, title, platform) {
// add the platform and title to the options and flags
// add the platform and title to the options and flags
['options', 'flags'].forEach(function (type) {
['options', 'flags'].forEach(function (type) {
if (obj[type]) {
if (obj && obj[type]) {
result[platform] || (result[platform] = {
result[platform] || (result[platform] = {
platform: platform,
platform: platform,
title: title || platform
title: title || platform
});
});
result[platform][type] = obj[type];
result[platform][type] = obj[type];
}
}
});
});
}
}


// for each platform, fetch their specific flags/options
// for each platform, fetch their specific flags/options
async.parallel(manifest.platforms.map(function (platform) {
async.parallel(manifest.platforms.map(function (platform) {
return function (callback) {
return function (callback) {
var platformDir = path.join(path.dirname(module.filename), '..', '..', '..', platform),
var platformDir = path.join(path.dirname(module.filename), '..', '..', '..', platform),
platformCommand = path.join(platformDir, 'cli', 'commands', '_' + commandName + '.js'),
platformCommand = path.join(platformDir, 'cli', 'commands', '_' + commandName + '.js'),
command,
command,
conf,
conf,
title;
title;


if (!fs.existsSync(platformCommand)) return callback();
if (!fs.existsSync(platformCommand)) return callback();


command = require(platformCommand);
command = require(platformCommand);
if (!command || !command.config) return callback();
if (!command || !command.config) return callback();


// try to get the platform specific configuration
// try to get the platform specific configuration
conf = command.config(logger, config, cli);
conf = command.config(logger, config, cli);


try {
try {
// try to read a title from the platform's package.json
// try to read a title from the platform's package.json
title = JSON.parse(fs.readFileSync(path.join(platformDir, 'package.json'))).title;
title = JSON.parse(fs.readFileSync(path.join(platformDir, 'package.json'))).title;
} catch (e) {}
} catch (e) {}


if (typeof conf == 'function') {
if (typeof conf == 'function') {
// async callback
// async callback
conf(function (obj) {
conf(function (obj) {
set(obj, title, platform);
set(obj, title, platform);