blob: 60b2e09c5621aaa2666bf0aa6a7210a0c5dfe428 [file] [log] [blame]
#!/usr/bin/env node
var tokens = process.argv.slice(2, process.argv.length),
cordova= require('../cordova');
var cmd, version = false, verbose = false, current;
while (current = tokens.shift()) {
if (current[0] == '-') {
if (current.indexOf('version') > -1 || current[1] == 'v') version = true;
if (current.indexOf('verbose') > -1 || current[1] == 'd') verbose = true;
} else {
cmd = current;
break;
}
}
// provide clean output on exceptions rather than dumping a stack trace
process.on('uncaughtException', function(err){
console.error(err);
process.exit(1);
});
cordova.on('result', console.log);
if (verbose) {
cordova.on('log', console.log);
cordova.on('warn', console.warn);
process.on('uncaughtException', function(err) { console.error(err.stack) });
}
if (version) {
console.log(require('../package').version);
} else if (cmd === undefined) {
console.log(cordova.help());
} else if (cordova.hasOwnProperty(cmd)) {
var opts = Array.prototype.slice.call(tokens, 0);
if (cmd == 'create' || cmd == 'docs' || cmd == 'serve') {
cordova[cmd].apply(this, opts);
} else if (cmd == 'emulate' || cmd == 'build' || cmd == 'prepare' || cmd == 'compile' || cmd == 'run') {
cordova[cmd].call(this, opts);
} else {
// platform or plugin cmds
if (tokens.length > 2) {
opts = [tokens.shift()];
opts.push(tokens);
}
cordova[cmd].apply(this, opts);
}
} else {
throw new Error('Cordova does not know ' + cmd + '; try help for a list of all the available commands.');
}