diff --git a/.gitignore b/.gitignore index 4fadde4..7ffdf58 100644 --- a/.gitignore +++ b/.gitignore @@ -9,3 +9,4 @@ static/js/libs static/js/templates data/projects/**/workspace data/builds +static/index.html \ No newline at end of file diff --git a/app.js b/app.js index 1112dbd..0214c32 100644 --- a/app.js +++ b/app.js @@ -1,9 +1,9 @@ 'use strict'; -var db = require('./db'), +var env = process.env.NODE_ENV || 'development', + db = require('./db'), http = require('http'), nodeStatic = require('node-static'), - jade = require('jade'), path = require('path'), fs = require('fs'), Steppy = require('twostep').Steppy, @@ -24,15 +24,20 @@ var server = http.createServer(function(req, res) { return httpApi(req, res); } - // serve index for all app pages if (req.url.indexOf('/data.io.js') === -1) { - if (!req.url.match(/(js|css|fonts)/)) { - // Compile a function - var index = jade.compileFile(__dirname + '/views/index.jade'); - res.write(index()); - res.end(); - } else { + if (/(js|css|fonts)/.test(req.url)) { staticServer.serve(req, res); + } else { + // serve index for all app pages + if (env === 'development') { + var jade = require('jade'); + // Compile a function + var index = jade.compileFile(__dirname + '/views/index.jade'); + res.write(index({env: env})); + res.end(); + } else { + staticServer.serve(req, res); + } } } }); diff --git a/package.json b/package.json index be29517..482599c 100644 --- a/package.json +++ b/package.json @@ -9,7 +9,10 @@ "makeTestRepos": "rm -rf test/repos/{mercurial,git}; cd test/repos/ && tar -xf mercurial.tar.gz && tar -xf git.tar.gz", "test": "npm run makeTestRepos && mocha --bail --reporter=spec test/index --timeout 4000", "dev": "gulp", - "sync": "npm install && npm prune && bower install && bower prune" + "sync": "npm install && npm prune && bower install && bower prune", + "buildJs": "r.js -o static/js/requirejs/buid.js", + "buildHtml": "jade views/index.jade --obj '{\"env\": \"production\"}' -o static/", + "build": "npm run buildJs && npm run buildHtml" }, "repository": { "type": "git", @@ -42,7 +45,6 @@ "colors": "1.1.2", "cron": "1.0.9", "data.io": "0.3.0", - "jade": "1.9.2", "nlevel": "1.0.2", "node-static": "0.7.6", "socket.io": "1.3.5", @@ -56,12 +58,14 @@ "gulp-less": "3.0.3", "gulp-nodemon": "2.0.3", "gulp-react-jade-amd": "git://github.com/vladimir-polyakov/gulp-react-jade-amd", + "jade": "1.11.0", "main-bower-files": "2.7.0", "medeadown": "1.1.7", "memdown": "1.0.0", "mocha": "1.18.2", "nci-yaml-reader": "0.1.0", "nodemon": "1.3.7", + "requirejs": "2.1.19", "sinon": "1.14.1" } } diff --git a/static/js/requirejs/buid.js b/static/js/requirejs/buid.js new file mode 100644 index 0000000..1f21f9b --- /dev/null +++ b/static/js/requirejs/buid.js @@ -0,0 +1,14 @@ + +({ + mainConfigFile: 'development.js', + baseUrl: '../', + paths: { + socketio: 'empty:', + _dataio: 'empty:' + }, + name: 'app/app', + preserveLicenseComments: false, + optimize: 'uglify2', + useStrict: true, + out: '../../scripts/app.js' +}); diff --git a/static/js/main.js b/static/js/requirejs/development.js similarity index 87% rename from static/js/main.js rename to static/js/requirejs/development.js index f29d157..1e28885 100644 --- a/static/js/main.js +++ b/static/js/requirejs/development.js @@ -1,14 +1,13 @@ -'use strict'; require.config({ - baseUrl: '/js/', + baseUrl: '/js', paths: { + socketio: '/socket.io/socket.io', + _dataio: '/data.io', underscore: 'libs/underscore/underscore', react: 'libs/react/react-with-addons', 'react-router': 'libs/react-router/build/umd/ReactRouter', reflux: 'libs/reflux/dist/reflux', - _dataio: '/data.io', - socketio: '/socket.io/socket.io.js', jquery: 'libs/jquery/jquery', ansi_up: 'libs/ansi_up/ansi_up', 'bootstrap/collapse': 'libs/bootstrap/js/collapse', diff --git a/static/js/requirejs/production.js b/static/js/requirejs/production.js new file mode 100644 index 0000000..c533b80 --- /dev/null +++ b/static/js/requirejs/production.js @@ -0,0 +1,8 @@ + +require.config({ + baseUrl: '/scripts', + paths: { + socketio: '/socket.io/socket.io', + _dataio: '/data.io', + } +}); diff --git a/static/scripts/app.js b/static/scripts/app.js new file mode 100644 index 0000000..e69de29 diff --git a/views/index.jade b/views/index.jade index f326ea3..e19f0b9 100644 --- a/views/index.jade +++ b/views/index.jade @@ -5,7 +5,18 @@ html link(href="/css/index.css", rel="stylesheet", type="text/css") - script(data-main="/js/main" src="/js/libs/requirejs/require.js") + script + include ../static/js/libs/requirejs/require.js + + if env === 'development' + script + include ../static/js/requirejs/development.js + else + script + include ../static/js/requirejs/production.js + script + include ../static/scripts/app.js + script(type="text/javascript"). require(['app/app']);