Skip to content

Instantly share code, notes, and snippets.

@RobAWilkinson
Forked from formula1/.gitignore
Created October 15, 2015 17:19
Show Gist options
  • Save RobAWilkinson/f00705e3fd0123aa06cd to your computer and use it in GitHub Desktop.
Save RobAWilkinson/f00705e3fd0123aa06cd to your computer and use it in GitHub Desktop.
Boiler Plate

Simple Boiler Plate

var pack = require(__dirname+"/package.json");
var browserify = require("browserify");
var uglify = require("uglify-js");
var fs = require("fs");
var watch = require("node-watch");
var async = require("async");
var cp = require('child_process');
var program = require('commander');
program
.version('0.0.1')
.option('-t, --test', 'Should test before build')
.option('-b, --build', 'Should Build')
.option('-e, --environment <environments>', 'Target Environment is server or client')
.parse(process.argv);
var build = {};
var watchers = {};
process.stdin.on("data", function(data){
if(data.toString() != "\n") return;
Object.keys(watchers).forEach(function(env){
watchers[env].runner();
});
});
process.nextTick(function(){
if(!program.environment) program.environment = ['server', 'client'];
program.environment.forEach(function(env){
if(!(env in build)) throw new Error(env+' is not available to be built on');
watchers[env] = {watcher: void 0, tasks:[]};
var tasks = watchers[env].tasks;
if(program.test) tasks.push(build[env].test);
if(program.build) tasks.push(build[env].build);
program.runner = runner(tasks);
watchers[env].watch = watch(__dirname + '/' + env, function(){
console.log('Watching for ' + env + ' changes');
});
})
});
function runner(tasks){
var running = false;
return function(){
if(running) return;
running = true;
async.series(tasks,function(e){
if(e) console.error(e);
running = false;
});
}
}
build.server = {
test: function(next){
next();
},
build: function(next){
next();
}
}
build.client = {
test: function(next){
cp.exec('mocha', next);
},
build: function(next){
var b = browserify(__dirname+"/client", {basedir:__dirname+"/lib"});
var writer = new fs.createWriteStream(__dirname+'/dist/client.js');
var bund = b.bundle();
bund.on("error",function(e){
console.log("Bundle Error");
next(e);
return;
});
bund.pipe(writer).on("finish",function(){
writer.close(function(){
var result;
try{
result = uglify.minify(__dirname+'/dist/client.js');
}catch(e){
console.log("Uglify Error");
return next(e);
}
fs.writeFile(__dirname+'/dist/client.min.js', result.code, next);
});
});
}
}
FROM ubuntu:15.04
RUN apt-get update
RUN apt-get install -y node python2.7 gcc make gyp build-essential
RUN mkdir -p /usr/src/app
ENV NODE_ENV=DEVELOPMENT
WORKDIR /usr/src/app
ONBUILD RUN npm install
ONBUILD COPY . /usr/src/app
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment