-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
1d2e316
commit c014934
Showing
48 changed files
with
3,272 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
'use strict'; | ||
|
||
var gulp = require('gulp'), | ||
nodemon = require('gulp-nodemon'), | ||
watch = require('gulp-watch'), | ||
jshint = require('gulp-jshint'), | ||
livereload = require('gulp-livereload'), | ||
browserify = require('browserify'), | ||
source = require('vinyl-source-stream'), | ||
watchify = require('watchify'); | ||
|
||
var production = process.env.NODE_ENV === 'production'; | ||
|
||
function handleError(task) { | ||
return function(err) { | ||
console.log(err); | ||
}; | ||
} | ||
|
||
function scripts(watch) { | ||
var bundler, rebundle; | ||
bundler = browserify('./public/js/app.js', { | ||
basedir: __dirname, | ||
debug: !production, | ||
cache: {}, // required for watchify | ||
packageCache: {}, // required for watchify | ||
fullPaths: watch // required to be true only for watchify | ||
}); | ||
if(watch) { | ||
bundler = watchify(bundler); | ||
} | ||
|
||
rebundle = function() { | ||
var stream = bundler.bundle(); | ||
stream.on('error', handleError('Browserify')); | ||
stream = stream.pipe(source('bundle.js')); | ||
return stream.pipe(gulp.dest('./public/js')); | ||
}; | ||
|
||
bundler.on('update', rebundle); | ||
return rebundle(); | ||
} | ||
|
||
//register nodemon task | ||
gulp.task('nodemon', function () { | ||
nodemon({ script: './bin/www', env: { 'NODE_ENV': 'development' }}) | ||
.on('restart'); | ||
}); | ||
|
||
// Rerun the task when a file changes | ||
gulp.task('watch', function() { | ||
var server = livereload(); | ||
gulp.src(['*.js','routes/*.js', 'public/*.js'], { read: true }) | ||
.pipe(watch({ emit: 'all' })) | ||
.pipe(jshint()) | ||
.pipe(jshint.reporter('default')); | ||
|
||
gulp.watch(['*.js','routes/*.js', 'views/**/*.*', 'public/**/*.*']).on('change', function(file) { | ||
server.changed(file.path); | ||
}); | ||
}); | ||
|
||
//lint js files | ||
gulp.task('lint', function() { | ||
gulp.src(['*.js','routes/*.js', 'public/*.js']) | ||
.pipe(jshint()) | ||
.pipe(jshint.reporter('default')); | ||
}); | ||
|
||
gulp.task('scripts', function() { | ||
return scripts(false); | ||
}); | ||
|
||
gulp.task('watchScripts', function() { | ||
return scripts(true); | ||
}); | ||
|
||
// The default task (called when you run `gulp` from cli) | ||
gulp.task('default', ['lint','nodemon', 'watch', 'watchScripts']); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
'use strict'; | ||
|
||
var express = require('express'); | ||
var path = require('path'); | ||
var favicon = require('static-favicon'); | ||
var logger = require('morgan'); | ||
var cookieParser = require('cookie-parser'); | ||
var bodyParser = require('body-parser'); | ||
|
||
var routes = require('./routes/index'); | ||
var wikimaps = require('./routes/wikimaps'); | ||
|
||
var app = express(); | ||
|
||
// view engine setup | ||
app.set('views', path.join(__dirname, 'views')); | ||
app.engine('html', require('ejs').renderFile); | ||
app.set('view engine', 'html'); | ||
|
||
app.use(favicon()); | ||
app.use(logger('dev')); | ||
app.use(bodyParser.json()); | ||
app.use(bodyParser.urlencoded()); | ||
app.use(cookieParser()); | ||
|
||
app.use(require('stylus').middleware(path.join(__dirname, 'public'))); | ||
|
||
app.use(express.static(path.join(__dirname, 'public'))); | ||
|
||
app.use('/', routes); | ||
app.use('/wikimaps', wikimaps); | ||
|
||
/// catch 404 and forwarding to error handler | ||
app.use(function(req, res, next) { | ||
var err = new Error('Not Found'); | ||
err.status = 404; | ||
next(err); | ||
}); | ||
|
||
/// error handlers | ||
|
||
// development error handler | ||
// will print stacktrace | ||
if (app.get('env') === 'development') { | ||
app.use(function(err, req, res, next) { | ||
res.status(err.status || 500); | ||
res.render('error', { | ||
message: err.message, | ||
error: err | ||
}); | ||
next(); | ||
}); | ||
} | ||
|
||
// production error handler | ||
// no stacktraces leaked to user | ||
app.use(function(err, req, res, next) { | ||
res.status(err.status || 500); | ||
res.render('error', { | ||
message: err.message, | ||
error: {} | ||
}); | ||
next(); | ||
}); | ||
|
||
|
||
module.exports = app; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
#!/usr/bin/env node | ||
var debug = require('debug')('my-application'); | ||
var app = require('../app'); | ||
|
||
app.set('port', process.env.PORT || 3000); | ||
|
||
var server = app.listen(app.get('port'), function() { | ||
console.log('Express server listening on port ' + server.address().port); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
{ | ||
"name": "application-name", | ||
"version": "0.0.1", | ||
"private": true, | ||
"scripts": { | ||
"start": "node ./bin/www" | ||
}, | ||
"devDependencies": { | ||
"gulp": "latest", | ||
"bower": "latest", | ||
"gulp-nodemon": "latest", | ||
"gulp-watch": "~0.6.4", | ||
"gulp-jshint": "latest", | ||
"gulp-livereload": "^1.5.0", | ||
"browserify": "^6.3.2", | ||
"browserify-middleware": "^4.1.0", | ||
"gulp-browserify": "^0.5.0", | ||
"vinyl-source-stream": "^1.0.0" | ||
}, | ||
"dependencies": { | ||
"express": "~4.0.0", | ||
"static-favicon": "~1.0.0", | ||
"morgan": "~1.0.0", | ||
"cookie-parser": "~1.0.1", | ||
"body-parser": "~1.0.0", | ||
"debug": "~0.7.4", | ||
"ejs": "~0.8.5", | ||
"stylus": "0.42.3", | ||
"mongoose": "^3.8.19" | ||
} | ||
} |
Large diffs are not rendered by default.
Oops, something went wrong.
Oops, something went wrong.