Skip to content

Instantly share code, notes, and snippets.

@formula1
Last active October 15, 2015 17:58
Show Gist options
  • Save formula1/f205258f8baf2beead98 to your computer and use it in GitHub Desktop.
Save formula1/f205258f8baf2beead98 to your computer and use it in GitHub Desktop.
Boiler Plate
/node_modules

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 <environemts>', '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){
console.log('watching: '+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');
program.runner();
});
})
});
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
{
"name": "docker-boiler-plate",
"version": "1.0.0",
"description": "A Boiler Plate for docker setup",
"main": "server",
"scripts": {
"test": "mocha"
},
"repository": {
"type": "git",
"url": "[email protected]:450d2c01884b0e1d3267.git"
},
"author": "formula1 <[email protected]> (https://github.com/formula1)",
"license": "ISC",
"dependencies": {
"async": "^1.4.2",
"browserify": "^11.2.0",
"commander": "^2.9.0",
"node-watch": "^0.3.4",
"uglify-js": "^2.5.0"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment