Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/grunt ftw #66

Open
wants to merge 18 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,6 @@ Gemfile.lock
# hookio
config.json

# jake
.jake_tasks

# jasmine-node
.monitor

Expand Down
7 changes: 5 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,8 @@ branches:

language: node_js
node_js:
- 0.6
- 0.8
- 0.8
- 0.10

before_script:
- npm install -g grunt-cli
176 changes: 176 additions & 0 deletions Gruntfile.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,176 @@
require('colors');
var browserify = require('browserify');
var tagify = require('tagify');
var path = require('path');
var UIGenerator = require('./UI/generator');

module.exports = function(grunt) {

// defautl task
grunt.registerTask('default', ['ascii']);

// tests tasks aliases
grunt.registerTask('test:node', ['ascii', 'mochaTest:test']);

// build tasks aliases
grunt.registerTask('build', ['build:xmpp', 'build:simudp']);
grunt.registerTask('build:xmpp', ['ascii', 'kadohBuild:xmpp']);
grunt.registerTask('build:simudp', ['ascii', 'kadohBuild:simudp']);

// generate tasks aliases
grunt.registerTask('generate:xmpp', ['ascii', 'generateUI:xmpp']);
grunt.registerTask('generate:simudp', ['ascii', 'generateUI:simudp']);
grunt.registerTask('generate:mainline', ['ascii', 'generateUI:mainline']);

// run tasks aliases
grunt.registerTask('run:xmpp', ['ascii', 'generateUI:xmpp', 'runServer:xmpp:keepalive']);
grunt.registerTask('run:udp', ['ascii', 'generateUI:udp', 'runServer:udp:keepalive']);
grunt.registerTask('run:mainline', ['ascii', 'generateUI:mainline', 'runServer:mainline:keepalive']);
grunt.registerTask('run:boilerplate', ['ascii', 'runServer:boilerplate:keepalive']);

// project configuration
grunt.initConfig({
mochaTest: {
test: {
src: ['test/**/*.js']
}
},

kadohBuild: {
options: {
debug: grunt.option('debug')
},
xmpp: {
options: {
flags: ['xmpp', 'lawnchair'],
},
src: ['lib/index-browserify.js'],
dest: 'dist/KadOH.xmpp.js'
},

simudp: {
options: {
flags: ['simudp', 'lawnchair'],
},
src: ['lib/index-browserify.js'],
dest: 'dist/KadOH.simudp.js'
}
},

generateUI: {
mainline: {
files: {
'apps/mainline/index.html': ['apps/mainline/conf.json']
}
},
udp: {
files: {
'apps/udp/index.html': ['apps/udp/conf.json']
}
},
xmpp: {
files: {
'apps/xmpp/index.html': ['apps/xmpp/conf.json']
}
}
},

runServer: {
mainline: {
src: ['./apps/mainline/app.js']
},
udp: {
src: ['./apps/udp/app.js']
},
xmpp: {
src: ['./apps/xmpp/app.js']
},
boilerplate: {
src: ['./apps/boilerplate/app.js']
}
}
});

// ascii task
grunt.registerTask('ascii', 'Print kadoh ascii', function() {
var logo = grunt.file.read('kadoh.ascii.txt');
grunt.log.writeln(logo.yellow);
});

// build kadoh task
// TODO: replace me with proper browserify task ASA
// we switch to browserify v2
grunt.registerMultiTask('kadohBuild', 'Build kadoh file', function() {
var task = this;
this.files.forEach(function(file, next) {
var options = task.options({
flags: [],
debug: false
});

var build = browserify({debug : options.debug});
build.use(tagify.flags(options.flags));

var entries = grunt.file.expand({filter: 'isFile'}, file.src)
.map(function (f) {
return path.resolve(f);
}).forEach(function(entry) {
build.addEntry(entry);
});

grunt.file.write(file.dest, build.bundle());
});
});

// gnerate UI task
grunt.registerMultiTask('generateUI', 'Generate UI', function() {
this.files.forEach(function(file) {
if(file.src.length !== 1)
return grunt.fail.warn('You should specify one conf file');

var conf = file.src[0];
grunt.file.write(file.dest, UIGenerator.generate(conf));
});
});

// run servers tasks
grunt.registerMultiTask('runServer', 'Run server', function() {

var task = this;
var done = task.async();

this.files.forEach(function(file) {
if(file.src.length !== 1)
return grunt.fail.warn('You should specify one app file');

var options = task.options({
port: 8080,
keepalive: false
});

// can pass --port=%port%
if(grunt.option('port'))
options.port = parseInt(grunt.option('port'), 10);

// can pass --port=keepalive
if(grunt.option('keepalive'))
options.keepalive = grunt.option('keepalive');

// can do runServer:mainline:keepalive
if(typeof task.flags.keepalive == 'boolean')
options.keepalive = task.flags.keepalive;

var app = file.src[0];
require(app).server.listen(options.port)
.on('listening', function() {
if(!options.keepalive) done();
});

grunt.log.ok('Server running on http://localhost:'+options.port);

});
});

// load npm tasks
grunt.loadNpmTasks('grunt-mocha-test');
};
141 changes: 1 addition & 140 deletions Jakefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
var DOC_DIR = __dirname + '/doc/jsdoc/';
var LIB_DIR = __dirname + '/lib/';
var DIST_DIR = __dirname + '/dist/';
var JsDoc3_CONF = __dirname + '/doc/JsDocConf.json';
Expand Down Expand Up @@ -31,32 +30,11 @@ var PROC = require('child_process');
var COLORS = require('colors');
var UI = require(__dirname + '/UI/generator');

