2016-10-14 12:32:53 +02:00
|
|
|
var gulp = require('gulp');
|
|
|
|
var concat = require('gulp-concat');
|
|
|
|
var sort = require('gulp-sort');
|
|
|
|
var minify = require('gulp-minify');
|
2016-10-18 13:37:38 +02:00
|
|
|
var plumber = require('gulp-plumber');
|
|
|
|
var istanbul = require('gulp-istanbul');
|
|
|
|
var mocha = require('gulp-mocha');
|
2016-10-25 17:57:32 +02:00
|
|
|
var watch = require('gulp-watch');
|
2016-11-21 14:36:38 +01:00
|
|
|
var preprocessor = require('gulp-c-preprocessor');
|
2016-10-14 12:32:53 +02:00
|
|
|
|
|
|
|
gulp.task(
|
|
|
|
'build',
|
|
|
|
function() {
|
|
|
|
return gulp.src('./src/game-lib-*.js')
|
|
|
|
.pipe(sort())
|
|
|
|
.pipe(concat('game-lib.js'))
|
|
|
|
.pipe(minify({
|
|
|
|
ext:{
|
2016-10-14 13:08:22 +02:00
|
|
|
src:'.js',
|
|
|
|
min:'-min.js'
|
2016-10-14 12:32:53 +02:00
|
|
|
}
|
|
|
|
}))
|
|
|
|
.pipe(gulp.dest('./build/'));
|
|
|
|
}
|
|
|
|
);
|
|
|
|
|
2016-10-18 13:37:38 +02:00
|
|
|
gulp.task('test-prepare', function(){
|
2016-10-18 13:49:03 +02:00
|
|
|
return gulp.src('./build/game-lib.js')
|
2016-10-18 13:37:38 +02:00
|
|
|
.pipe(plumber())
|
|
|
|
.pipe(istanbul())
|
|
|
|
.pipe(istanbul.hookRequire())
|
|
|
|
.on('end', function(){
|
|
|
|
console.log('prepared the game lib for code coverage');
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
gulp.task(
|
|
|
|
'test',
|
|
|
|
['build', 'test-prepare'],
|
|
|
|
function() {
|
|
|
|
gulp.src('./test/test.*.js')
|
|
|
|
.pipe(sort())
|
|
|
|
.pipe(plumber())
|
|
|
|
.pipe(mocha({reporter: 'spec'}))
|
2016-10-18 13:49:03 +02:00
|
|
|
.pipe(istanbul.writeReports({
|
2016-10-24 15:56:28 +02:00
|
|
|
dir: './build/coverage'
|
2016-10-18 13:49:03 +02:00
|
|
|
}))
|
2016-10-24 15:56:28 +02:00
|
|
|
.pipe(istanbul.enforceThresholds({thresholds:{global:1}}))
|
2016-10-18 13:37:38 +02:00
|
|
|
.on('error',
|
|
|
|
function(error) {
|
|
|
|
console.log('plugin error occurred' + error);
|
|
|
|
}
|
|
|
|
)
|
|
|
|
.on('end',
|
|
|
|
function() {
|
|
|
|
console.log('test task ended')
|
|
|
|
}
|
|
|
|
);
|
|
|
|
}
|
|
|
|
);
|
|
|
|
|
2016-11-21 14:36:38 +01:00
|
|
|
|
|
|
|
gulp.task('compileRuntime', ['build'],
|
|
|
|
function() {
|
2016-11-23 11:06:08 +01:00
|
|
|
gulp.src(['./defines/runtime.js', './build/game-lib.js'])
|
2016-11-21 14:36:38 +01:00
|
|
|
.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', ['build'],
|
|
|
|
function() {
|
2016-11-23 11:06:08 +01:00
|
|
|
gulp.src(['./defines/editor.js', './build/game-lib.js'])
|
2016-11-21 14:36:38 +01:00
|
|
|
.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/'));
|
|
|
|
}
|
|
|
|
);
|
|
|
|
|
|
|
|
|
2016-10-14 12:32:53 +02:00
|
|
|
gulp.task(
|
|
|
|
'default',
|
2016-10-25 17:57:32 +02:00
|
|
|
[
|
2016-11-21 14:36:38 +01:00
|
|
|
'build',
|
|
|
|
'compileRuntime',
|
|
|
|
'compileEditor'
|
2016-10-25 17:57:32 +02:00
|
|
|
],
|
|
|
|
function() {
|
|
|
|
return watch([
|
|
|
|
'src/*.js'
|
|
|
|
],
|
|
|
|
function() {
|
|
|
|
gulp.start([
|
2016-11-21 14:36:38 +01:00
|
|
|
'build',
|
|
|
|
'compileRuntime',
|
|
|
|
'compileEditor'
|
2016-10-25 17:57:32 +02:00
|
|
|
]);
|
|
|
|
})
|
|
|
|
}
|
2016-10-14 12:32:53 +02:00
|
|
|
);
|