diff --git a/.gitignore b/.gitignore index 205d225..cf86297 100644 --- a/.gitignore +++ b/.gitignore @@ -20,9 +20,6 @@ Gemfile.lock # hookio config.json -# jake -.jake_tasks - # jasmine-node .monitor diff --git a/.travis.yml b/.travis.yml index eb93765..3f625d4 100644 --- a/.travis.yml +++ b/.travis.yml @@ -7,5 +7,8 @@ branches: language: node_js node_js: - - 0.6 - - 0.8 \ No newline at end of file + - 0.8 + - 0.10 + +before_script: + - npm install -g grunt-cli diff --git a/Gruntfile.js b/Gruntfile.js new file mode 100644 index 0000000..b5e715c --- /dev/null +++ b/Gruntfile.js @@ -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'); +}; diff --git a/Jakefile b/Jakefile index a7b0de4..668f1ea 100644 --- a/Jakefile +++ b/Jakefile @@ -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'; @@ -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'); @@ -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')); -}); \ No newline at end of file diff --git a/README.md b/README.md index 02f0fe4..9cd322e 100644 --- a/README.md +++ b/README.md @@ -24,10 +24,10 @@ First you can start a little DHT based on UDP transport using this command : bin/dht udp.default ``` -Then in an other terminal, start the web-based [debug UI](/jinroh/kadoh/wiki/Debug-UI) using the following Jake command and go to `localhost:8080` : +Then in an other terminal, start the web-based [debug UI](/jinroh/kadoh/wiki/Debug-UI) using the following grunt task and go to `localhost:8080` : ```sh -jake run:udp +grunt run:udp ``` See the wiki for more informations on how to [launch your own DHT](/jinroh/kadoh/wiki/DHT-simulation) from scratch and on different environments. @@ -36,7 +36,7 @@ See the wiki for more informations on how to [launch your own DHT](/jinroh/kadoh ### Install KadOH -The only required dependency is [node.js](http://nodejs.org/) (version >= 0.6, but you clould try below..). Take a look at the [official manual](https://github.com/joyent/node/wiki/Installing-Node.js-via-package-manager) to install node on your system. +The only required dependency is [node.js](http://nodejs.org/) (version >= 0.8). Take a look at the [official manual](https://github.com/joyent/node/wiki/Installing-Node.js-via-package-manager) to install node on your system. Then run : @@ -47,10 +47,10 @@ cd kadoh npm install ``` -You may also want to install the Jake module globally : +If not already done, you may also want to install the [grunt](gruntjs.com) command line: ``` -npm install -g jake +npm install -g grunt-cli ``` *For Linux users*, if the installation of KadOH's dependencies fails, you may need to install the `libexpat-dev` package. For Ubuntu/Debian users, run the following command : @@ -63,10 +63,10 @@ sudo apt-get install libexpat-dev #### Browser -To build the source inside the `dist` folder run one of the following Jake command : +To build the source inside the `dist` folder run one of the following grunt task : ```sh -jake build +grunt build ``` This will build two versions of KadOH supporting different transports : @@ -102,6 +102,6 @@ KadOH is built on top of many open-source libraries and projects: *For the moment, tests are not running anymore.. But we hope that will be fixed as soon as we migrate to Mocha.* ``` -jake test:node -jake test:browser +grunt test:node +grunt test:browser ``` diff --git a/kadoh.ascii.txt b/kadoh.ascii.txt new file mode 100644 index 0000000..5b02f60 --- /dev/null +++ b/kadoh.ascii.txt @@ -0,0 +1,6 @@ + + _/ _/ _/ _/_/ _/ _/ + _/ _/ _/_/_/ _/_/_/ _/ _/ _/ _/ + _/_/ _/ _/ _/ _/ _/ _/ _/_/_/_/ + _/ _/ _/ _/ _/ _/ _/ _/ _/ _/ + _/ _/ _/_/_/ _/_/_/ _/_/ _/ _/ diff --git a/package.json b/package.json index be53df9..ee2056e 100644 --- a/package.json +++ b/package.json @@ -1,46 +1,61 @@ { - "name": "kadoh" - , "version": "0.1.0" - , "description": "Kademlia over HTTP in Javascript" - , "keywords":["p2p", "kad", "kademlia", "dht", "mainline", "bittorrent", "http", "xmpp", "bosh", "udp", "socket.io"] - , "contributors": [ - "Alexandre Lachèze " - , "Pierre Guilleminot " - ] - , "repository":{ - "type": "git" - , "url": "https://github.com/jinroh/kadoh.git" - } - , "main" : "./lib/index.js" - , "browserify" : "./lib/index-browserify.js" - , "dependencies": { - "colors" : "~0.6" - , "connect" : "~2.0" - , "express" : "~2.5" - , "ifconfig.me" : "https://github.com/alexstrat/ifconfig.me-node/tarball/master" - , "jake" : "~0.1" - , "klass" : "~1.2" - , "ltx" : ">= 0.2.0" - , "node-xmpp" : "~0.3" - , "bncode" : "~0.2" - , "socket.io" : "~0.9" - , "socket.io-client" : "https://github.com/substack/socket.io-client/tarball/master" - , "mustache" : "~0.4" - , "browserify" : "https://github.com/alexstrat/node-browserify/tarball/for-kadoh" - , "tagify" : "*" - , "Strophe.js" : "https://github.com/alexstrat/strophejs/tarball/for-kadoh" - }, - "scripts": { - "test": "jake test:node[spec]" - }, - "devDependencies": { - "mocha" : "~1.0" - , "chai" : "~1.0" - , "sinon-chai" : "~2.1" - , "sinon" : "~1.3" - , "optimist" : "~0.3" - , "nconf" : "~0.5" - , "multimeter" : "~0.1" - } - , "engines": { "node": ">= 0.6.0" } -} \ No newline at end of file + "name": "kadoh", + "version": "0.1.0", + "description": "Kademlia over HTTP in Javascript", + "keywords": [ + "p2p", + "kad", + "kademlia", + "dht", + "mainline", + "bittorrent", + "http", + "xmpp", + "bosh", + "udp", + "socket.io" + ], + "contributors": [ + "Alexandre Lachèze ", + "Pierre Guilleminot " + ], + "repository": { + "type": "git", + "url": "https://github.com/jinroh/kadoh.git" + }, + "main": "./lib/index.js", + "browserify": "./lib/index-browserify.js", + "dependencies": { + "colors": "~0.6", + "connect": "~2.0", + "express": "~2.5", + "ifconfig.me": "https://github.com/alexstrat/ifconfig.me-node/tarball/master", + "klass": "~1.2", + "ltx": ">= 0.2.0", + "node-xmpp": "~0.3", + "bncode": "~0.2", + "socket.io": "~0.9", + "socket.io-client": "https://github.com/substack/socket.io-client/tarball/master", + "mustache": "~0.4", + "browserify": "https://github.com/alexstrat/node-browserify/tarball/for-kadoh", + "tagify": "*", + "Strophe.js": "https://github.com/alexstrat/strophejs/tarball/for-kadoh" + }, + "scripts": { + "test": "grunt test:node" + }, + "devDependencies": { + "mocha": "~1.0", + "chai": "~1.0", + "sinon-chai": "~2.1", + "sinon": "~1.3", + "optimist": "~0.3", + "nconf": "~0.5", + "multimeter": "~0.1", + "grunt": "~0.4.1", + "grunt-mocha-test": "~0.7.0" + }, + "engines": { + "node": ">= 0.8.0" + } +}