Skip to content

Commit

Permalink
Merge pull request #3123 from ayeung/timob-9067
Browse files Browse the repository at this point in the history
TIMOB-9067: Add analytics to create and build commands
  • Loading branch information
cb1kenobi committed Oct 8, 2012
2 parents 1f18517 + 9766be9 commit 517fec1
Show file tree
Hide file tree
Showing 7 changed files with 172 additions and 29 deletions.
77 changes: 64 additions & 13 deletions android/cli/commands/_build.js
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,8 @@ exports.config = function (logger, config, cli) {

exports.validate = function (logger, config, cli) {
var tokens,
parts,
port,
i;

ti.validateProjectDir(logger, cli, cli.argv, 'project-dir');
Expand Down Expand Up @@ -287,8 +289,15 @@ exports.validate = function (logger, config, cli) {
}

if (cli.argv['debug-host'] && cli.argv.target != 'dist-playstore') {
var parts = cli.argv['debug-host'].split(':'),
port = parts.length > 1 && parseInt(parts[1]);
if (typeof cli.argv['debug-host'] == 'number') {
logger.error(__('Invalid debug host "%s"', cli.argv['debug-host']) + '\n');
logger.log(__('The debug host must be in the format "host:port".') + '\n');
process.exit(1);
}

parts = cli.argv['debug-host'].split(':'),
port = parts.length > 1 && parseInt(parts[1]);

if (parts.length < 2) {
logger.error(__('Invalid debug host "%s"', cli.argv['debug-host']) + '\n');
logger.log(__('The debug host must be in the format "host:port".') + '\n');
Expand All @@ -308,6 +317,8 @@ exports.validate = function (logger, config, cli) {
};

exports.run = function (logger, config, cli, finished) {
// TODO Add analytics events later when we implement the full andorid build instead of wrapping.
sendAnalytics(cli);
cli.fireHook('build.pre', function () {
var buildObj = new build(logger, config, cli, function (err) {
cli.fireHook('build.post', buildObj, function (e) {
Expand All @@ -325,37 +336,77 @@ exports.run = function (logger, config, cli, finished) {
});
};

function sendAnalytics(cli) {
var eventName = 'android.' + cli.argv.target;

if (cli.argv.target == 'dist-playstore') {
eventName = "android.distribute.playstore";
} else if(cli.argv['debug-host']) {
eventName += '.debug';
} else {
eventName += '.run';
}

cli.addAnalyticsEvent(eventName, {
dir: cli.argv['project-dir'],
name: tiapp.name,
publisher: tiapp.publisher,
url: tiapp.url,
image: tiapp.image,
appid: tiapp.id,
description: tiapp.description,
type: cli.argv.type,
guid: tiapp.guid,
version: tiapp.version,
copyright: tiapp.copyright,
date: (new Date()).toDateString()
});
}

function build(logger, config, cli, finished) {
var emulatorCmd = [],
cmd = [],
cmdSpawn;
cmdSpawn,
err,
options = {
stdio: 'inherit'
};

logger.info(__('Compiling "%s" build', cli.argv['deploy-type']));

ti.legacy.constructLegacyCommand(logger, cli, tiapp, cli.argv.platform , cmd, emulatorCmd);
ti.legacy.constructLegacyCommand(cli, tiapp, cli.argv.platform , cmd, emulatorCmd);

// console.log('Forking correct SDK command: ' + ('python ' + cmd.join(' ')).cyan + '\n');

if (emulatorCmd.length > 0) {
spawn('python', emulatorCmd,{}).on('exit', function(code) {
if (code === 1) {
finished && finished("An error occurred while running the command: " + ('python ' + cmd.join(' ')).cyan + '\n');
if (code) {
finished && finished('An error occurred while running the command: ' + ('python ' + cmd.join(' ')).cyan + '\n');
}
});
}

cmdSpawn = spawn('python', cmd, {
stdio: 'inherit'
});
// TODO Remove this when we don't want to wrap the python scripts anymore.
// We have to send the analytics here because for the emulator command, we will never 'exit' properly,
// as a result send won't get called on exit
cli.sendAnalytics();
}

cmdSpawn = spawn('python', cmd, options);

cmdSpawn.on('exit', function(code) {
var err;
if (code) {
err = "An error occurred while running the command: " + ('python ' + cmd.join(' ')).cyan + '\n';
err = 'An error occurred while running the command: ' + ('python ' + cmd.join(' ')).cyan + '\n';
} else if (cli.argv['target'] == 'emulator') {
// Call the logcat command in the old builder.py after the emulator, so we get logcat output
cmd = [];
cmd.push(path.join(path.resolve(cli.env.sdks[tiapp['sdk-version']].path), cli.argv.platform, 'builder.py'));
cmd.push('logcat');
cmd.push(cli.argv['android-sdk']);
cmd.push('-e');
spawn('python', cmd, options);
}
finished && finished(err);
});

}

build.prototype = {
Expand Down
39 changes: 38 additions & 1 deletion iphone/cli/commands/_build.js
Original file line number Diff line number Diff line change
Expand Up @@ -437,6 +437,12 @@ exports.validate = function (logger, config, cli) {
}

if (cli.argv['debug-host'] && cli.argv.target != 'dist-appstore') {
if (typeof cli.argv['debug-host'] == 'number') {
logger.error(__('Invalid debug host "%s"', cli.argv['debug-host']) + '\n');
logger.log(__('The debug host must be in the format "host:port".') + '\n');
process.exit(1);
}

var parts = cli.argv['debug-host'].split(':'),
port = parts.length > 1 && parseInt(parts[1]);
if ((cli.argv.target == 'simulator' && parts.length < 2) || (cli.argv.target != 'simulator' && parts.length < 3)) {
Expand All @@ -458,9 +464,12 @@ exports.validate = function (logger, config, cli) {
};

exports.run = function (logger, config, cli, finished) {
var buildObj;

if (cli.argv.xcode) {
// basically, we bypass the pre, post, and finalize hooks for xcode builds
new build(logger, config, cli, finished);
buildObj = new build(logger, config, cli, finished);
sendAnalytics(cli, buildObj.tiapp);
} else {
cli.fireHook('build.pre', function () {
var buildObj = new build(logger, config, cli, function (err) {
Expand All @@ -471,6 +480,7 @@ exports.run = function (logger, config, cli, finished) {
line && logger.error(line);
});
}
sendAnalytics(cli, buildObj.tiapp);
cli.fireHook('build.finalize', buildObj, function () {
finished(err);
});
Expand All @@ -480,6 +490,33 @@ exports.run = function (logger, config, cli, finished) {
}
};

function sendAnalytics(cli, tiapp) {
var eventName = cli.argv['device-family'] + '.' + cli.argv.target;

if (cli.argv.target == 'dist-appstore' || cli.argv.target == 'dist-adhoc') {
eventName = cli.argv['device-family'] + '.distribute.' + cli.argv.target.replace('dist-', '');
} else if (cli.argv['debug-host']) {
eventName += '.debug';
} else {
eventName += '.run';
}

cli.addAnalyticsEvent(eventName, {
dir: cli.argv['project-dir'],
name: tiapp.name,
publisher: tiapp.publisher,
url: tiapp.url,
image: tiapp.image,
appid: tiapp.id,
description: tiapp.description,
type: cli.argv.type,
guid: tiapp.guid,
version: tiapp.version,
copyright: tiapp.copyright,
date: (new Date()).toDateString()
});
}

function build(logger, config, cli, finished) {
this.logger = logger;
this.cli = cli;
Expand Down
37 changes: 27 additions & 10 deletions mobileweb/cli/commands/_build.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,18 +60,35 @@ exports.validate = function (logger, config, cli) {

exports.run = function (logger, config, cli, finished) {
cli.fireHook('build.pre', function () {
var buildObj = new build(logger, config, cli, function (err) {
cli.fireHook('build.post', buildObj, function (e) {
if (e && e.type == 'AppcException') {
logger.error(e.message);
e.details.forEach(function (line) {
line && logger.error(line);
var tiapp,
buildObj = new build(logger, config, cli, function (err) {
cli.fireHook('build.post', buildObj, function (e) {
if (e && e.type == 'AppcException') {
logger.error(e.message);
e.details.forEach(function (line) {
line && logger.error(line);
});
}
tiapp = buildObj.tiapp;
cli.addAnalyticsEvent('mobileweb.build.' + cli.argv['deploy-type'], {
dir: cli.argv['project-dir'],
name: tiapp.name,
publisher: tiapp.publisher,
url: tiapp.url,
image: tiapp.image,
appid: tiapp.id,
description: tiapp.description,
type: cli.argv.type,
guid: tiapp.guid,
version: tiapp.version,
copyright: tiapp.copyright,
date: (new Date()).toDateString()
});

cli.fireHook('build.finalize', buildObj, function () {
finished(err);
});
}
cli.fireHook('build.finalize', buildObj, function () {
finished(err);
});
});
});
});
};
Expand Down
5 changes: 5 additions & 0 deletions support/cli/commands/build.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,10 @@ exports.config = function (logger, config, cli) {
};

exports.validate = function (logger, config, cli) {

// Set the type to 'app' for now
cli.argv['type'] = 'app';

ti.validatePlatform(logger, cli.argv, 'platform');
if (ti.validatePlatformOptions(logger, config, cli, 'build') === false) {
return false;
Expand Down Expand Up @@ -134,4 +138,5 @@ exports.run = function (logger, config, cli) {
logger.info(__('Project built successfully in %s', delta) + '\n');
}
});

};
39 changes: 36 additions & 3 deletions support/cli/commands/create.js
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,8 @@ exports.run = function (logger, config, cli) {
projectDir = afs.resolvePath(cli.argv['workspace-dir'], projectName),
templateDir = afs.resolvePath(sdk.path, 'templates', type, cli.argv.template),
uuid = require('node-uuid'),
projectConfig;
projectConfig,
analyticsPayload;

afs.exists(projectDir) || wrench.mkdirSyncRecursive(projectDir);
wrench.copyDirSyncRecursive(templateDir, projectDir);
Expand Down Expand Up @@ -162,6 +163,22 @@ exports.run = function (logger, config, cli) {
'#image: appicon.png',
'#desc: not specified'
].join('\n'));

analyticsPayload = {
dir: projectDir,
name: projectName,
publisher: projectConfig.publisher,
url: projectConfig.url,
image: projectConfig.image,
appid: id,
description: projectConfig.description,
type: type,
guid: projectConfig.guid,
version: projectConfig.version,
copyright: projectConfig.copyright,
runtime: '1.0',
date: (new Date()).toDateString()
};
} else if (type == 'module') {
logger.info(__('Creating Titanium Mobile module project'));

Expand Down Expand Up @@ -196,9 +213,22 @@ exports.run = function (logger, config, cli) {
'name: ' + projectName,
'moduleid: ' + id,
'guid: ' + projectConfig.__GUID__,
'platforms: ' + platforms.sort().join(', '),
'minsdk: ' + sdk.name
'platforms: ' + platforms.sort().join(', ')
].join('\n'));

analyticsPayload = {
dir: projectDir,
name: projectName,
author: ((config.user && config.user.name) || 'Your Name'),
moduleid: id,
description: projectName,
guid: projectConfig.__GUID__,
version: '1.0',
copyright: 'copyright: Copyright (c) 2012 by ' + ((config.user && config.user.name) || 'Your Company'),
minsdk: sdk.name,
platforms: platforms.sort().join(', '),
date: (new Date()).toDateString()
};
}

platforms.forEach(function (platform) {
Expand All @@ -209,4 +239,7 @@ exports.run = function (logger, config, cli) {
});

logger.info(__("Project '%s' created successfully in %s", projectName.cyan, appc.time.prettyDiff(cli.startTime, Date.now())) + '\n');

// This will be something like 'project.create.app' ... do we want it to be something like 'project.create.mobile' like studio?
cli.addAnalyticsEvent('project.create.' + cli.argv.type, analyticsPayload);
};
2 changes: 1 addition & 1 deletion support/node_modules/titanium-sdk/lib/legacy.js

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

2 changes: 1 addition & 1 deletion 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.

0 comments on commit 517fec1

Please sign in to comment.