From b18e8315251114b9d35dedc1275645c1f25058b6 Mon Sep 17 00:00:00 2001 From: Kunal Kapadia Date: Fri, 5 Feb 2016 01:27:48 +0530 Subject: [PATCH] Add gulp copy - copy non-js files to dist --- README.md | 6 ++++-- gulpfile.babel.js | 30 +++++++++++++++++++----------- index.js | 2 +- package.json | 2 +- 4 files changed, 25 insertions(+), 15 deletions(-) diff --git a/README.md b/README.md index 3e3aad5e..63e26f7f 100644 --- a/README.md +++ b/README.md @@ -22,7 +22,7 @@ This is a boilerplate application for building REST APIs in Node.js using ES6 an | ES6 Code Coverage via [istanbul](https://www.npmjs.com/package/istanbul) | Supports code coverage of ES6 code using istanbul and mocha. Code coverage reports are saved in `coverage/` directory post `npm test` execution. Open `lcov-report/index.html` to view coverage report. `npm test` also displays code coverage summary on console. | | Debugging via [debug](https://www.npmjs.com/package/debug) | Instead of inserting and deleting console.log you can replace it with the debug function and just leave it there. You can then selectively debug portions of your code by setting DEBUG env variable. If DEBUG env variable is not set, nothing is displayed to the console. | | Promisified Code via [bluebird](https://github.com/petkaantonov/bluebird) | We love promise, don't we ? All our code is promisified and even so our tests via [supertest-as-promised](https://www.npmjs.com/package/supertest-as-promised). | -| API parameter validation via [express-validation](https://www.npmjs.com/package/express-validation) | Validate body, params, query, headers and cookies of a request (via middleware) and return a response with errors; if any of the configured validation rules fail.| +| API parameter validation via [express-validation](https://www.npmjs.com/package/express-validation) | Validate body, params, query, headers and cookies of a request (via middleware) and return a response with errors; if any of the configured validation rules fail. You won't anymore need to make your route handler dirty with such validations. | - CORS support via [cors](https://github.com/troygoode/node-cors) - Uses [http-status](https://www.npmjs.com/package/http-status) to set http status code. It is recommended to use `httpStatus.INTERNAL_SERVER_ERROR` instead of directly using `500` when setting status code. @@ -66,9 +66,11 @@ Other gulp tasks: ```sh # Wipe out dist and coverage directory gulp clean + # Lint code with ESLint gulp lint -# Default task: Wipes out dist and coverage direcotory. Compiles using babel. + +# Default task: Wipes out dist and coverage directory. Compiles using babel. gulp ``` diff --git a/gulpfile.babel.js b/gulpfile.babel.js index de864a4f..ff598ed8 100644 --- a/gulpfile.babel.js +++ b/gulpfile.babel.js @@ -10,6 +10,7 @@ const plugins = gulpLoadPlugins(); const paths = { js: ['./**/*.js', '!dist/**', '!node_modules/**', '!coverage/**'], + nonJs: ['./package.json', './.gitignore'], tests: './server/tests/*.js' }; @@ -23,7 +24,7 @@ const options = { } }; -// Clean up dist files +// Clean up dist and coverage directory gulp.task('clean', () => del(['dist/**', 'coverage/**', '!dist', '!coverage']) ); @@ -51,6 +52,13 @@ gulp.task('lint', () => .pipe(plugins.eslint.failAfterError()) ); +// Copy non-js files to dist +gulp.task('copy', () => + gulp.src(paths.nonJs) + .pipe(plugins.newer('dist')) + .pipe(gulp.dest('dist')) +); + // Compile ES6 to ES5 and copy to dist gulp.task('babel', () => gulp.src([...paths.js, '!gulpfile.babel.js'], { base: '.' }) @@ -71,12 +79,12 @@ gulp.task('babel', () => ); // Start server with restart on file changes -gulp.task('nodemon', ['lint', 'babel'], () => +gulp.task('nodemon', ['lint', 'copy', 'babel'], () => plugins.nodemon({ script: path.join('dist', 'index.js'), ext: 'js', ignore: ['node_modules/**/*.js', 'dist/**/*.js'], - tasks: ['lint', 'babel'] + tasks: ['lint', 'copy', 'babel'] }) ); @@ -132,20 +140,20 @@ gulp.task('test', ['pre-test', 'set-env'], () => { }); }); -// Run mocha with clean up, copy and babel compilation -// gulp mocha --env test +// clean dist, compile js files, copy non-js files and execute tests gulp.task('mocha', ['clean'], () => { runSequence( - 'babel', + ['copy', 'babel'], 'test' ); }); -gulp.task('serve', ['clean'], () => { - runSequence('nodemon'); -}); +// gulp serve for development +gulp.task('serve', ['clean'], () => runSequence('nodemon')); -// clean and compile files, the default task +// default task: clean dist, compile js files and copy non-js files. gulp.task('default', ['clean'], () => { - runSequence('babel'); + runSequence( + ['copy', 'babel'] + ); }); diff --git a/index.js b/index.js index 4ea17bf5..9547d5c0 100644 --- a/index.js +++ b/index.js @@ -16,7 +16,7 @@ const debug = require('debug')('express-mongoose-es6-rest-api:index'); // listen on port config.port app.listen(config.port, () => { - debug(`started server on port ${config.port} (${config.env})`); + debug(`server started on port ${config.port} (${config.env})`); }); export default app; diff --git a/package.json b/package.json index 41f1a22e..d3c73693 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "express-mongoose-es6-rest-api", - "version": "0.6.0", + "version": "0.7.0", "description": "A Boilerplate application for building REST APIs using express, mongoose in ES6 with code coverage", "author": "Kunal Kapadia ", "main": "index.js",