diff --git a/node/server.js b/node/server.js index 422bbe12..c0d6ce6a 100644 --- a/node/server.js +++ b/node/server.js @@ -114,7 +114,15 @@ async.waterfall([ gracefulShutdown(); }); + //serve minified files + app.get('/minified/:filename', minify.minifyJS); + //serve static files + app.get('/static/js/require-kernel.js', function (req, res, next) { + res.header("Content-Type","application/javascript; charset: utf-8"); + res.write(minify.requireDefinition()); + res.end(); + }); app.get('/static/*', function(req, res) { var filePath = path.normalize(__dirname + "/.." + diff --git a/node/utils/Minify.js b/node/utils/Minify.js index 1a214fb9..348f2537 100644 --- a/node/utils/Minify.js +++ b/node/utils/Minify.js @@ -29,6 +29,7 @@ var pro = require("uglify-js").uglify; var path = require('path'); var Buffer = require('buffer').Buffer; var gzip = require('gzip'); +var RequireKernel = require('require-kernel'); var server = require('../server'); var os = require('os'); @@ -52,10 +53,21 @@ exports.minifyJS = function(req, res, next) var jsFiles = undefined; if (Object.prototype.hasOwnProperty.call(tar, jsFilename)) { jsFiles = tar[jsFilename]; + _handle(req, res, jsFilename, jsFiles) } else { - return next(); + // Not in tar list, but try anyways, if it fails, pass to `next`. + jsFiles = [jsFilename]; + fs.stat(JS_DIR + jsFilename, function (error, stats) { + if (error || !stats.isFile()) { + next(); + } else { + _handle(req, res, jsFilename, jsFiles); + } + }); } +} +function _handle(req, res, jsFilename, jsFiles) { res.header("Content-Type","text/javascript"); //minifying is enabled @@ -151,7 +163,7 @@ exports.minifyJS = function(req, res, next) return; } - var founds = fileValues["ace.js"].match(/\$\$INCLUDE_[a-zA-Z_]+\([a-zA-Z0-9.\/_"]+\)/gi); + var founds = fileValues["ace.js"].match(/\$\$INCLUDE_[a-zA-Z_]+\([a-zA-Z0-9.\/_"-]+\)/gi); //go trough all includes async.forEach(founds, function (item, callback) @@ -162,21 +174,31 @@ exports.minifyJS = function(req, res, next) var type = item.match(/INCLUDE_[A-Z]+/g)[0].substr("INCLUDE_".length); //read the included file - fs.readFile(ROOT_DIR + filename, "utf-8", function(err, data) + var shortFilename = filename.replace(/^..\/static\/js\//, ''); + if (shortFilename == 'require-kernel.js') { + // the kernel isn’t actually on the file system. + handleEmbed(null, requireDefinition()); + } else { + fs.readFile(ROOT_DIR + filename, "utf-8", handleEmbed); + } + function handleEmbed(err, data) { if(ERR(err, callback)) return; if(type == "JS") { - embeds[filename] = compressJS([data]); + if (shortFilename == 'require-kernel.js') { + embeds[filename] = compressJS([data]); + } else { + embeds[filename] = compressJS([isolateJS(data, shortFilename)]); + } } else { embeds[filename] = compressCSS([data]); } - callback(); - }); + } }, function(err) { if(ERR(err, callback)) return; @@ -197,14 +219,9 @@ exports.minifyJS = function(req, res, next) //put all together and write it into a file function(callback) { - //put all javascript files in an array - var values = []; - for(var i in jsFiles) - { - values.push(fileValues[jsFiles[i]]); - } - //minify all javascript files to one + var values = []; + tarCode(jsFiles, fileValues, function (content) {values.push(content)}); var result = compressJS(values); async.parallel([ @@ -280,18 +297,44 @@ exports.minifyJS = function(req, res, next) { if(ERR(err)) return; - for(var i=0;i'); + buffer.push(Ace2Editor.EMBEDED[KERNEL_SOURCE]); + buffer.push('<\/script>'); + } else { + buffer.push(' + @@ -337,5 +338,13 @@ + + diff --git a/static/timeslider.html b/static/timeslider.html index c1310cc6..4e85047e 100644 --- a/static/timeslider.html +++ b/static/timeslider.html @@ -9,6 +9,7 @@ + @@ -19,6 +20,10 @@ //