diff --git a/gulpfile.babel.js b/gulpfile.babel.js index a40a9cac2f62a0fc328222ddce85ce73db0c207e..cecae587a2e22e11052da3dc01371310086a74bd 100644 --- a/gulpfile.babel.js +++ b/gulpfile.babel.js @@ -1,7 +1,17 @@ const gulp = require('gulp'); + const babel = require('gulp-babel'); + const eslint = require('gulp-eslint'); +const mocha = require('gulp-mocha'); + +const nodemon = require('gulp-nodemon'); + +const Cache = require('gulp-file-cache'); + +const cache = new Cache(); + /** * Compile source files */ @@ -13,8 +23,10 @@ function compile() { // compile source to ES5 gulp.src('src/**/*.js') - .pipe(babel()) - .pipe(gulp.dest('build')); + .pipe(cache.filter()) // cache source files + .pipe(babel()) // compile only modified files + .pipe(cache.cache()) // cache compiled files + .pipe(gulp.dest('build')); // move compiled files to build directory // copy configuration file to build directory gulp.src('config.json') @@ -24,14 +36,37 @@ function compile() { gulp.task('build', compile); -gulp.task('run', ['build'], () => { +gulp.task('test', () => { + gulp.src('test/test.js', {read: false}) + .pipe(mocha()) + .once('error', () => { + process.exit(1); + }) + .once('end', () => { + process.exit(); + }); }); gulp.task('watch', [], () => { + console.log('Watching source directory for changes'); compile(); + gulp.watch('src/**/*.js').on('change', () => { + console.log('Recompiling source'); + compile(); + console.log('Source recompilation done') + }); }); -gulp.task('test', ['build'], () => { +gulp.task('run', () => { + process.chdir('build'); + nodemon({ + script: 'server.js', + tasks: ['watch'], + ignore: ["test/test.js", "gulpfile.babel.js"], + ext: 'js html json', + env: { 'NODE_ENV': 'development' } + }); }); -gulp.task('default', ['watch']); +gulp.task('default', ['run']); + diff --git a/package.json b/package.json index 713f494edf7c7206701be876b54663539bfdb9fb..06ea4fce17d05c284ee4b464d84c5f35352ca443 100644 --- a/package.json +++ b/package.json @@ -17,6 +17,7 @@ "cors": "^2.7.1", "csv-express": "^1.1.0", "debug": "~2.0.x", + "dirty-chai": "^1.2.2", "express": "^4.13.0", "faker": "^2.1.5", "forever": "^0.15.2", @@ -44,6 +45,12 @@ "gulp": "^3.9.1", "gulp-babel": "^6.1.2", "gulp-cli": "^1.2.2", - "gulp-eslint": "^3.0.1" + "gulp-eslint": "^3.0.1", + "gulp-file-cache": "0.0.1", + "gulp-mocha": "^3.0.1", + "gulp-nodemon": "^2.1.0", + "gulp-plumber": "^1.1.0", + "gulp-rename": "^1.2.2", + "gulp-uglify": "^2.0.0" } }