Created
November 13, 2013 22:30
-
-
Save moduscreate/7457675 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/local/bin/node | |
var sys = require('sys'), | |
fs = require('fs'), | |
console = require('console'), | |
exec = require('child_process').exec; | |
var target = "testing", | |
cdvRoot = 'cdv', | |
cdvSrc = cdvRoot + '/www.orig', | |
cdvDest = cdvRoot + '/www', | |
projName, | |
buildDir; | |
var Program = { | |
platforms : [ | |
'ios', | |
'android' | |
], | |
colors : { | |
green : "$'\\\E[00;32m''", | |
red : "$'\\\E[41m''", | |
yellow : "$'\\\E[33;48m''", | |
clear : "' $'\\\E[00m' \n" | |
}, | |
start : function() { | |
this.warn('Program started...'); | |
this.getSenchaProjectName(); | |
}, | |
getSenchaProjectName : function() { | |
var cmd = 'cat html5/app.json | grep "\\\"name\\\"" | awk -F\\\" \'{print $4}\''; | |
// console.log(cmd); | |
this.execProcess(cmd, this.onAfterGetSenchaProjectName, this); | |
}, | |
onAfterGetSenchaProjectName : function(error, stdOut, stdError) { | |
// remove new line character | |
projName = stdOut.substr(0, stdOut.length - 1); | |
buildDir = 'html5/build/' + projName + '/' + target; | |
//this.log(buildDir); | |
this.buildSencha(); | |
}, | |
buildSencha : function() { | |
this.info('Starting sencha build...'); | |
var cmd = "cd html5/; ~/bin/Sencha/Cmd/3.1.2.342/sencha -q app build " + target; | |
this.execProcess(cmd, this.onAfterBuildSencha, this); | |
}, | |
onAfterBuildSencha : function(error, stdOut, stdError) { | |
this.info('Sencha ' + target + ' build complete.'); | |
this.copyConfigXml(); | |
}, | |
moveTestingBuildDir : function() { | |
this.info('Moving touch testing build dir to ' + cdvDest); | |
this.execProcess('rm -rf ' + cdvDest + '; mv ' + buildDir + ' ' + cdvDest, this.onAfterMoveTestingBuildDir, this); | |
}, | |
onAfterMoveTestingBuildDir : function() { | |
this.moveTestingBuildDir(); | |
}, | |
copyConfigXml : function() { | |
this.info('Copying ' + cdvSrc + '/config.xml to ' + cdvDest); | |
this.execProcess('cp ' + cdvSrc + '/config.xml ' + cdvDest +'/', this.onAfterCopyConfigXml, this); | |
}, | |
onAfterCopyConfigXml : function() { | |
this.prepareCdvIos(); | |
}, | |
prepareCdvIos : function() { | |
this.info('Preparing Cordova iOS build'); | |
this.execProcess('cd cdv; cordova prepare ios', this.onAfterPrepareCdvIos, this); | |
}, | |
onAfterPrepareCdvIos : function() { | |
this.prepareCdvAndroid(); | |
}, | |
prepareCdvAndroid : function() { | |
// this.info('Preparing Cordova android build'); | |
this.warn('Preparing Cordova iOS build :: NOT IMPLEMENTED'); | |
// this.execProcess('cordova prepare ios', this.onAfterPrepareCdvIos, this); | |
}, | |
onAfterPrepareCdvAndroid : function() { | |
}, | |
log : function(msg, callback, scope) { | |
this.execLogCmd(msg, callback, scope); | |
}, | |
info : function(msg, callback, scope) { | |
this.execLogCmd(msg, callback, scope, this.colors.green); | |
}, | |
warn : function(msg, callback, scope) { | |
this.execLogCmd(msg, callback, scope, this.colors.yellow); | |
}, | |
error : function(msg, callback, scope) { | |
this.execLogCmd(msg, callback, scope, this.colors.red); | |
}, | |
execProcess : function(cmd, callback, scope) { | |
var me = this, | |
err; | |
// console.log('execProcess : ' + cmd); | |
exec(cmd, { maxBuffer : 1024 * 1024 }, function(error, stdOut, stdError) { | |
if (error || stdError) { | |
err = error; | |
console.log(error || stdError); | |
me.error('Error with command: "' + cmd + '"', function() { | |
console.log(error || stdError); | |
}); | |
return; | |
} | |
if (callback) { | |
callback.apply(scope || this, arguments); | |
} | |
}); | |
}, | |
execLogCmd : function(msg, callback, scope, color) { | |
var cmd; | |
if (color) { | |
cmd = "echo " + color + msg + this.colors.clear; | |
} | |
else { | |
cmd = "echo " + msg; | |
} | |
this.execProcess(cmd, function(error, stdOut) { | |
console.log(stdOut); | |
}); | |
}, | |
processArgs : function() { | |
// print process.argv | |
process.argv.forEach(function(val, index, array) { | |
console.log(index + ': ' + val); | |
}); | |
} | |
}; | |
Program.start(); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment