Skip to content

Commit

Permalink
Merge pull request #455 from nus-fboa2016-si/webpack
Browse files Browse the repository at this point in the history
Integrating gulp, webpack, babel
  • Loading branch information
rauchg committed Feb 24, 2016
2 parents 692f18c + 4c2a7b3 commit 9748f6b
Show file tree
Hide file tree
Showing 9 changed files with 199 additions and 107 deletions.
6 changes: 0 additions & 6 deletions .zuul.yml

This file was deleted.

29 changes: 6 additions & 23 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,36 +3,19 @@ REPORTER = dot

build: engine.io.js

engine.io.js: lib/*.js lib/transports/*.js package.json
@./support/browserify.sh > engine.io.js
engine.io.js:
@./node_modules/.bin/gulp build

test:
@if [ "x$(BROWSER_NAME)" = "x" ]; then make test-node; else make test-zuul; fi
@./node_modules/.bin/gulp test

test-node:
@./node_modules/.bin/mocha \
--reporter $(REPORTER) \
--require test/support/server.js \
test/index.js
@./node_modules/.bin/gulp test-node

test-zuul:
@if [ "x$(BROWSER_PLATFORM)" = "x" ]; then \
./node_modules/zuul/bin/zuul \
--browser-name $(BROWSER_NAME) \
--browser-version $(BROWSER_VERSION) \
test/index.js; \
else \
./node_modules/zuul/bin/zuul \
--browser-name $(BROWSER_NAME) \
--browser-version $(BROWSER_VERSION) \
--browser-platform "$(BROWSER_PLATFORM)" \
test/index.js; \
fi
@./node_modules/.bin/gulp test-zuul

test-cov:
@./node_modules/.bin/istanbul cover ./node_modules/.bin/_mocha -- \
--require ./test/common \
--reporter $(REPORTER) \
$(TESTS)
@./node_modules/.bin/gulp test-cov

.PHONY: test build
117 changes: 117 additions & 0 deletions gulpfile.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
const gulp = require("gulp");
const mocha = require("gulp-mocha");
const istanbul = require("gulp-istanbul");
const file = require("gulp-file");
const webpack = require('webpack-stream');
const child = require("child_process");
const help = require("gulp-task-listing");
const del = require('del');

gulp.task("help", help);

////////////////////////////////////////
// BUILDING
////////////////////////////////////////

const BUILD_TARGET_FILENAME = "engine.io.js";
const BUILD_TARGET_DIR = "./";

gulp.task("default", ["build"]);

gulp.task("build", function() {
return gulp.src(["lib/*.js", "lib/transports/*.js"], {
base: 'lib'
})
.pipe(webpack(require("./support/webpack.config.js")))
.pipe(gulp.dest(BUILD_TARGET_DIR));
});

////////////////////////////////////////
// TESTING
////////////////////////////////////////

const REPORTER = "dot";
const TEST_FILE = "./test/index.js";
const TEST_SUPPORT_SERVER_FILE = "./test/support/server.js";
const FILES_TO_CLEAN = [
'test/support/public/engine.io.js'
];

gulp.task("test", function() {
if (process.env.hasOwnProperty("BROWSER_NAME")) {
return testZuul();
} else {
return testNode();
}
});

gulp.task("test-node", testNode);
gulp.task("test-zuul", testZuul);

function testNode() {
const MOCHA_OPTS = {
reporter: REPORTER,
require: [TEST_SUPPORT_SERVER_FILE],
bail: true
};
return gulp.src(TEST_FILE, { read: false })
.pipe(mocha(MOCHA_OPTS))
// following lines to fix gulp-mocha not terminating (see gulp-mocha webpage)
.once("error", function(err) {
console.error(err.stack);
cleanFiles(FILES_TO_CLEAN);
process.exit(1);
})
.once("end", function() {
cleanFiles(FILES_TO_CLEAN);
process.exit();
});
}

// runs zuul through shell process
function testZuul() {
const ZUUL_CMD = "./node_modules/zuul/bin/zuul";
const args = [
"--browser-name",
process.env.BROWSER_NAME,
"--browser-version",
process.env.BROWSER_VERSION
];
if (process.env.hasOwnProperty("BROWSER_PLATFORM")) {
args.push("--browser-platform");
args.push(process.env.BROWSER_PLATFORM);
}
args.push(TEST_FILE);
const zuulChild = child.spawn(ZUUL_CMD, args, { stdio: "inherit" });
zuulChild.on("exit", function (code) {
cleanFiles(FILES_TO_CLEAN);
process.exit(code);
});
}

function cleanFiles(globArray) {
return del.sync(globArray);
}

gulp.task('istanbul-pre-test', function() {
return gulp.src(['lib/**/*.js'])
// Covering files
.pipe(istanbul())
// Force `require` to return covered files
.pipe(istanbul.hookRequire());
});

gulp.task('test-cov', ['istanbul-pre-test'], function() {
return gulp.src(['test/*.js', 'test/support/*.js'])
.pipe(mocha({
reporter: REPORTER
}))
.pipe(istanbul.writeReports())
.once('error', function(err) {
console.error(err.stack);
process.exit(1);
})
.once('end', function() {
process.exit();
});
});
29 changes: 20 additions & 9 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,34 +23,45 @@
}
],
"dependencies": {
"has-cors": "1.1.0",
"ws": "1.0.1",
"xmlhttprequest-ssl": "1.5.1",
"component-emitter": "1.1.2",
"indexof": "0.0.1",
"engine.io-parser": "1.2.4",
"component-inherit": "0.0.3",
"debug": "2.2.0",
"parseuri": "0.0.4",
"engine.io-parser": "1.2.4",
"has-cors": "1.1.0",
"indexof": "0.0.1",
"parsejson": "0.0.1",
"parseqs": "0.0.2",
"component-inherit": "0.0.3",
"parseuri": "0.0.4",
"ws": "1.0.1",
"xmlhttprequest-ssl": "1.5.1",
"yeast": "0.1.2"
},
"devDependencies": {
"babel-core": "6.4.5",
"babel-loader": "6.2.1",
"babel-preset-es2015": "6.3.13",
"blob": "0.0.4",
"browserify": "6.2.0",
"concat-stream": "1.4.6",
"del": "2.2.0",
"derequire": "1.2.0",
"engine.io": "1.6.7",
"expect.js": "0.2.0",
"express": "3.4.8",
"gulp": "3.9.0",
"gulp-file": "0.2.0",
"gulp-istanbul": "0.10.3",
"gulp-mocha": "2.2.0",
"gulp-task-listing": "1.0.1",
"istanbul": "0.2.3",
"mocha": "1.16.2",
"webpack": "1.12.12",
"webpack-stream": "3.1.0",
"zuul": "3.7.2",
"zuul-builder-webpack": "1.1.0",
"zuul-ngrok": "3.2.0"
},
"scripts": {
"test": "make test"
"test": "gulp test"
},
"browser": {
"ws": false,
Expand Down
52 changes: 0 additions & 52 deletions support/browserify.js

This file was deleted.

6 changes: 0 additions & 6 deletions support/browserify.sh

This file was deleted.

34 changes: 34 additions & 0 deletions support/webpack.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@

module.exports = {
entry: "./index.js",
output: {
filename: "engine.io.js",
library: "eio",
libraryTarget: "umd"
},
externals: {
global: glob()
},
module: {
loaders: [{
test: /\.js$/,
exclude: /(node_modules|bower_components)/,
loader: 'babel', // 'babel-loader' is also a legal name to reference
query: {
presets: ['es2015']
}
}]
}
};

/**
* Populates `global`.
*
* @api private
*/

function glob() {
return 'typeof self !== "undefined" ? self : ' +
'typeof window !== "undefined" ? window : ' +
'typeof global !== "undefined" ? global : {}';
}
21 changes: 10 additions & 11 deletions test/support/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,21 @@ var app = express();
var join = require('path').join;
var http = require('http').Server(app);
var server = require('engine.io').attach(http, {'pingInterval': 500});
var browserify = require('../../support/browserify');
var webpack = require('webpack');

http.listen(process.env.ZUUL_PORT || 3000);
var webpackConfig = require('../../support/webpack.config.js');

// server worker.js as raw file
app.use('/test/support', express.static(join(__dirname, 'public')));
webpackConfig.output.path = 'test/support/public';

// server engine.io.js via browserify
app.get('/test/support/engine.io.js', function(err, res, next) {
browserify(function(err, src) {
if (err) return next(err);
res.set('Content-Type', 'application/javascript');
res.send(src);
});
webpack(webpackConfig, function(err, stats){
if (err) console.log(err);
});

http.listen(process.env.ZUUL_PORT || 3000);

// serve worker.js and engine.io.js as raw file
app.use('/test/support', express.static(join(__dirname, 'public')));

server.on('connection', function(socket){
socket.send('hi');

Expand Down
12 changes: 12 additions & 0 deletions zuul.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@

module.exports = {
ui: 'mocha-bdd',
server: './test/support/server.js',
tunnel: {
type: 'ngrok',
authtoken: '6Aw8vTgcG5EvXdQywVvbh_3fMxvd4Q7dcL2caAHAFjV',
proto: 'tcp'
},
builder: 'zuul-builder-webpack',
webpack: require('./support/webpack.config.js')
};

0 comments on commit 9748f6b

Please sign in to comment.