Skip to content

Commit

Permalink
Add gulp copy - copy non-js files to dist
Browse files Browse the repository at this point in the history
  • Loading branch information
kunalkapadia committed Feb 4, 2016
1 parent caff483 commit b18e831
Showing 4 changed files with 25 additions and 15 deletions.
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -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
```

30 changes: 19 additions & 11 deletions gulpfile.babel.js
Original file line number Diff line number Diff line change
@@ -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']
);
});
2 changes: 1 addition & 1 deletion index.js
Original file line number Diff line number Diff line change
@@ -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;
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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 <[email protected]>",
"main": "index.js",

0 comments on commit b18e831

Please sign in to comment.