r3-legacy/gulpfile.js

201 lines
5.4 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');
var inject = require('gulp-inject-string');
var replace = require('gulp-string-replace');
gulp.task(
'merge',
function() {
var d = new Date();
var __DATE__ = JSON.stringify(d.toString());
console.log("Compiling start at", __DATE__);
var __EXTENDS__ = "";
return gulp.src('./src/r3-*.js')
.pipe(sort())
.pipe(concat('r3.js'))
.pipe(
inject.prepend(
"// COMPILE TIME DEFINITIONS (Generated via gulp) \n" +
"var __DATE__ = " + __DATE__ + "; \n" +
"// END COMPILE TIME DEFINITIONS \n \n"
)
)
.pipe(
replace(new RegExp('R3.D3.Utils.Extend\\(.*?\\);', 'g'), function (replacement) {
__EXTENDS__ += replacement + "\n";
return "//" + replacement;
})
)
.pipe(
inject.append(
"\n//EXTENDS\n"
)
)
.pipe(
replace(
"//EXTENDS", function() {
return "//EXTENDING INTERFACES (Generated via gulp) \n" + __EXTENDS__ + "//END EXTENDING";
}
)
)
.pipe(minify({
ext:{
src:'.js',
min:'-min.js'
}
}))
.pipe(gulp.dest('./build/'));
}
);
gulp.task('test-prepare', function(){
return gulp.src('./build/r3.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/r3.js'])
.pipe(concat('r3-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/r3.js'])
.pipe(concat('r3-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'
],
function() {
}
);
gulp.task(
'default',
[
'merge'
],
function() {
return watch([
'src/*.js'
],
function() {
gulp.start([
'merge'
]);
})
}
);