Skip to content

Instantly share code, notes, and snippets.

@chrishyle
Created July 24, 2010 07:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chrishyle/488508 to your computer and use it in GitHub Desktop.
Save chrishyle/488508 to your computer and use it in GitHub Desktop.
#!/usr/local/bin/node
/**
Usage:
Launch a dev server: build.js --server --debug
Save to disk: build.js --save --debug (currently broken)
(debug turns on verbose output)
*/
//Node setup
var g = require('./garcon/lib/garçon'),
sys = require('sys'),
server, app, apps,
options = {};
function debugMessage(message){
if(options.debug){
sys.puts('\u001B[35m[>] DEBUG: \u001B[0m'+message);
}
}
//Handle command line arguments
if(process.argv.length > 2){
for(var idx = 2, len = process.argv.length; idx < len; idx++){
switch(process.argv[idx]){
case '--server': case '-s':
options.server = true;
break;
case '--debug': case '-d':
options.debug = true;
break;
case '--save':
options.save = true;
break;
}
}
}
server = new g.Server({
port: 4021
});
apps = ['app1','app2'];
function buildApp(appName, save){
var callback, appConfig;
callback = function(){
debugMessage(appName+' built!');
};
appConfig = {
name: appName,
theme: 'sc-theme',
buildLanguage: 'english'
};
if(save){
appConfig.combineScripts = true;
appConfig.combineStylesheets = true;
appConfig.minifyScripts = true;
appConfig.minifyStylesheets = true;
}
app = server.addApp(appConfig);
app.addSproutcore();
app.addFrameworks(
// frameworks
{ path: 'frameworks/my_framework' },
// themes
{ path:'frameworks/sproutcore/themes/standard_theme', combineScripts: true },
//app
{ path: 'apps/'+appName }
);
// add some html for inside the <head> tag
app.htmlHead = '<title>'+appName+'</title>';
// add some html for inside the <body> tag
app.htmlBody = [
'<p id="loading">',
'Loading…',
'</p>'
].join('\n');
if(save){
callback = function() {
debugMessage(appName+' built!');
app.save();
};
}
// build the app
app.build(callback);
}
for(var idx=0, len = apps.length; idx < len; idx++){
buildApp(apps[idx], options.save);
}
if(options.server){
server.run();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment