Skip to content

Commit d68dd24

Browse files
committed
Added build system
1 parent ebcda08 commit d68dd24

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

60 files changed

+9939
-541
lines changed

.gitignore

+3-1
Original file line numberDiff line numberDiff line change
@@ -20,4 +20,6 @@ tmp/**/*
2020
.idea
2121
.idea/**/*
2222
*.iml
23-
*.log
23+
*.log
24+
25+
public/build/

.npmignore

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
node_modules
2+
npm-debug.log
3+
public/src/

bin/app.js

+19-14
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,12 @@ var config = require('./config.js'),
66
middleware = require('./middleware.js'),
77
log = require('./log.js'),
88
express = require('express'),
9-
app = express();
9+
app = express(),
10+
externals = {
11+
js : (config.get('env') === 'development') ? config.get('jsFiles') : config.get('jsMinFile'),
12+
css : (config.get('env') === 'development') ? config.get('cssFiles') : config.get('cssMinFile')
13+
};
14+
1015

1116

1217
// Configure app
@@ -34,43 +39,43 @@ app.set('view engine', 'ejs');
3439
// Set http routes
3540

3641
app.get('/', function(req, res){
37-
res.render('index', { pageTitle: 'Web Rebels ☠ Oslo ☠ 2014' });
42+
res.render('index', {externals: externals, pageTitle: 'Web Rebels ☠ Oslo ☠ 2014' });
3843
});
3944
app.get('/index', function(req, res){
40-
res.render('index', { pageTitle: 'Web Rebels ☠ Oslo ☠ 2014' });
45+
res.render('index', {externals: externals, pageTitle: 'Web Rebels ☠ Oslo ☠ 2014' });
4146
});
4247
app.get('/sponsors', function(req,res){
43-
res.render('sponsors', {pageTitle: 'Our sponsors without whom none of this would be possible ☠ Web Rebels ☠ Oslo 2014'});
48+
res.render('sponsors', {externals: externals, pageTitle: 'Our sponsors without whom none of this would be possible ☠ Web Rebels ☠ Oslo 2014'});
4449
});
4550
app.get('/sponsoroptions', function(req,res){
46-
res.render('sponsoroptions', {pageTitle: 'Sponsoring options for the Web Rebels ☠ Oslo 2014'});
51+
res.render('sponsoroptions', {externals: externals, pageTitle: 'Sponsoring options for the Web Rebels ☠ Oslo 2014'});
4752
});
4853
app.get('/about', function(req,res){
49-
res.render('about', {pageTitle: '☠ About the Web Rebels ☠'});
54+
res.render('about', {externals: externals, pageTitle: '☠ About the Web Rebels ☠'});
5055
});
5156
app.get('/tickets', function(req,res){
52-
res.render('tickets', {pageTitle: 'Tickets for the Web Rebels ☠ Oslo 2014'});
57+
res.render('tickets', {externals: externals, pageTitle: 'Tickets for the Web Rebels ☠ Oslo 2014'});
5358
});
5459
app.get('/ticketConfirmation', function(req,res){
55-
res.render('ticketConfirmation', {pageTitle: 'Thank you for registering with the Web Rebels ☠ Oslo 2014'});
60+
res.render('ticketConfirmation', {externals: externals, pageTitle: 'Thank you for registering with the Web Rebels ☠ Oslo 2014'});
5661
});
5762
app.get('/location', function(req,res){
58-
res.render('location', {pageTitle: 'Location of the Web Rebels ☠ Oslo 2014'});
63+
res.render('location', {externals: externals, pageTitle: 'Location of the Web Rebels ☠ Oslo 2014'});
5964
});
6065
app.get('/oslo', function(req,res){
61-
res.render('oslo', {pageTitle: 'Oslo survival guide for Web Rebels ☠ Oslo 2014'});
66+
res.render('oslo', {externals: externals, pageTitle: 'Oslo survival guide for Web Rebels ☠ Oslo 2014'});
6267
});
6368
app.get('/openmic', function(req,res){
64-
res.render('openmic', {pageTitle: 'Open Mic Night - Web Rebels ☠ Oslo 2014'});
69+
res.render('openmic', {externals: externals, pageTitle: 'Open Mic Night - Web Rebels ☠ Oslo 2014'});
6570
});
6671
app.get('/schedule', function(req,res){
67-
res.render('schedule', {pageTitle: 'Schedule for Web Rebels ☠ Oslo 2014'});
72+
res.render('schedule', {externals: externals, pageTitle: 'Schedule for Web Rebels ☠ Oslo 2014'});
6873
});
6974
app.get('/speakers', function(req,res){
70-
res.render('speakers', {pageTitle: 'Speakers - Web Rebels ☠ Oslo 2014'});
75+
res.render('speakers', {externals: externals, pageTitle: 'Speakers - Web Rebels ☠ Oslo 2014'});
7176
});
7277
app.get('/roadbook', function(req,res){
73-
res.render('roadbook', {pageTitle: 'Speakers Roadbook - Web Rebels ☠ Oslo 2014'});
78+
res.render('roadbook', {externals: externals, pageTitle: 'Speakers Roadbook - Web Rebels ☠ Oslo 2014'});
7479
});
7580

7681

bin/config.js

+56-4
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@ env: {
1414
doc: "Applicaton environments",
1515
format : ["development", "production"],
1616
default : "development",
17-
env : "NODE_ENV"
17+
env : "NODE_ENV",
18+
arg : "env"
1819
},
1920

2021
version: {
@@ -34,7 +35,7 @@ env: {
3435
docRoot: {
3536
doc : "Document root for static files to be served by the http server",
3637
format : "*",
37-
default : "./public",
38+
default : "./public/src",
3839
env : "NODE_HTTP_DOC_ROOT"
3940
},
4041

@@ -56,14 +57,65 @@ env: {
5657
doc : "Which level the console transport log should log at",
5758
format : "*",
5859
default : "info",
59-
env : "NODE_LOG_CONSOLE_LEVEL"
60+
env : "NODE_LOG_CONSOLE_LEVEL",
61+
arg : "log-console-level"
6062
},
6163

6264
logConsoleSilent: {
6365
doc : "If the console transport log should be silent or not",
6466
format : "*",
6567
default : false,
66-
env : "NODE_LOG_CONSOLE_SILENT"
68+
env : "NODE_LOG_CONSOLE_SILENT",
69+
arg : "log-console-silent"
70+
},
71+
72+
jsFiles: {
73+
doc : "Non minified JavaScript files - Use relative path to 'docRoot'",
74+
format : Array,
75+
default : [
76+
'/js/lib/leaflet-0.7.1/leaflet-src.js',
77+
'/js/lib/derp-modules.js',
78+
'/js/map.js'
79+
],
80+
env : "NODE_JS_FILES"
81+
},
82+
83+
cssFiles: {
84+
doc : "Non minified CSS files - Use relative path to 'docRoot'",
85+
format : Array,
86+
default : [
87+
'/css/style.css',
88+
'/js/lib/leaflet-0.7.1/leaflet.css'
89+
],
90+
env : "NODE_CSS_FILES"
91+
},
92+
93+
gfxFiles: {
94+
doc : "Source graphic files - Use relative path to 'docRoot'",
95+
format : Array,
96+
default : ['/img/**/*'],
97+
env : "NODE_GFX_FILES"
98+
},
99+
100+
fontFiles: {
101+
doc : "Source font files - Use relative path to 'docRoot'",
102+
format : Array,
103+
default : ['/webfonts/**/*'],
104+
env : "NODE_FONT_FILES"
105+
},
106+
107+
jsMinFile: {
108+
doc : "Minified JavaScript file",
109+
format : Array,
110+
default : ['/js/scripts.min.js'],
111+
env : "NODE_JS_MIN_FILE"
112+
},
113+
114+
cssMinFile: {
115+
doc : "Minified CSS file",
116+
format : Array,
117+
default : ['/css/styles.min.css'],
118+
env : "NODE_CSS_MIN_FILE"
67119
}
68120

69121
});

config/production.json

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
{
2+
"docRoot" : "./public/build",
23
"logConsoleLevel" : "error"
34
}

gulpfile.js

+62
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
/* jshint node: true, strict: true */
2+
3+
"use strict";
4+
5+
6+
var gulp = require('gulp'),
7+
concat = require('gulp-concat'),
8+
uglify = require('gulp-uglify'),
9+
minifyCSS = require('gulp-minify-css'),
10+
config = require('./bin/config.js');
11+
12+
13+
14+
function prependDocRoot(path) {
15+
return config.get('docRoot') + path;
16+
}
17+
18+
19+
20+
// Minify JS
21+
22+
gulp.task('js', function() {
23+
return gulp.src(config.get('jsFiles').map(prependDocRoot))
24+
.pipe(uglify({outSourceMap: false}))
25+
.pipe(concat(config.get('jsMinFile')[0]))
26+
.pipe(gulp.dest('public/build'));
27+
});
28+
29+
30+
31+
// Minify CSS
32+
33+
gulp.task('css', function() {
34+
return gulp.src(config.get('cssFiles').map(prependDocRoot))
35+
.pipe(minifyCSS({removeEmpty : true}))
36+
.pipe(concat(config.get('cssMinFile')[0]))
37+
.pipe(gulp.dest('public/build'));
38+
});
39+
40+
41+
42+
// Copy gfx
43+
44+
gulp.task('gfx', function() {
45+
return gulp.src(config.get('gfxFiles').map(prependDocRoot))
46+
.pipe(gulp.dest('public/build/img'));
47+
});
48+
49+
50+
51+
// Copy fonts
52+
53+
gulp.task('fonts', function() {
54+
return gulp.src(config.get('fontFiles').map(prependDocRoot))
55+
.pipe(gulp.dest('public/build/webfonts'));
56+
});
57+
58+
59+
60+
// The default task
61+
62+
gulp.task('default', ['js', 'css', 'gfx', 'fonts']);

package.json

+10-4
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,13 @@
1616
"javascript",
1717
"web"
1818
],
19-
"homepage": "http://webreb2014.jit.su/",
19+
"homepage": "https://www.webrebels.org/",
2020
"scripts": {
21-
"pretest": "jshint ./bin/*.js ./test/*.js",
21+
"pretest": "jshint ./bin/*.js ./gulpfile.js ./public/src/js/*.js",
2222
"test": "mocha ./test/*.js --reporter spec",
23-
"start": "node ./bin/server.js"
23+
"start": "node ./bin/server.js",
24+
"minify": "gulp",
25+
"prepublish": "gulp"
2426
},
2527
"contributors": [
2628
{
@@ -51,7 +53,11 @@
5153
"devDependencies": {
5254
"jshint": "latest",
5355
"mocha": "latest",
54-
"chai": "latest"
56+
"chai": "latest",
57+
"gulp": "latest",
58+
"gulp-concat": "latest",
59+
"gulp-uglify": "latest",
60+
"gulp-minify-css" : "latest"
5561
},
5662
"dependencies": {
5763
"winston": "0.7.x",

public/build/.placeholder

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Nothing here...

public/css/style.min.css

-6
This file was deleted.

public/js/map.js

-27
This file was deleted.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

public/src/js/lib/derp-modules.js

+78
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
// Source: https://gist.github.com/3861744
2+
// Added to project at: 2013.01.08
3+
//
4+
// Simple, tiny, dumb module definitions for Browser JavaScript.
5+
//
6+
// What it does:
7+
//
8+
// * Tiny enough to include anywhere. Intended as a shim for delivering
9+
// browser builds of your library to folks who don't want to use script loaders.
10+
// * Exports modules to `__modules__`, a namespace on the global object.
11+
// This is an improvement over typical browser code, which pollutes the
12+
// global object.
13+
// * Prettier and more robust than the
14+
// [IIFE module pattern](http://addyosmani.com/resources/essentialjsdesignpatterns/book/#revealingmodulepatternjavascript),
15+
// and if you have multiple modules, it's really no bigger.
16+
// * It's a compatible sub-set of AMD, so if you switch to a script loader,
17+
// it will "just work".
18+
// * Lets you know if your dependencies are awry.
19+
// * Passes you a syncronous require, making this an option for wrapping
20+
// Node libraries that don't require server features
21+
// (e.g. wrap it with a Makefile or somesuch).
22+
// * Helpful for development. Syncronous `require` means you can easily test
23+
// code live in REPLs like the Console or Scratchpad:
24+
//
25+
// >> require('foo').bar()
26+
// >> 3
27+
//
28+
// What it doesn't:
29+
//
30+
// * Does not handle script loading. You order your script tags yourself.
31+
// BUT, it does throw helpful exceptions, letting you know if you've
32+
// loaded your scripts out of order.
33+
// * Does not do path mapping. Module IDs are absolute.
34+
// * No AMD plugin/loader support, but could support inlined loader plugin
35+
// resources like 'text!...' ones. A reasonable tradeoff for size.
36+
// * Does not support the second AMD form `define(['a', 'b'], function (a, b) {})`.
37+
// YAGNI.
38+
//
39+
// Motivation: make `define`/`require`/`exports` wrappers a practical module
40+
// format for distributing libraries to folks, whether or not they use an
41+
// AMD script loader.
42+
43+
// Create a hash to store our modules.
44+
var modules = window.__modules__ = {};
45+
46+
// Require a module at an id. Returns the module's `exports` object.
47+
// `require` looks for modules on `window` and throws an exception when it
48+
// doesn't find them.
49+
function require(id) {
50+
// Get the module's exports.
51+
var exports = modules[id];
52+
// If there is no module yet, throw an exception, letting us know we've
53+
// loaded our scripts out of order.
54+
if(!exports) throw new Error(id + ' module not yet defined');
55+
return exports;
56+
}
57+
58+
// Create an AMD-style define function, for defining new modules.
59+
// This function takes an ID and a callback that exports your module.
60+
// `exports` are added under `path` to `window`.
61+
//
62+
// * The path can be any valid key. Usually the name of your module. The key
63+
// will be assigned to the global object, so be sure it's unique.
64+
// * Callback is where you construct your module and export values.
65+
// It gets a "require" function and an "exports" object.
66+
//
67+
// This is basically a subset of AMD's define. Modules using this pattern
68+
// should be compatible with AMD loaders, and Modules authored for AMD
69+
// should work if they have a path key.
70+
function define(id, callback) {
71+
// Throw an exception if the module already exists.
72+
if(modules[id]) throw new Error(id + ' module or property already exists');
73+
var exports = {};
74+
// Assign module to to namespace. If `callback` returns a value, use that
75+
// as the module value. Otherwise, use `exports`. Allowing return values
76+
// makes define compatible with a greater subset of AMD code.
77+
return modules[id] = callback(require, exports) || exports;
78+
}

0 commit comments

Comments
 (0)