Skip to content

Instantly share code, notes, and snippets.

@billyvg
Created May 28, 2014 23:56
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save billyvg/2a7321623b2d2a87381c to your computer and use it in GitHub Desktop.
Save billyvg/2a7321623b2d2a87381c to your computer and use it in GitHub Desktop.
grunt task for integrating with fb-flo
module.exports = function(grunt) {
// easy way to load grunt tasks in package.json
// require('load-grunt-tasks')(grunt);
// or the normal way
grunt.task.loadNpmTasks('grunt-concurrent');
grunt.task.loadNpmTasks('grunt-contrib-connect');
grunt.task.loadNpmTasks('grunt-contrib-watch');
// configure local dev server
grunt.config('connect.dev', {
options: {
port: 7070,
hostname: '0.0.0.0',
keepalive: true,
base: './src/web',
middleware: function(connect, options) {
return [
function(req, res, next) {
// magic to server my SPA
if (req.url === '/' || req.url.substring(0, 6) === '/live/') {
res.end(grunt.file.read(grunt.config('woopra.dev_index_path')));
}
else if (req.url.match(/^\/TestRunner/)) {
res.end(grunt.file.read(grunt.config('woopra.test_runner_path')));
}
else {
next();
}
},
connect.static(__dirname),
connect.static(options.base),
connect.static('src'),
connect.static('src/build/web')
];
}
}
});
// configure concurrent task to run your grunt-watch task, connect server, and flo server
grunt.config('concurrent.development', {
tasks: ['watch', 'connect:dev', 'flo'],
options: {
logConcurrentOutput: true
}
});
// configure your flo task
grunt.registerTask('flo', 'Runs the fb-flo server for live editing', function() {
var flo = require('fb-flo');
var path = require('path');
var fs = require('fs');
var done = this.async();
var WEBROOT = './src';
var server = flo(
WEBROOT,
{
port: 8889,
host: 'localhost',
verbose: false,
globs: [
'web/**/*.js',
'build/web/**/*.css'
]
},
function(fp, callback) {
if (fp.match(/\.js$/)) {
callback({
resourceURL: fp.replace(/^web\/js/, '/js'),
contents: fs.readFileSync(WEB_ROOT + '/' + fp).toString()
});
}
else if (fp.match(/^build.*?\.css$/)) {
callback({
resourceURL: fp.replace(/^build\/web\/css/, '/css'),
contents: fs.readFileSync(WEB_ROOT + '/' + fp).toString()
});
}
}
);
});
// alias
grunt.registerTask('develop', ['concurrent']);
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment