mirror of
https://github.com/socketio/socket.io.git
synced 2026-04-30 03:00:39 -04:00
122 lines
2.9 KiB
JavaScript
122 lines
2.9 KiB
JavaScript
var gulp = require('gulp');
|
|
var mocha = require('gulp-mocha');
|
|
var file = require('gulp-file');
|
|
var istanbul = require('gulp-istanbul');
|
|
var webpack = require('webpack-stream');
|
|
var exec = require('child_process').exec;
|
|
|
|
var browserify = require('./support/browserify.js');
|
|
|
|
gulp.task('build-webpack', function() {
|
|
return gulp.src('lib/*.js')
|
|
.pipe(webpack({
|
|
entry: './lib/index.js',
|
|
output: {
|
|
library: 'io',
|
|
libraryTarget: 'umd',
|
|
filename: 'socket.io.js',
|
|
},
|
|
externals: {
|
|
'global': glob()
|
|
},
|
|
module: {
|
|
loaders: [{
|
|
test: /\.(js|jsx)?$/,
|
|
exclude: /(node_modules|bower_components)/,
|
|
loader: 'babel', // 'babel-loader' is also a legal name to reference
|
|
query: {
|
|
presets: ['react', 'es2015']
|
|
}
|
|
}]
|
|
}
|
|
}))
|
|
.pipe(gulp.dest('./'));
|
|
});
|
|
|
|
gulp.task('build', function(){
|
|
browserify(function(err, out){
|
|
if(err){
|
|
throw err;
|
|
}else{
|
|
gulp.src('')
|
|
.pipe(file('socket.io.js', out))
|
|
.pipe(gulp.dest('./'));
|
|
}
|
|
});
|
|
});
|
|
|
|
gulp.task('test', [process.env.BROWSER_NAME ? 'test-zuul' : 'test-node'], function(){
|
|
});
|
|
|
|
gulp.task('test-zuul', function(){
|
|
if(process.env.BROWSER_PLATFORM){
|
|
exec('./node_modules/zuul/bin/zuul ' +
|
|
'--browser-name ' + process.env.BROWSER_NAME + ' ' +
|
|
'--browser-version ' + process.env.BROWSER_VERSION + ' ' +
|
|
'--browser-platform ' +process.env.BROWSER_PLATFORM + ' ' +
|
|
'test/index.js',
|
|
function(err, stdout, stderr){
|
|
console.log(stdout);
|
|
console.error(stderr);
|
|
});
|
|
}else{
|
|
exec('./node_modules/zuul/bin/zuul ' +
|
|
'--browser-name ' + process.env.BROWSER_NAME + ' ' +
|
|
'--browser-version ' + process.env.BROWSER_VERSION + ' ' +
|
|
'test/index.js',
|
|
function(err, stdout, stderr){
|
|
console.log(stdout);
|
|
console.error(stderr);
|
|
});
|
|
}
|
|
});
|
|
|
|
gulp.task('test-node', function(){
|
|
gulp.src(['test/*.js', 'test/support/*.js'])
|
|
.pipe(mocha({
|
|
reporter: 'dot',
|
|
bail: true
|
|
}))
|
|
.once('error', function (err) {
|
|
console.error(err.stack);
|
|
process.exit(1);
|
|
})
|
|
.once('end', function () {
|
|
process.exit();
|
|
});
|
|
});
|
|
|
|
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(){
|
|
gulp.src(['test/*.js', 'test/support/*.js'])
|
|
.pipe(mocha({
|
|
reporter: 'dot'
|
|
}))
|
|
.pipe(istanbul.writeReports())
|
|
.once('error', function (){
|
|
process.exit(1);
|
|
})
|
|
.once('end', function (){
|
|
process.exit();
|
|
});
|
|
});
|
|
|
|
/**
|
|
* Populates `global`.
|
|
*
|
|
* @api private
|
|
*/
|
|
|
|
function glob(){
|
|
return 'typeof self !== "undefined" ? self : '
|
|
+ 'typeof window !== "undefined" ? window : '
|
|
+ 'typeof global !== "undefined" ? global : {}';
|
|
}
|