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-12375] Fixed project creation with various platform configurations. #3761

Merged
merged 2 commits into from
Jan 23, 2013
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
5 changes: 2 additions & 3 deletions iphone/cli/commands/_create.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@

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

exports.config = function (logger, config, cli) {
return {
Expand All @@ -20,6 +19,6 @@ exports.run = function (logger, config, cli, projectConfig) {
var templatePath = afs.resolvePath(path.dirname(module.filename), '..', '..', 'templates', cli.argv.type, cli.argv.template),
projectDir = afs.resolvePath(cli.argv['workspace-dir'], cli.argv.name);
if (afs.exists(templatePath)) {
wrench.copyDirSyncRecursive(templatePath, projectDir, { preserve: true });
afs.copyDirSyncRecursive(templatePath, projectDir, { preserve: true, logger: logger.debug });
}
};
5 changes: 2 additions & 3 deletions mobileweb/cli/commands/_create.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@

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

exports.config = function (logger, config, cli) {
return {
Expand All @@ -20,6 +19,6 @@ exports.run = function (logger, config, cli, projectConfig) {
var templatePath = afs.resolvePath(path.dirname(module.filename), '..', '..', 'templates', cli.argv.type, cli.argv.template),
projectDir = afs.resolvePath(cli.argv['workspace-dir'], cli.argv.name);
if (afs.exists(templatePath)) {
wrench.copyDirSyncRecursive(templatePath, projectDir, { preserve: true });
afs.copyDirSyncRecursive(templatePath, projectDir, { preserve: true, logger: logger.debug });
}
};
49 changes: 37 additions & 12 deletions support/cli/commands/clean.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,15 @@ exports.config = function (logger, config, cli) {
return {
options: appc.util.mix({
platform: {
// note: --platform is not required for the clean command
// this is for backwards compatibility and eventually should be dropped
hidden: true
},
platforms: {
// note: --platforms is not required for the clean command
abbr: 'p',
desc: __('a platform to clean'),
values: ti.availablePlatforms
desc: __('one or more platforms to clean'),
values: ti.targetPlatforms,
skipValueCheck: true // we do our own validation
},
'project-dir': {
abbr: 'd',
Expand All @@ -35,22 +40,42 @@ exports.config = function (logger, config, cli) {
};

exports.validate = function (logger, config, cli) {
cli.argv.platform && ti.validatePlatform(logger, cli.argv, 'platform');
var platforms = cli.argv.platforms || cli.argv.platform;
if (platforms) {
platforms = ti.scrubPlatforms(platforms);

if (platforms.bad.length) {
logger.error(__n('Invalid platform: %%s', 'Invalid platforms: %%s', platforms.bad.length, platforms.bad.join(', ')) + '\n');
logger.log(__('Available platforms for SDK version %s:', ti.manifest.sdkVersion) + '\n');
ti.targetPlatforms.forEach(function (p) {
logger.log(' ' + p.cyan);
});
logger.log();
process.exit(1);
}

cli.argv.platforms = platforms.scrubbed;
} else {
cli.argv.platforms = null;
}

ti.validateProjectDir(logger, cli, cli.argv, 'project-dir');
ti.loadPlugins(logger, cli, config, cli.argv['project-dir']);
};

exports.run = function (logger, config, cli) {
var buildDir = path.join(cli.argv['project-dir'], 'build');

if (cli.argv.platform) {
var dir = path.join(buildDir, cli.argv.platform);
if (appc.fs.exists(dir)) {
logger.debug(__('Deleting %s', dir.cyan));
wrench.rmdirSyncRecursive(dir);
} else {
logger.debug(__('Directory does not exist %s', dir.cyan));
}
if (cli.argv.platforms) {
cli.argv.platforms.forEach(function (platform) {
var dir = path.join(buildDir, platform);
if (appc.fs.exists(dir)) {
logger.debug(__('Deleting %s', dir.cyan));
wrench.rmdirSyncRecursive(dir);
} else {
logger.debug(__('Directory does not exist %s', dir.cyan));
}
});
} else if (appc.fs.exists(buildDir)) {
logger.debug(__('Deleting all platform build directories'));
fs.readdirSync(buildDir).forEach(function (dir) {
Expand Down
25 changes: 14 additions & 11 deletions support/cli/commands/create.js
Original file line number Diff line number Diff line change
Expand Up @@ -123,12 +123,11 @@ exports.config = function (logger, config, cli) {

exports.validate = function (logger, config, cli) {
var platforms = ti.scrubPlatforms(cli.argv.platforms);
cli.argv.platforms = platforms.scrubbed;

if (platforms.bad.length) {
logger.error(__n('Invalid platform: %%s', 'Invalid platforms: %%s', platforms.bad.length, platforms.bad.join(', ')) + '\n');
logger.log(__('Available platforms for SDK version %s:', ti.manifest.sdkVersion) + '\n');
ti.availablePlatforms.forEach(function (p) {
ti.availablePlatformsNames.forEach(function (p) {
logger.log(' ' + p.cyan);
});
logger.log();
Expand Down Expand Up @@ -170,7 +169,7 @@ exports.validate = function (logger, config, cli) {

exports.run = function (logger, config, cli) {
var projectName = cli.argv.name,
platforms = cli.argv.platforms,
platforms = ti.scrubPlatforms(cli.argv.platforms),
id = cli.argv.id,
type = cli.argv.type,
url = cli.argv.url || '',
Expand All @@ -182,11 +181,12 @@ exports.run = function (logger, config, cli) {
analyticsPayload;

afs.exists(projectDir) || wrench.mkdirSyncRecursive(projectDir);
wrench.copyDirSyncRecursive(templateDir, projectDir);

if (type == 'app') {
logger.info(__('Creating Titanium Mobile application project'));

afs.copyDirSyncRecursive(templateDir, projectDir, { logger: logger.debug });

// read and populate the tiapp.xml
projectConfig = new ti.tiappxml(projectDir + '/tiapp.xml');
projectConfig.id = id;
Expand All @@ -195,13 +195,13 @@ exports.run = function (logger, config, cli) {
projectConfig.version = '1.0';
projectConfig.guid = uuid.v4();
projectConfig['deployment-targets'] = {};
if (platforms.indexOf('ios') != -1) {
platforms.indexOf('ipad') != -1 || platforms.push('ipad');
platforms.indexOf('iphone') != -1 || platforms.push('iphone');
if (platforms.original.indexOf('ios') != -1) {
platforms.original.indexOf('ipad') != -1 || platforms.original.push('ipad');
platforms.original.indexOf('iphone') != -1 || platforms.original.push('iphone');
}
ti.availablePlatformsNames.forEach(function (p) {
if (p != 'ios') {
projectConfig['deployment-targets'][p] = platforms.indexOf(p) != -1;
projectConfig['deployment-targets'][p] = platforms.original.indexOf(p) != -1;
}
});
projectConfig['sdk-version'] = sdk.name;
Expand Down Expand Up @@ -240,6 +240,8 @@ exports.run = function (logger, config, cli) {
} else if (type == 'module') {
logger.info(__('Creating Titanium Mobile module project'));

afs.copyDirSyncRecursive(templateDir, projectDir, { logger: logger.debug });

projectConfig = {
'___PROJECTNAMEASIDENTIFIER___': projectName.toLowerCase().split(/\./).map(function (s) { return appc.string.capitalize(s); }).join(''),
'___MODULE_NAME_CAMEL___': projectName.toLowerCase().split(/[\W_]/).map(function (s) { return appc.string.capitalize(s); }).join(''),
Expand Down Expand Up @@ -271,7 +273,7 @@ exports.run = function (logger, config, cli) {
'name: ' + projectName,
'moduleid: ' + id,
'guid: ' + projectConfig.__GUID__,
'platforms: ' + platforms.sort().join(', ')
'platforms: ' + platforms.original.join(', ')
].join('\n'));

analyticsPayload = {
Expand All @@ -284,16 +286,17 @@ exports.run = function (logger, config, cli) {
version: '1.0',
copyright: 'copyright: Copyright (c) 2012 by ' + ((config.user && config.user.name) || 'Your Company'),
minsdk: sdk.name,
platforms: platforms.sort().join(', '),
platforms: platforms.original.join(', '),
date: (new Date()).toDateString()
};

cli.addAnalyticsEvent('project.create.module', analyticsPayload);
}

platforms.forEach(function (platform) {
platforms.scrubbed.forEach(function (platform) {
var p = afs.resolvePath(path.dirname(module.filename), '..', '..', platform, 'cli', 'commands', '_create.js');
if (afs.exists(p)) {
logger.info(__('Copying "%s" platform resources', platform));
require(p).run(logger, config, cli, projectConfig);
}
});
Expand Down
29 changes: 17 additions & 12 deletions support/node_modules/titanium-sdk/lib/titanium.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.