// ------------ DEFAULT ------------
desc('Say Hello to Kadoh');
task('default', [], function() {
var logo =
' \n' +
' _/ _/ _/ _/_/ _/ _/ \n' +
' _/ _/ _/_/_/ _/_/_/ _/ _/ _/ _/ \n' +
' _/_/ _/ _/ _/ _/ _/ _/ _/_/_/_/ \n' +
' _/ _/ _/ _/ _/ _/ _/ _/ _/ _/ \n' +
' _/ _/ _/_/_/ _/_/_/ _/_/ _/ _/ \n' +
' ';
console.log(logo.yellow);
});

// ------------ TESTS ------------
namespace('test', function() {
desc('Testing in node');
task('node', ['default'], function(reporter) {
reporter = reporter || 'dot'
var mocha = PROC.spawn('mocha', ['--colors', '--reporter', reporter]);
mocha.stdout.pipe(process.stdout, { end: false });
mocha.stderr.pipe(process.stderr, { end: false });
}, true);

desc('Testing in the browser');
task('browser', ['default'], function() {
task('browser', function() {
jake.Task['build:test'].execute();

var jasmine = require('jasmine-runner');
Expand All @@ -67,120 +45,3 @@ namespace('test', function() {
});
});
});

// ------------ DOC ------------
desc('Generate documentation using JsDoc3');
task('doc', ['default'], function(){
console.log('[Doc] Purging the doc folder');
var rm = 'rm -rf '+DOC_DIR;
console.log(rm);
PROC.exec(rm, function (error, stdout, stderr) {
console.log('[Doc] ' + stdout);
console.error('[Doc] Error :' + stderr);
if (error !== null) {
console.error('[Doc] Error : ' + error);
}
});

console.log('[Doc] Generating documentation..');

var cmd = JsDoc3_EXEC+' --recurse '+LIB_DIR +' --destination '+DOC_DIR +' -c '+JsDoc3_CONF;
console.log(cmd);

PROC.exec(cmd, function (error, stdout, stderr) {
console.log('[Doc] ' + stdout);
console.error('[Doc] Error :' + stderr);
if (error !== null) {
console.error('[Doc] Error : ' + error);
}
});
});

// ------------ BUILD ------------

var checked = ' done ✓'.green + '\n';

desc('Building and minifing the embedded code');
task('build', ['default'], function() {
jake.Task['build:xmpp'].execute();
jake.Task['build:simudp'].execute();
});

namespace('build', function() {

function build(type, debug) {
return function() {
var browserify = require('browserify');
var tagify = require('tagify');

process.stdout.write('Building '+type);

var build = browserify({debug : debug});
build.use(tagify.flags([type, 'lawnchair']));
build.addEntry(LIB_DIR+'index-browserify.js');

fs.writeFileSync(
DIST_DIR+'KadOH.'+type+'.js',
build.bundle()
);

process.stdout.write(checked);
};
}

desc('Building the brower-side code with xmpp configuration');
task('xmpp', ['default'], build('xmpp', false));

desc('Building the brower-side code with simudp configuration');
task('simudp', ['default'], build('simudp', false));
});

// ------------ UI GENERATE ------------

namespace('generate', function() {

function generate(type) {
return function() {
process.stdout.write('Creating '+type+' UI');
fs.writeFileSync(
UI_FILES[type].index,
UI.generate(UI_FILES[type].conf)
);
process.stdout.write(checked);
}
}

desc('Generate the mainline proxy app UI');
task('mainline', ['default'], generate('mainline'));

desc('Generate the udp proxy app UI');
task('udp', ['default'], generate('udp'));

desc('Generate the xmpp app UI');
task('xmpp', ['default'], generate('xmpp'));
});

// ------------ RUN SERVER ------------

namespace('run', function() {

function run(type) {
return function(port) {
port = parseInt(port, 10) || 8080 ;
require(UI_FILES[type].app).server.listen(port);
console.log('Server running on http://localhost:'+port);
}
}

desc('Run the mainline proxy app server');
task('mainline', ['generate:mainline'], run('mainline'));

desc('Run the udp proxy app server');
task('udp', ['generate:udp'], run('udp'));

desc('Run the xmpp app server');
task('xmpp', ['generate:xmpp'], run('xmpp'));

desc('Run the boilerplate app server');
task('boilerplate', run('boilerplate'));
});
Loading