diff --git a/Gruntfile.js b/Gruntfile.js
index 9fc012ec1d..c1bf9a461a 100644
--- a/Gruntfile.js
+++ b/Gruntfile.js
@@ -1,4 +1,5 @@
/*global module:false*/
+var _ = require('lodash');
module.exports = function(grunt) {
// Project configuration.
@@ -19,82 +20,6 @@ module.exports = function(grunt) {
build: ['build']
},
- uglify: {
- buildApp: {
- files: {
- 'build/app.js': [
- 'public/bower_components/jquery/jquery.min.js',
- 'public/bower_components/jquery.cookie/jquery.cookie.js',
- 'public/bower_components/bootstrap-growl/jquery.bootstrap-growl.min.js',
- 'public/bower_components/bootstrap-tour/build/js/bootstrap-tour.min.js',
- 'public/bower_components/angular/angular.min.js',
- 'public/bower_components/angular-sanitize/angular-sanitize.min.js',
- 'public/bower_components/marked/lib/marked.js',
- 'public/bower_components/angular-ui-router/release/angular-ui-router.js',
- 'public/bower_components/angular-resource/angular-resource.min.js',
- 'public/bower_components/angular-ui/build/angular-ui.min.js',
- 'public/bower_components/angular-ui-utils/modules/keypress/keypress.js',
- 'public/bower_components/angular-loading-bar/build/loading-bar.js',
- // we'll remove this once angular-bootstrap is fixed
- 'public/bower_components/bootstrap/docs/assets/js/bootstrap.min.js',
- 'public/bower_components/angular-bootstrap/ui-bootstrap.min.js',
- 'public/bower_components/angular-bootstrap/ui-bootstrap-tpls.min.js',
- // Sortable
- 'public/bower_components/jquery-ui/ui/minified/jquery.ui.core.min.js',
- 'public/bower_components/jquery-ui/ui/minified/jquery.ui.widget.min.js',
- 'public/bower_components/jquery-ui/ui/minified/jquery.ui.mouse.min.js',
- 'public/bower_components/jquery-ui/ui/minified/jquery.ui.sortable.min.js',
- // habitrpg-shared
- 'public/bower_components/habitrpg-shared/dist/habitrpg-shared.js',
- // app
- 'public/js/app.js',
- 'public/js/services/authServices.js',
- 'public/js/services/notificationServices.js',
- 'public/js/services/sharedServices.js',
- 'public/js/services/userServices.js',
- 'public/js/services/groupServices.js',
- 'public/js/services/memberServices.js',
- 'public/js/services/guideServices.js',
- 'public/js/services/challengeServices.js',
-
- 'public/js/filters/filters.js',
-
- 'public/js/directives/directives.js',
-
- 'public/js/controllers/authCtrl.js',
- 'public/js/controllers/notificationCtrl.js',
- 'public/js/controllers/rootCtrl.js',
- 'public/js/controllers/settingsCtrl.js',
- 'public/js/controllers/headerCtrl.js',
- 'public/js/controllers/tasksCtrl.js',
- 'public/js/controllers/filtersCtrl.js',
- 'public/js/controllers/userCtrl.js',
- 'public/js/controllers/groupsCtrl.js',
- 'public/js/controllers/petsCtrl.js',
- 'public/js/controllers/inventoryCtrl.js',
- 'public/js/controllers/marketCtrl.js',
- 'public/js/controllers/footerCtrl.js',
- 'public/js/controllers/challengesCtrl.js'
- ]
- }
- },
- buildStatic: {
- files: {
- 'build/static.js': [
- 'public/bower_components/jquery/jquery.min.js',
- 'public/bower_components/habitrpg-shared/dist/habitrpg-shared.js',
- 'public/bower_components/angular/angular.min.js',
- 'public/bower_components/angular-resource/angular-resource.min.js',
- 'public/bower_components/bootstrap/docs/assets/js/bootstrap.min.js',
- 'public/bower_components/angular-loading-bar/build/loading-bar.js',
- 'public/js/static.js',
- 'public/js/services/userServices.js',
- 'public/js/controllers/authCtrl.js'
- ]
- }
- }
- },
-
stylus: {
build: {
options: {
@@ -109,19 +34,6 @@ module.exports = function(grunt) {
}
},
- cssmin: {
- build: {
- files: {
- 'build/app.css': ['build/app.css'],
- 'build/static.css': ['build/static.css'],
- 'build/bower_components/habitrpg-shared/dist/spritesheets.css': ['public/bower_components/habitrpg-shared/dist/spritesheets.css'],
- 'build/bower_components/bootstrap/docs/assets/css/bootstrap.css': ['public/bower_components/bootstrap/docs/assets/css/bootstrap.css'],
- 'build/bower_components/bootstrap/docs/assets/css/bootstrap-responsive.css': ['public/bower_components/bootstrap/docs/assets/css/bootstrap-responsive.css'],
- 'build/bower_components/bootstrap/docs/assets/css/docs.css': ['public/bower_components/bootstrap/docs/assets/css/docs.css']
- }
- }
- },
-
copy: {
build: {
files: [{expand: true, cwd: 'public/', src: 'favicon.ico', dest: 'build/'}]
@@ -168,9 +80,31 @@ module.exports = function(grunt) {
});
+ //Load build files from public/manifest.json
+ grunt.registerTask('loadManifestFiles', 'Load all build files from public/manifest.json', function(){
+ var files = grunt.file.readJSON('./public/manifest.json');
+ var uglify = {};
+ var cssmin = {};
+ _.each(files, function(val, key){
+ var js = uglify['build/' + key + '.js'] = [];
+ _.each(files[key]['js'], function(val){
+ js.push('public/' + val);
+ });
+ _.each(files[key]['css'], function(val){
+ if(val == 'app.css' || val == 'static.css'){
+ cssmin['build/' + val] = ['build/' + val]
+ }else{
+ cssmin['build/' + val] = ['public/' + val]
+ }
+ });
+ });
+ grunt.config.set('uglify.build.files', uglify);
+ grunt.config.set('cssmin.build.files', cssmin);
+ });
+
// Register tasks.
- grunt.registerTask('build:prod', ['clean:build', 'uglify', 'stylus', 'cssmin', 'copy:build', 'hashres']);
- grunt.registerTask('build:dev', ['clean:build', 'stylus', 'cssmin', 'copy:build', 'hashres']);
+ grunt.registerTask('build:prod', ['loadManifestFiles', 'clean:build', 'uglify', 'stylus', 'cssmin', 'copy:build', 'hashres']);
+ grunt.registerTask('build:dev', ['loadManifestFiles', 'clean:build', 'stylus', 'cssmin', 'copy:build']);
grunt.registerTask('run:dev', [ 'build:dev', 'concurrent' ]);
diff --git a/public/manifest.json b/public/manifest.json
new file mode 100644
index 0000000000..f0c0806330
--- /dev/null
+++ b/public/manifest.json
@@ -0,0 +1,83 @@
+{
+ "app": {
+ "js": [
+ "bower_components/jquery/jquery.js",
+ "bower_components/bootstrap-growl/jquery.bootstrap-growl.js",
+ "bower_components/bootstrap-tour/build/js/bootstrap-tour.js",
+ "bower_components/angular/angular.js",
+ "bower_components/angular-sanitize/angular-sanitize.js",
+ "bower_components/marked/lib/marked.js",
+ "bower_components/angular-ui-router/release/angular-ui-router.js",
+ "bower_components/angular-resource/angular-resource.min.js",
+ "bower_components/angular-ui/build/angular-ui.js",
+ "bower_components/angular-ui-utils/modules/keypress/keypress.js",
+ "bower_components/angular-loading-bar/build/loading-bar.js",
+
+ "bower_components/bootstrap/docs/assets/js/bootstrap.js",
+ "bower_components/angular-bootstrap/ui-bootstrap.js",
+ "bower_components/angular-bootstrap/ui-bootstrap-tpls.js",
+
+ "bower_components/jquery-ui/ui/minified/jquery.ui.core.min.js",
+ "bower_components/jquery-ui/ui/minified/jquery.ui.widget.min.js",
+ "bower_components/jquery-ui/ui/minified/jquery.ui.mouse.min.js",
+ "bower_components/jquery-ui/ui/minified/jquery.ui.sortable.min.js",
+
+ "bower_components/habitrpg-shared/dist/habitrpg-shared.js",
+
+ "js/app.js",
+ "js/services/authServices.js",
+ "js/services/notificationServices.js",
+ "js/services/sharedServices.js",
+ "js/services/userServices.js",
+ "js/services/groupServices.js",
+ "js/services/memberServices.js",
+ "js/services/guideServices.js",
+ "js/services/challengeServices.js",
+
+ "js/filters/filters.js",
+
+ "js/directives/directives.js",
+
+ "js/controllers/authCtrl.js",
+ "js/controllers/notificationCtrl.js",
+ "js/controllers/rootCtrl.js",
+ "js/controllers/settingsCtrl.js",
+ "js/controllers/headerCtrl.js",
+ "js/controllers/tasksCtrl.js",
+ "js/controllers/filtersCtrl.js",
+ "js/controllers/userCtrl.js",
+ "js/controllers/groupsCtrl.js",
+ "js/controllers/petsCtrl.js",
+ "js/controllers/inventoryCtrl.js",
+ "js/controllers/marketCtrl.js",
+ "js/controllers/footerCtrl.js",
+ "js/controllers/challengesCtrl.js"
+ ],
+ "css": [
+ "bower_components/bootstrap/docs/assets/css/bootstrap.css",
+ "app.css",
+ "bower_components/habitrpg-shared/dist/spritesheets.css"
+ ]
+ },
+ "static": {
+ "js": [
+ "bower_components/jquery/jquery.js",
+ "bower_components/habitrpg-shared/dist/habitrpg-shared.js",
+ "bower_components/angular/angular.js",
+
+ "bower_components/bootstrap/docs/assets/js/bootstrap.js",
+
+ "bower_components/angular-loading-bar/build/loading-bar.js",
+ "js/static.js",
+ "js/services/userServices.js",
+ "js/controllers/authCtrl.js"
+ ],
+ "css": [
+ "bower_components/bootstrap/docs/assets/css/bootstrap.css",
+ "bower_components/bootstrap/docs/assets/css/bootstrap-responsive.css",
+ "bower_components/bootstrap/docs/assets/css/docs.css",
+
+ "static.css"
+ ]
+ }
+}
\ No newline at end of file
diff --git a/src/middleware.js b/src/middleware.js
index 2b224ab85f..3bb94e08d8 100644
--- a/src/middleware.js
+++ b/src/middleware.js
@@ -54,11 +54,37 @@ var walk = function(folder){
walk(path.join(__dirname, "/../build"));
var getBuildUrl = function(url){
- if(buildFiles[url]) return buildFiles[url];
+ console.log(url, buildFiles[url])
+ if(buildFiles[url]) return '/' + buildFiles[url];
- return url;
+ return '/' + url;
}
+var manifestFiles = require("../public/manifest.json");
+
+var getManifestFiles = function(page){
+ var files = manifestFiles[page];
+
+ if(!files) throw new Error("Page not found!");
+
+ var css = '';
+
+ _.each(files.css, function(file){
+ css += '';
+ });
+
+ if(nconf.get('NODE_ENV') === 'production'){
+ return css + '';
+ }else{
+ var results = css;
+ _.each(files.js, function(file){
+ results += '';
+ });
+ return results;
+ }
+
+}
+
module.exports.locals = function(req, res, next) {
res.locals.habitrpg = res.locals.habitrpg || {}
_.defaults(res.locals.habitrpg, {
@@ -67,6 +93,7 @@ module.exports.locals = function(req, res, next) {
PAYPAL_MERCHANT: nconf.get('PAYPAL_MERCHANT'),
IS_MOBILE: /Android|webOS|iPhone|iPad|iPod|BlackBerry/i.test(req.header('User-Agent')),
STRIPE_PUB_KEY: nconf.get('STRIPE_PUB_KEY'),
+ getManifestFiles: getManifestFiles,
getBuildUrl: getBuildUrl
});
next()
diff --git a/src/server.js b/src/server.js
index 3e9c36ebc1..6b9e4e11d6 100644
--- a/src/server.js
+++ b/src/server.js
@@ -101,8 +101,8 @@ app.use(passport.session());
app.use(app.router);
-var oneYear = 31536000000;
-app.use(express['static'](path.join(__dirname, "/../build"), { maxAge: oneYear }));
+var maxAge = (nconf.get('NODE_ENV') === 'production') ? 31536000000 : 0;
+app.use(express['static'](path.join(__dirname, "/../build"), { maxAge: maxAge }));
app.use(express['static'](path.join(__dirname, "/../public")));
// development only
diff --git a/views/index.jade b/views/index.jade
index adec2bc655..733bdca2ae 100644
--- a/views/index.jade
+++ b/views/index.jade
@@ -4,7 +4,7 @@ html
title HabitRPG | Your Life The Role Playing Game
// ?v=1 needed to force refresh
- link(rel='shortcut icon' href='/#{env.getBuildUrl("favicon.ico")}?v=2')
+ link(rel='shortcut icon' href='#{env.getBuildUrl("favicon.ico")}?v=2')
script(type='text/javascript').
window.env = !{JSON.stringify(env)};
@@ -14,74 +14,7 @@ html
display: none;
}
- // CSS Remember to update also in Grunfile.js cssmin task!
- link(rel='stylesheet', href='/#{env.getBuildUrl("bower_components/bootstrap/docs/assets/css/bootstrap.css")}')
-
- link(rel='stylesheet', href='/#{env.getBuildUrl("app.css")}')
-
- // HabitRPG Shared
- link(rel='stylesheet', href='/#{env.getBuildUrl("bower_components/habitrpg-shared/dist/spritesheets.css")}')
-
- - if(env.NODE_ENV == 'production'){
- script(type='text/javascript', src='/#{env.getBuildUrl("app.js")}')
- - }else{
- // Remember to update the file list in Gruntfile.js!
- script(type='text/javascript', src='/bower_components/jquery/jquery.min.js')
- script(type='text/javascript', src='/bower_components/jquery.cookie/jquery.cookie.js')
- script(type='text/javascript', src='/bower_components/bootstrap-growl/jquery.bootstrap-growl.min.js')
- script(type='text/javascript', src='/bower_components/bootstrap-tour/build/js/bootstrap-tour.min.js')
- script(type='text/javascript', src='/bower_components/angular/angular.js')
- script(type='text/javascript', src='/bower_components/angular-ui-router/release/angular-ui-router.js')
-
- script(type='text/javascript', src='/bower_components/angular-sanitize/angular-sanitize.min.js')
- script(type='text/javascript', src='/bower_components/marked/lib/marked.js')
-
- script(type='text/javascript', src='/bower_components/angular-resource/angular-resource.js')
- script(type='text/javascript', src='/bower_components/angular-ui/build/angular-ui.js')
- script(type='text/javascript', src='/bower_components/angular-ui-utils/modules/keypress/keypress.js')
-
- script(type='text/javascript', src='/bower_components/angular-loading-bar/build/loading-bar.js')
- // we'll remove this once angular-bootstrap is fixed
- script(type='text/javascript', src='/bower_components/bootstrap/docs/assets/js/bootstrap.min.js')
- script(type='text/javascript', src='/bower_components/angular-bootstrap/ui-bootstrap.min.js')
- script(type='text/javascript', src='/bower_components/angular-bootstrap/ui-bootstrap-tpls.min.js')
- // Sortable
- script(type='text/javascript', src='/bower_components/jquery-ui/ui/minified/jquery.ui.core.min.js')
- script(type='text/javascript', src='/bower_components/jquery-ui/ui/minified/jquery.ui.widget.min.js')
- script(type='text/javascript', src='/bower_components/jquery-ui/ui/minified/jquery.ui.mouse.min.js')
- script(type='text/javascript', src='/bower_components/jquery-ui/ui/minified/jquery.ui.sortable.min.js')
- // habitrpg-shared
- script(type='text/javascript', src='/bower_components/habitrpg-shared/dist/habitrpg-shared.js')
- // app
- script(type='text/javascript', src='/js/app.js')
- script(type='text/javascript', src='/js/services/authServices.js')
- script(type='text/javascript', src='/js/services/notificationServices.js')
- script(type='text/javascript', src='/js/services/sharedServices.js')
- script(type='text/javascript', src='/js/services/userServices.js')
- script(type='text/javascript', src='/js/services/groupServices.js')
- script(type='text/javascript', src='/js/services/memberServices.js')
- script(type='text/javascript', src='/js/services/guideServices.js')
- script(type='text/javascript', src='/js/services/challengeServices.js')
-
- script(type='text/javascript', src='/js/filters/filters.js')
-
- script(type='text/javascript', src='/js/directives/directives.js')
-
- script(type='text/javascript', src='/js/controllers/authCtrl.js')
- script(type='text/javascript', src='/js/controllers/notificationCtrl.js')
- script(type='text/javascript', src='/js/controllers/rootCtrl.js')
- script(type='text/javascript', src='/js/controllers/settingsCtrl.js')
- script(type='text/javascript', src='/js/controllers/headerCtrl.js')
- script(type='text/javascript', src='/js/controllers/tasksCtrl.js')
- script(type='text/javascript', src='/js/controllers/filtersCtrl.js')
- script(type='text/javascript', src='/js/controllers/userCtrl.js')
- script(type='text/javascript', src='/js/controllers/groupsCtrl.js')
- script(type='text/javascript', src='/js/controllers/petsCtrl.js')
- script(type='text/javascript', src='/js/controllers/inventoryCtrl.js')
- script(type='text/javascript', src='/js/controllers/marketCtrl.js')
- script(type='text/javascript', src='/js/controllers/footerCtrl.js')
- script(type='text/javascript', src='/js/controllers/challengesCtrl.js')
- -}
+ != env.getManifestFiles("app")
//webfonts
link(href='//fonts.googleapis.com/css?family=Lato:300,400,700,400italic,700italic', rel='stylesheet', type='text/css')
diff --git a/views/static/layout.jade b/views/static/layout.jade
index 29837f2e79..6d797f34e5 100644
--- a/views/static/layout.jade
+++ b/views/static/layout.jade
@@ -7,35 +7,12 @@ html
block title
title HabitRPG | Your Life the Role Playing Game
- link(rel='shortcut icon', href='/#{env.getBuildUrl("favicon.ico")}?v=2')
+ link(rel='shortcut icon', href='#{env.getBuildUrl("favicon.ico")}?v=2')
meta(charset='utf-8')
meta(name='viewport', content='width=device-width, initial-scale=1.0')
- // CSS Remember to update also in Grunfile.js cssmin task!
- link(rel='stylesheet', href='/#{env.getBuildUrl("bower_components/bootstrap/docs/assets/css/bootstrap.css")}')
- // Keep this out of build because the one after has some images and would like not to override it
- link(rel='stylesheet', href='/#{env.getBuildUrl("bower_components/bootstrap/docs/assets/css/bootstrap-responsive.css")}')
- link(rel='stylesheet', href='/#{env.getBuildUrl("bower_components/bootstrap/docs/assets/css/docs.css")}')
-
- link(rel='stylesheet', href='/#{env.getBuildUrl("static.css")}')
-
- // JS
- - if(layoutEnv.NODE_ENV == 'production'){
- script(type='text/javascript', src='/#{env.getBuildUrl("static.js")}')
- - }else{
- // Remember to update the file list in Gruntfile.js!
- script(type='text/javascript', src='/bower_components/jquery/jquery.min.js')
- script(type='text/javascript', src='/bower_components/habitrpg-shared/dist/habitrpg-shared.js')
- script(type='text/javascript', src='/bower_components/angular/angular.min.js')
- script(type='text/javascript', src='/bower_components/angular-resource/angular-resource.min.js')
- script(type='text/javascript', src='/bower_components/bootstrap/docs/assets/js/bootstrap.min.js')
- script(type='text/javascript', src='/bower_components/angular-loading-bar/build/loading-bar.js')
-
- script(type='text/javascript', src='/js/static.js')
- script(type='text/javascript', src='/js/services/userServices.js')
- script(type='text/javascript', src='/js/controllers/authCtrl.js')
- -}
+ != env.getManifestFiles("static")
script(type='text/javascript').
$.getScript("//s7.addthis.com/js/250/addthis_widget.js#pubid=lefnire");