diff --git a/node/utils/Minify.js b/node/utils/Minify.js
index baeaee688..859ee07ae 100644
--- a/node/utils/Minify.js
+++ b/node/utils/Minify.js
@@ -213,6 +213,72 @@ function _handle(req, res, jsFilename, jsFiles) {
}
}
+// find all includes in ace.js and embed them.
+function getAceFile(callback) {
+ fs.readFile(JS_DIR + 'ace.js', "utf8", function(err, data) {
+ if(ERR(err, callback)) return;
+
+ // Find all includes in ace.js and embed them
+ var founds = data.match(/\$\$INCLUDE_[a-zA-Z_]+\([a-zA-Z0-9.\/_"-]+\)/gi);
+ if (!settings.minify) {
+ founds = [];
+ }
+ founds.push('$$INCLUDE_JS("../static/js/require-kernel.js")');
+
+ data += ';\n';
+ data += 'Ace2Editor.EMBEDED = Ace2Editor.EMBEDED || {};\n';
+
+ //go trough all includes
+ async.forEach(founds, function (item, callback) {
+ var filename = item.match(/"([^"]*)"/)[1];
+ var type = item.match(/INCLUDE_([A-Z]+)/)[1];
+ var shortFilename = (filename.match(/^..\/static\/js\/(.*)$/, '')||[])[1];
+
+ //read the included files
+ if (shortFilename) {
+ if (shortFilename == 'require-kernel.js') {
+ // the kernel isn’t actually on the file system.
+ handleEmbed(null, requireDefinition());
+ } else {
+ var contents = '';
+ tarCode(tar[shortFilename] || shortFilename
+ , function (content) {
+ contents += content;
+ }
+ , function () {
+ handleEmbed(null, contents);
+ }
+ );
+ }
+ } else {
+ fs.readFile(ROOT_DIR + filename, "utf8", handleEmbed);
+ }
+
+ function handleEmbed(error, data_) {
+ if (error) {
+ return; // Don't bother to include it.
+ }
+ if (settings.minify) {
+ if (type == "JS") {
+ try {
+ data_ = compressJS([data_]);
+ } catch (e) {
+ // Ignore, include uncompresseed, which will break in browser.
+ }
+ } else {
+ data_ = compressCSS([data_]);
+ }
+ }
+ data += 'Ace2Editor.EMBEDED[' + JSON.stringify(filename) + '] = '
+ + JSON.stringify(data_) + ';\n';
+ callback();
+ }
+ }, function(error) {
+ callback(error, data);
+ });
+ });
+}
+
exports.requireDefinition = requireDefinition;
function requireDefinition() {
return 'var require = ' + RequireKernel.kernelSource + ';\n';
@@ -222,8 +288,12 @@ function tarCode(jsFiles, write, callback) {
write('require.define({');
var initialEntry = true;
async.forEach(jsFiles, function (filename, callback){
- fs.readFile(JS_DIR + filename, "utf8", handleFile);
-
+ if (filename == 'ace.js') {
+ getAceFile(handleFile);
+ } else {
+ fs.readFile(JS_DIR + filename, "utf8", handleFile);
+ }
+
function handleFile(err, data) {
if(ERR(err, callback)) return;
var srcPath = JSON.stringify('/' + filename);
diff --git a/static/js/ace.js b/static/js/ace.js
index 63b1e61fe..6c7bb84e2 100644
--- a/static/js/ace.js
+++ b/static/js/ace.js
@@ -133,6 +133,74 @@ function Ace2Editor()
return info.ace_getUnhandledErrors();
};
+
+
+ function sortFilesByEmbeded(files) {
+ var embededFiles = [];
+ var remoteFiles = [];
+
+ if (Ace2Editor.EMBEDED) {
+ for (var i = 0, ii = files.length; i < ii; i++) {
+ var file = files[i];
+ if (Object.prototype.hasOwnProperty.call(Ace2Editor.EMBEDED, file)) {
+ embededFiles.push(file);
+ } else {
+ remoteFiles.push(file);
+ }
+ }
+ } else {
+ remoteFiles = files;
+ }
+
+ return {embeded: embededFiles, remote: remoteFiles};
+ }
+ function pushRequireScriptTo(buffer) {
+ var KERNEL_SOURCE = '../static/js/require-kernel.js';
+ var KERNEL_BOOT = 'require.setRootURI("../minified/");\nrequire.setGlobalKeyPath("require");'
+ if (Ace2Editor.EMBEDED && Ace2Editor.EMBEDED[KERNEL_SOURCE]) {
+ buffer.push('');
- iframeHTML.push('');
- iframeHTML.push('\
+');
+ pushScriptsTo(iframeHTML);
+
iframeHTML.push('');
iframeHTML.push('