diff --git a/.babelrc b/.babelrc new file mode 100644 index 0000000..3c078e9 --- /dev/null +++ b/.babelrc @@ -0,0 +1,5 @@ +{ + "presets": [ + "es2015" + ] +} diff --git a/.env b/.env new file mode 100644 index 0000000..d8e22ad --- /dev/null +++ b/.env @@ -0,0 +1 @@ +PORT=5000 diff --git a/gulpfile.babel.js b/gulpfile.babel.js new file mode 100644 index 0000000..7cb6b75 --- /dev/null +++ b/gulpfile.babel.js @@ -0,0 +1,73 @@ +'use strict'; + +import dotenv from 'dotenv'; +import gulp from 'gulp'; +import del from 'del'; +import gulpLoadPlugins from 'gulp-load-plugins'; +import browserSync from 'browser-sync'; + +const $ = gulpLoadPlugins(); +const SERVER = 'dist/server'; +browserSync.create(); +dotenv.config({silent: true}); + +/** + * Task jshint + * Use js lint + */ +gulp.task('jshint', ['jscs'], () => { + return gulp.src([ + 'server/**/*.js', + 'gulfile.js', + ]) + .pipe($.jshint('.jshintrc')) + .pipe($.jshint.reporter('default')) + .pipe($.jshint.reporter('fail')); +}); + +/** + * Task jscs + * Use js cs lint + */ +gulp.task('jscs', () => { + return gulp.src([ + 'server/**/*.js', + 'gulfile.js', + ]) + .pipe($.jscs('.jscsrc')) + .pipe($.jscs.reporter()) + .pipe($.jscs.reporter('fail')); +}); + +/** + * Task reload + * reload the browser after executing default + */ +gulp.task('reload', ['default'], () => { + browserSync.reload(); +}); + +/** + * Task serve + * launch an express server + */ +gulp.task('serve', () => { + const server = $.liveServer.new('server/server.js'); + server.start(); +}); + +/** + * Task clean + * Remove dist directory + */ +gulp.task('clean', () => { + return del([ + SERVER, + ]); +}); + +/** + * Task test + * Build the project and test for it's consistency + */ +gulp.task('test', ['jscs']); diff --git a/package.json b/package.json index e36a35e..b6e7fa6 100644 --- a/package.json +++ b/package.json @@ -4,6 +4,7 @@ "description": "The nutritional fact database's website", "main": "index.js", "scripts": { + "start": "gulp serve", "test": "gulp test" }, "repository": { @@ -21,6 +22,21 @@ }, "homepage": "https://github.com/anthillsolutions/nutrient#readme", "dependencies": { + "dotenv": "^4.0.0", "express": "^4.14.0" + }, + "devDependencies": { + "babel-core": "^6.22.1", + "babel-preset-es2015": "^6.22.0", + "bower": "^1.8.0", + "browser-sync": "^2.18.6", + "del": "^2.2.2", + "gulp": "^3.9.1", + "gulp-batch": "^1.0.5", + "gulp-jscs": "^4.0.0", + "gulp-jshint": "^2.0.4", + "gulp-live-server": "0.0.30", + "gulp-load-plugins": "^1.4.0", + "jshint": "^2.9.4" } } diff --git a/server/routes/index.js b/server/routes/index.js new file mode 100644 index 0000000..88936cb --- /dev/null +++ b/server/routes/index.js @@ -0,0 +1,13 @@ +'use strict'; + +var express = require('express'); +var router = express.Router(); + +/* GET home page. */ +router.get('/', function(req, res, next) { + res.json({ + message: 'Welcome to Nutrient!' + }); +}); + +module.exports = router; diff --git a/server/server.js b/server/server.js new file mode 100644 index 0000000..746b12b --- /dev/null +++ b/server/server.js @@ -0,0 +1,15 @@ +'use strict'; + +var express = require('express'); +var dotenv = require('dotenv'); +dotenv.config({silent: true}); + +var app = express(); +var PORT = process.env.PORT || 3000; +var index = require('./routes/index.js'); + +app.use(index); + +app.listen(PORT, () => { + console.log('app listening on port ' + PORT + '!'); +});