Skip to content

Commit b18e831

Browse files
committed
Add gulp copy - copy non-js files to dist
1 parent caff483 commit b18e831

File tree

4 files changed

+25
-15
lines changed

4 files changed

+25
-15
lines changed

README.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ This is a boilerplate application for building REST APIs in Node.js using ES6 an
2222
| 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. |
2323
| 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. |
2424
| 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). |
25-
| 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.|
25+
| 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. |
2626

2727
- CORS support via [cors](https://github.com/troygoode/node-cors)
2828
- 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:
6666
```sh
6767
# Wipe out dist and coverage directory
6868
gulp clean
69+
6970
# Lint code with ESLint
7071
gulp lint
71-
# Default task: Wipes out dist and coverage direcotory. Compiles using babel.
72+
73+
# Default task: Wipes out dist and coverage directory. Compiles using babel.
7274
gulp
7375
```
7476

gulpfile.babel.js

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ const plugins = gulpLoadPlugins();
1010

1111
const paths = {
1212
js: ['./**/*.js', '!dist/**', '!node_modules/**', '!coverage/**'],
13+
nonJs: ['./package.json', './.gitignore'],
1314
tests: './server/tests/*.js'
1415
};
1516

@@ -23,7 +24,7 @@ const options = {
2324
}
2425
};
2526

26-
// Clean up dist files
27+
// Clean up dist and coverage directory
2728
gulp.task('clean', () =>
2829
del(['dist/**', 'coverage/**', '!dist', '!coverage'])
2930
);
@@ -51,6 +52,13 @@ gulp.task('lint', () =>
5152
.pipe(plugins.eslint.failAfterError())
5253
);
5354

55+
// Copy non-js files to dist
56+
gulp.task('copy', () =>
57+
gulp.src(paths.nonJs)
58+
.pipe(plugins.newer('dist'))
59+
.pipe(gulp.dest('dist'))
60+
);
61+
5462
// Compile ES6 to ES5 and copy to dist
5563
gulp.task('babel', () =>
5664
gulp.src([...paths.js, '!gulpfile.babel.js'], { base: '.' })
@@ -71,12 +79,12 @@ gulp.task('babel', () =>
7179
);
7280

7381
// Start server with restart on file changes
74-
gulp.task('nodemon', ['lint', 'babel'], () =>
82+
gulp.task('nodemon', ['lint', 'copy', 'babel'], () =>
7583
plugins.nodemon({
7684
script: path.join('dist', 'index.js'),
7785
ext: 'js',
7886
ignore: ['node_modules/**/*.js', 'dist/**/*.js'],
79-
tasks: ['lint', 'babel']
87+
tasks: ['lint', 'copy', 'babel']
8088
})
8189
);
8290

@@ -132,20 +140,20 @@ gulp.task('test', ['pre-test', 'set-env'], () => {
132140
});
133141
});
134142

135-
// Run mocha with clean up, copy and babel compilation
136-
// gulp mocha --env test
143+
// clean dist, compile js files, copy non-js files and execute tests
137144
gulp.task('mocha', ['clean'], () => {
138145
runSequence(
139-
'babel',
146+
['copy', 'babel'],
140147
'test'
141148
);
142149
});
143150

144-
gulp.task('serve', ['clean'], () => {
145-
runSequence('nodemon');
146-
});
151+
// gulp serve for development
152+
gulp.task('serve', ['clean'], () => runSequence('nodemon'));
147153

148-
// clean and compile files, the default task
154+
// default task: clean dist, compile js files and copy non-js files.
149155
gulp.task('default', ['clean'], () => {
150-
runSequence('babel');
156+
runSequence(
157+
['copy', 'babel']
158+
);
151159
});

index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ const debug = require('debug')('express-mongoose-es6-rest-api:index');
1616

1717
// listen on port config.port
1818
app.listen(config.port, () => {
19-
debug(`started server on port ${config.port} (${config.env})`);
19+
debug(`server started on port ${config.port} (${config.env})`);
2020
});
2121

2222
export default app;

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "express-mongoose-es6-rest-api",
3-
"version": "0.6.0",
3+
"version": "0.7.0",
44
"description": "A Boilerplate application for building REST APIs using express, mongoose in ES6 with code coverage",
55
"author": "Kunal Kapadia <[email protected]>",
66
"main": "index.js",

0 commit comments

Comments
 (0)