Skip to content

Commit

Permalink
compile public stuff into build dir
Browse files Browse the repository at this point in the history
  • Loading branch information
selaux committed Mar 9, 2014
1 parent cacc8d6 commit d62fb0e
Show file tree
Hide file tree
Showing 11 changed files with 77 additions and 36 deletions.
41 changes: 40 additions & 1 deletion Gruntfile.js
Expand Up @@ -56,14 +56,53 @@ module.exports = function (grunt) {
'build/compiledTemplates.js': 'templates/*.hbs'
}
}
},

copy: {
images: {
expand: true,
cwd: 'frontend/images/',
src: '**',
dest: 'build/public/images/'
},
stylesheets: {
expand: true,
cwd: 'frontend/stylesheets/',
src: '*.css',
dest: 'build/public/stylesheets/'
}
},

browserify: {
main: {
files: {
'build/public/javascripts/main.js': [
'lib/Module.js',
'lib/views/*.js',
'lib/handlebars/**/*.js',
'build/compiledTemplates.js',
'frontend/javascripts/main.js'
]
},
options: {
alias: [
'node_modules/jquery/dist/jquery.js:jquery',
'node_modules/lodash/dist/lodash.js:lodash',
'node_modules/backbone/backbone.js:backbone',
'node_modules/socket.io/node_modules/socket.io-client/dist/socket.io.js:socket.io-client'
]
}
}
}

});

grunt.loadNpmTasks('grunt-browserify');
grunt.loadNpmTasks('grunt-contrib-copy');
grunt.loadNpmTasks('grunt-contrib-jshint');
grunt.loadNpmTasks('grunt-contrib-handlebars');
grunt.loadNpmTasks('grunt-mocha-test');

grunt.registerTask('compile', ['handlebars']);
grunt.registerTask('compile', ['handlebars', 'copy', 'browserify']);
grunt.registerTask('test', ['jshint', 'mochaTest']);
};
File renamed without changes.
29 changes: 29 additions & 0 deletions frontend/javascripts/main.js
@@ -0,0 +1,29 @@
'use strict';

var io = require('socket.io-client');

function connect() {
var socket = io.connect('http://' + window.location.host, {
'reconnect': true,
'reconnection delay': 5000,
'max reconnection attempts': Infinity
});

socket.on('update:view', function (id, data) {
var div = document.createElement('div'),
element = document.getElementById(id);
div.innerHTML = data;

element.parentNode.replaceChild(div.firstChild, element);
});

socket.on('connect', function () {
document.getElementById('backend-connection').innerHTML = '';
});

socket.on('disconnect', function () {
document.getElementById('backend-connection').innerHTML = '<div class="alert alert-danger row"><strong>Error:</strong> Backend Disconnected</div>';
});
}

window.onload = connect;
29 changes: 0 additions & 29 deletions frontend/public/javascripts/main.js

This file was deleted.

2 changes: 0 additions & 2 deletions frontend/public/javascripts/vendor/socket.io.min.js

This file was deleted.

File renamed without changes.
File renamed without changes.
File renamed without changes.
1 change: 0 additions & 1 deletion frontend/views/layouts/main.hbs
Expand Up @@ -14,7 +14,6 @@
{{{body}}}
</div>

<script src="/javascripts/vendor/socket.io.min.js"></script>
<script src="/javascripts/main.js"></script>
</body>
</html>
9 changes: 6 additions & 3 deletions frontend/webinterface.js
Expand Up @@ -36,14 +36,17 @@ module.exports = Module.extend({
webinterface.set('config', self.config);
webinterface.set('app', self.app);

webinterface.use(express.favicon(path.join(__dirname, '/public/images/favicon.ico')));
webinterface.use(express.favicon(path.join(__dirname, '../build/public/images/favicon.ico')));
webinterface.use(express.logger('dev'));
webinterface.use(express.bodyParser());
webinterface.use(express.methodOverride());
webinterface.use(webinterface.router);

webinterface.use(require('stylus').middleware(path.join(__dirname, '/public')));
webinterface.use(express.static(path.join(__dirname, '/public')));
webinterface.use(require('stylus').middleware({
src: __dirname,
dest: path.join(__dirname, '../build/public')
}));
webinterface.use(express.static(path.join(__dirname, '../build/public')));
});

webinterface.configure('development', function(){
Expand Down
2 changes: 2 additions & 0 deletions package.json
Expand Up @@ -37,7 +37,9 @@
"socket.io": "0.9.16",
"grunt": "0.4.2",
"grunt-cli": "0.1.9",
"grunt-contrib-copy": "0.5.0",
"grunt-contrib-handlebars": "0.7.0",
"grunt-browserify": "1.3.1",
"handlebars": "1.0.12",
"nodemailer": "0.5.3",
"numeral": "1.5.2",
Expand Down

0 comments on commit d62fb0e

Please sign in to comment.