Created
November 19, 2013 13:56
-
-
Save moduscreate/7545725 to your computer and use it in GitHub Desktop.
Prototype gluecode CLI for Sencha & Cordova projects
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 die = function(msg) { | |
msg && console.log(msg); | |
process.exit(code=1); | |
}; | |
var sys = require('sys'), | |
fs = require('fs'), | |
console = require('console'), | |
exec = require('child_process').exec, | |
step = 0, | |
commander, | |
colors; | |
try { | |
colors = require('colors'); | |
colors.setTheme({ | |
silly : 'rainbow', | |
input : 'grey', | |
verbose : 'cyan', | |
prompt : 'grey', | |
info : 'green', | |
data : 'grey', | |
help : 'cyan', | |
warn : 'yellow', | |
debug : 'blue', | |
error : 'red' | |
}); | |
} | |
catch (e){ | |
die( | |
'Error! Could not find the "colors" npm package.\n'+ | |
'Please install via "npm install colors"' | |
); | |
} | |
try { | |
commander = require('commander'); | |
commander.option('-a, --all', 'Build all items'); | |
commander.option('-i, --ios', 'Build iOS'); | |
commander.option('-a, --and', 'Build Android'); | |
commander.parse(process.argv); | |
} | |
catch (e){ | |
die( | |
'Error! Could not find the "commander" npm package.\n'+ | |
'Please install via "npm install commander"' | |
); | |
} | |
var target = "testing", | |
cdvRoot = 'cdv', | |
cdvSrc = cdvRoot + '/www.orig', | |
cdvDest = cdvRoot + '/www', | |
projName, | |
buildDir; | |
var Program = { | |
platforms : [ | |
'ios', | |
'android' | |
], | |
start : function() { | |
this.log('-=[ 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 for ' + projName + '...'); | |
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 ANDROID build :: NOT IMPLEMENTED'); | |
// this.execProcess('cordova prepare ios', this.onAfterPrepareCdvIos, this); | |
}, | |
onAfterPrepareCdvAndroid : function() { | |
}, | |
log : function(msg) { | |
console.log(msg.data); | |
}, | |
info : function(msg) { | |
console.log(msg.debug); | |
}, | |
warn : function(msg) { | |
console.log(msg.warn); | |
}, | |
error : function(msg) { | |
console.log(msg.error); | |
}, | |
execProcess : function(cmd, callback, scope) { | |
var me = this; | |
exec(cmd, { maxBuffer : 1024 * 1024 }, function(error, stdOut, stdError) { | |
if (error || stdError) { | |
me.error('Error with command: "' + cmd + '"'); | |
console.log(error || stdError); | |
return; | |
} | |
if (callback) { | |
callback.apply(scope || this, arguments); | |
} | |
}); | |
}, | |
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