Skip to content

Instantly share code, notes, and snippets.

@generalov
Created May 31, 2014 04:28
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save generalov/c4fd618ebf8a98d17cbe to your computer and use it in GitHub Desktop.
Save generalov/c4fd618ebf8a98d17cbe to your computer and use it in GitHub Desktop.
Gruntfile config to run python tornado application and node.js fronted with livereload
/* jslint node:true */
'use strict';
module.exports = function(grunt) {
grunt.registerTask('default', [
'serve'
]);
grunt.registerTask('serve', [
'configureProxies:server',
'connect:server',
'open:dev',
'concurrent:dev'
]);
grunt.registerTask('test', [
'nodemon:test'
]);
var BIND_PORT = 8000;
var BIND_ALL_INTERFACES = false;
var BACKEND_HOST = '127.0.0.1';
var BACKEND_PORT = 8880;
require('load-grunt-tasks')(grunt);
grunt.initConfig({
//
pkg: grunt.file.readJSON('package.json'),
open: {
dev: {
path: 'http://localhost:' + BIND_PORT + '/',
app: 'google-chrome'
}
},
concurrent: {
dev: {
tasks: ['nodemon:dev', 'watch'],
options: {
logConcurrentOutput: true
}
}
},
less: {
dev: {
options: {
paths: ["static/css"]
},
files: {
"static/css/main.css": "static/css/main.less"
}
},
},
nodemon: {
test: {
options: {
exec: 'python -m tornado.test.runtests discover -t . -s test/ -vvv',
watch: ['**/*.py'],
ext: 'py',
}
},
dev: {
options: {
exec: 'python application.py --logging=debug --debug=true --port=' + BACKEND_PORT,
watch: ['**/*.py', 'templates/**/*.html'],
ext: 'py html',
callback: function(nodemon) {
nodemon.on('log', function(event) {
console.log(event.colour);
});
nodemon.on('restart', function() {
// Delay before server listens on port
setTimeout(function() {
require('fs').writeFileSync('.rebooted', 'rebooted');
}, 1000);
});
}
}
}
},
watch: {
server: {
files: ['.rebooted'],
options: {
livereload: true
}
},
less: {
files: ['static/**/*.less'],
tasks: ['less:dev'],
},
css: {
files: ['static/**/*.css'],
options: {
livereload: true
}
},
js: {
files: ['static/**/*.js'],
options: {
livereload: true
}
},
config: {
files: ['Gruntfile.js', 'package.json'],
options: {
reload: true
}
}
},
connect: {
server: {
options: {
port: BIND_PORT,
hostname: BIND_ALL_INTERFACES ? '*' : 'localhost',
livereload: true,
middleware: function(connect, options, middlewares) {
middlewares.unshift(
require('grunt-connect-proxy/lib/utils').proxyRequest
);
return middlewares;
}
},
proxies: [{
context: ['!/static', '/'],
host: BACKEND_HOST,
port: BACKEND_PORT,
https: false,
changeOrigin: false,
xforward: false
}]
}
}
});
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment