Skip to content
This repository was archived by the owner on Jul 31, 2020. It is now read-only.

Commit d9c6bd2

Browse files
committed
feat: add gulp tasks to bootstrap server
1 parent 88f4015 commit d9c6bd2

File tree

6 files changed

+123
-0
lines changed

6 files changed

+123
-0
lines changed

.babelrc

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"presets": [
3+
"es2015"
4+
]
5+
}

.env

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
PORT=5000

gulpfile.babel.js

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
'use strict';
2+
3+
import dotenv from 'dotenv';
4+
import gulp from 'gulp';
5+
import del from 'del';
6+
import gulpLoadPlugins from 'gulp-load-plugins';
7+
import browserSync from 'browser-sync';
8+
9+
const $ = gulpLoadPlugins();
10+
const SERVER = 'dist/server';
11+
browserSync.create();
12+
dotenv.config({silent: true});
13+
14+
/**
15+
* Task jshint
16+
* Use js lint
17+
*/
18+
gulp.task('jshint', ['jscs'], () => {
19+
return gulp.src([
20+
'server/**/*.js',
21+
'gulfile.js',
22+
])
23+
.pipe($.jshint('.jshintrc'))
24+
.pipe($.jshint.reporter('default'))
25+
.pipe($.jshint.reporter('fail'));
26+
});
27+
28+
/**
29+
* Task jscs
30+
* Use js cs lint
31+
*/
32+
gulp.task('jscs', () => {
33+
return gulp.src([
34+
'server/**/*.js',
35+
'gulfile.js',
36+
])
37+
.pipe($.jscs('.jscsrc'))
38+
.pipe($.jscs.reporter())
39+
.pipe($.jscs.reporter('fail'));
40+
});
41+
42+
/**
43+
* Task reload
44+
* reload the browser after executing default
45+
*/
46+
gulp.task('reload', ['default'], () => {
47+
browserSync.reload();
48+
});
49+
50+
/**
51+
* Task serve
52+
* launch an express server
53+
*/
54+
gulp.task('serve', () => {
55+
const server = $.liveServer.new('server/server.js');
56+
server.start();
57+
});
58+
59+
/**
60+
* Task clean
61+
* Remove dist directory
62+
*/
63+
gulp.task('clean', () => {
64+
return del([
65+
SERVER,
66+
]);
67+
});
68+
69+
/**
70+
* Task test
71+
* Build the project and test for it's consistency
72+
*/
73+
gulp.task('test', ['jscs']);

package.json

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
"description": "The nutritional fact database's website",
55
"main": "index.js",
66
"scripts": {
7+
"start": "gulp serve",
78
"test": "gulp test"
89
},
910
"repository": {
@@ -21,6 +22,21 @@
2122
},
2223
"homepage": "https://github.com/anthillsolutions/nutrient#readme",
2324
"dependencies": {
25+
"dotenv": "^4.0.0",
2426
"express": "^4.14.0"
27+
},
28+
"devDependencies": {
29+
"babel-core": "^6.22.1",
30+
"babel-preset-es2015": "^6.22.0",
31+
"bower": "^1.8.0",
32+
"browser-sync": "^2.18.6",
33+
"del": "^2.2.2",
34+
"gulp": "^3.9.1",
35+
"gulp-batch": "^1.0.5",
36+
"gulp-jscs": "^4.0.0",
37+
"gulp-jshint": "^2.0.4",
38+
"gulp-live-server": "0.0.30",
39+
"gulp-load-plugins": "^1.4.0",
40+
"jshint": "^2.9.4"
2541
}
2642
}

server/routes/index.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
'use strict';
2+
3+
var express = require('express');
4+
var router = express.Router();
5+
6+
/* GET home page. */
7+
router.get('/', function(req, res, next) {
8+
res.json({
9+
message: 'Welcome to Nutrient!'
10+
});
11+
});
12+
13+
module.exports = router;

server/server.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
'use strict';
2+
3+
var express = require('express');
4+
var dotenv = require('dotenv');
5+
dotenv.config({silent: true});
6+
7+
var app = express();
8+
var PORT = process.env.PORT || 3000;
9+
var index = require('./routes/index.js');
10+
11+
app.use(index);
12+
13+
app.listen(PORT, () => {
14+
console.log('app listening on port ' + PORT + '!');
15+
});

0 commit comments

Comments
 (0)