Skip to content

Commit

Permalink
Reorganize directories a bit.
Browse files Browse the repository at this point in the history
This sets up that the directory for the server stuff will be the server
directory.

Client stuff will live in the `dist/` directory.

This also fixes the util `renderPage` helper to automatically look in
the correct directory.
  • Loading branch information
crertel committed Jun 15, 2016
1 parent 5fe29df commit c6b9d84
Show file tree
Hide file tree
Showing 9 changed files with 34 additions and 78 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -38,3 +38,6 @@ node_modules
# ignore sublime text droppings
*.sublime-project
*.sublime-workspace

# ignore generated/build articfacts
dist
15 changes: 5 additions & 10 deletions gulpfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ var gulp = require('gulp'),
gulp.task('build:styles', function() {
return gulp.src('styles/**/*.css')
.pipe(concat('main.css'))
.pipe(gulp.dest('static/css'))
.pipe(gulp.dest('dist/css'))
.pipe(rename({suffix: '.min'}))
.pipe(gulp.dest('static/css'))
.pipe(gulp.dest('dist/css'))
.pipe(notify({ message: 'Built styles.'}));
});

Expand All @@ -25,9 +25,9 @@ gulp.task('lint:client', function() {
gulp.task('build:client', function() {
return gulp.src('client/**/*.js')
.pipe(concat('main-client.js'))
.pipe(gulp.dest('static/js'))
.pipe(gulp.dest('dist/js'))
.pipe(rename({suffix: '.min'}))
.pipe(gulp.dest('static/js'))
.pipe(gulp.dest('dist/js'))
.pipe(notify({ message: 'Built client scripts.' }));
});

Expand All @@ -39,12 +39,7 @@ gulp.task('lint:server', function() {
});

gulp.task('build:server', function() {
return gulp.src('server/**/*.js')
.pipe(concat('main-server.js'))
.pipe(gulp.dest('static/js'))
.pipe(rename({suffix: '.min'}))
.pipe(gulp.dest('static/js'))
.pipe(notify({ message: 'Built server scripts.' }));
return notify({ message: 'Built server scripts.' });
});

gulp.task('clean', function(cb) {
Expand Down
6 changes: 3 additions & 3 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ function URFP( x ) { /* jshint expr:true */ x; }
var express = require('express');
var app = express();

var gameRouter = require('./server/gameController.js');
var resultRouter = require('./server/resultController.js');
var appRouter = require('./server/appController.js');
var gameRouter = require('./gameController.js');
var resultRouter = require('./resultController.js');
var appRouter = require('./appController.js');

app.use('/results', resultRouter)
app.use('/games', gameRouter);
Expand Down
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"lint": "gulp lint",
"build": "gulp default",
"clean": "gulp clean",
"start": "nodejs src/server/server.js",
"start": "node server/server.js",
"build:server": "gulp scripts-server",
"build:client": "gulp scripts-client"
},
Expand All @@ -25,7 +25,8 @@
"dependencies": {
"bluebird": "^3.4.0",
"ejs": "^2.4.2",
"express": "^4.13.3"
"express": "^4.13.3",
"pg-promise": "^4.6.2"
},
"devDependencies": {
"del": "^2.2.0",
Expand Down
4 changes: 2 additions & 2 deletions server/appController.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ var router = express.Router();
var util = require('./util.js');

router.get('/', function _renderGamesIndex( req, res) {
URFP(req);
util.renderPage('./server/views/index.html.ejs')
URFP(req);
util.renderPage('index.html.ejs')
.then( function (page) {
res.status(200).send(page);
})
Expand Down
14 changes: 14 additions & 0 deletions server/server.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
'use strict';

var express = require('express');
var app = express();

var gameRouter = require('./gameController.js');
var resultRouter = require('./resultController.js');
var appRouter = require('./appController.js');

app.use('/results', resultRouter);
app.use('/games', gameRouter);
app.get('/', appRouter);

app.listen(3000);
5 changes: 4 additions & 1 deletion server/util.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
'use strict';
var ejs = require('ejs');
var path = require('path');
var Promise = require('bluebird');

var promisedRenderPage = Promise.promisify( ejs.renderFile );

function renderPage( name, data ){
return promisedRenderPage( name, data, { strict: true, cache: true });
return promisedRenderPage( path.join(__dirname, 'views', name),
data,
{ strict: true, cache: true });
}

module.exports = {
Expand Down
30 changes: 0 additions & 30 deletions static/js/main-server.js

This file was deleted.

30 changes: 0 additions & 30 deletions static/js/main-server.min.js

This file was deleted.

0 comments on commit c6b9d84

Please sign in to comment.