r3-legacy/gulpfile.js

174 lines
4.5 KiB
JavaScript

var gulp = require('gulp');
var concat = require('gulp-concat');
var sort = require('gulp-sort');
var minify = require('gulp-minify');
var plumber = require('gulp-plumber');
var istanbul = require('gulp-istanbul');
var mocha = require('gulp-mocha');
var watch = require('gulp-watch');
var preprocessor = require('gulp-c-preprocessor');
gulp.task(
'merge',
function() {
return gulp.src('./src/game-lib-*.js')
.pipe(sort())
.pipe(concat('game-lib.js'))
.pipe(minify({
ext:{
src:'.js',
min:'-min.js'
}
}))
.pipe(gulp.dest('./build/'));
}
);
gulp.task('test-prepare', function(){
return gulp.src('./build/game-lib.js')
.pipe(plumber())
.pipe(istanbul())
.pipe(istanbul.hookRequire())
.on('end', function(){
console.log('prepared the game lib for code coverage');
});
});
gulp.task(
'test',
['merge', 'test-prepare'],
function() {
gulp.src('./test/test.*.js')
.pipe(sort())
.pipe(plumber())
.pipe(mocha({reporter: 'spec'}))
.pipe(istanbul.writeReports({
dir: './build/coverage'
}))
.pipe(istanbul.enforceThresholds({thresholds:{global:1}}))
.on('error',
function(error) {
console.log('plugin error occurred' + error);
}
)
.on('end',
function() {
console.log('test task ended')
}
);
}
);
gulp.task('compileRuntime', ['merge'],
function() {
gulp.src(['./defines/runtime.js', './build/game-lib.js'])
.pipe(concat('game-lib-runtime.js'))
.pipe(preprocessor(
{
// End of line character
endLine: '\n',
// Escape '//#' & '/*#' comments (see extra/comments)
commentEscape: true,
// Empty lines to add between code and included files
includeSpaces: 0,
// Limit of empty following lines (0 = no limit)
emptyLinesLimit: 0,
// Base path for including files
basePath: './',
// Stop the compiler when an error ocurred ?
stopOnError: true,
// Constants in #enum command must be in hexadecimal ?
enumInHex: true
})
)
.pipe(minify({
ext:{
src:'.js',
min:'-min.js'
}
}))
.pipe(gulp.dest('./build/'));
}
);
gulp.task('compileEditor', ['merge'],
function() {
gulp.src(['./defines/editor.js', './build/game-lib.js'])
.pipe(concat('game-lib-editor.js'))
.pipe(preprocessor(
{
// End of line character
endLine: '\n',
// Escape '//#' & '/*#' comments (see extra/comments)
commentEscape: true,
// Empty lines to add between code and included files
includeSpaces: 0,
// Limit of empty following lines (0 = no limit)
emptyLinesLimit: 0,
// Base path for including files
basePath: './',
// Stop the compiler when an error ocurred ?
stopOnError: true,
// Constants in #enum command must be in hexadecimal ?
enumInHex: true
})
)
.pipe(minify({
ext:{
src:'.js',
min:'-min.js'
}
}))
.pipe(gulp.dest('./build/'));
}
);
gulp.task(
'build',
[
'merge',
'compileRuntime',
'compileEditor'
],
function() {
}
);
gulp.task(
'default',
[
'merge',
'compileRuntime',
'compileEditor'
],
function() {
return watch([
'src/*.js'
],
function() {
gulp.start([
'merge',
'compileRuntime',
'compileEditor'
]);
})
}
);