Drop all packaging logic from minify.
parent
3b2a3ad324
commit
78691feec7
|
@ -130,7 +130,7 @@ function getAceFile(callback) {
|
||||||
if(ERR(err, callback)) return;
|
if(ERR(err, callback)) return;
|
||||||
|
|
||||||
// Find all includes in ace.js and embed them
|
// Find all includes in ace.js and embed them
|
||||||
var founds = data.match(/\$\$INCLUDE_[a-zA-Z_]+\([a-zA-Z0-9.\/_"-]+\)/gi);
|
var founds = data.match(/\$\$INCLUDE_[a-zA-Z_]+\("[^"]*"\)/gi);
|
||||||
if (!settings.minify) {
|
if (!settings.minify) {
|
||||||
founds = [];
|
founds = [];
|
||||||
}
|
}
|
||||||
|
@ -142,49 +142,19 @@ function getAceFile(callback) {
|
||||||
//go trough all includes
|
//go trough all includes
|
||||||
async.forEach(founds, function (item, callback) {
|
async.forEach(founds, function (item, callback) {
|
||||||
var filename = item.match(/"([^"]*)"/)[1];
|
var filename = item.match(/"([^"]*)"/)[1];
|
||||||
var type = item.match(/INCLUDE_([A-Z]+)/)[1];
|
var request = require('request');
|
||||||
var shortFilename =
|
|
||||||
(filename.match(/^\.\.\/static\/js\/(.*)$/, '') || [])[1];
|
|
||||||
|
|
||||||
//read the included files
|
var baseURI = 'http://' + settings.ip + ":" + settings.port
|
||||||
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_) {
|
request(baseURI + path.normalize(path.join('/static/', filename)), function (error, response, body) {
|
||||||
if (error) {
|
if (!error && response.statusCode == 200) {
|
||||||
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) + '] = '
|
data += 'Ace2Editor.EMBEDED[' + JSON.stringify(filename) + '] = '
|
||||||
+ JSON.stringify(data_) + ';\n';
|
+ JSON.stringify(body || '') + ';\n';
|
||||||
callback();
|
} else {
|
||||||
|
// Silence?
|
||||||
}
|
}
|
||||||
|
callback();
|
||||||
|
});
|
||||||
}, function(error) {
|
}, function(error) {
|
||||||
callback(error, data);
|
callback(error, data);
|
||||||
});
|
});
|
||||||
|
@ -297,40 +267,6 @@ function getFile(filename, callback) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function tarCode(jsFiles, write, callback) {
|
|
||||||
write('require.define({');
|
|
||||||
var initialEntry = true;
|
|
||||||
async.forEach(jsFiles, function (filename, callback){
|
|
||||||
getFile(filename, handleFile)
|
|
||||||
|
|
||||||
function handleFile(err, data) {
|
|
||||||
if(ERR(err, callback)) return;
|
|
||||||
var srcPath = JSON.stringify('/' + filename);
|
|
||||||
var srcPathAbbv = JSON.stringify('/' + filename.replace(/\.js$/, ''));
|
|
||||||
if (!initialEntry) {
|
|
||||||
write('\n,');
|
|
||||||
} else {
|
|
||||||
initialEntry = false;
|
|
||||||
}
|
|
||||||
write(srcPath + ': ')
|
|
||||||
data = '(function (require, exports, module) {' + data + '})';
|
|
||||||
if (settings.minify) {
|
|
||||||
write(compressJS([data]));
|
|
||||||
} else {
|
|
||||||
write(data);
|
|
||||||
}
|
|
||||||
if (srcPath != srcPathAbbv) {
|
|
||||||
write('\n,' + srcPathAbbv + ': null');
|
|
||||||
}
|
|
||||||
|
|
||||||
callback();
|
|
||||||
}
|
|
||||||
}, function () {
|
|
||||||
write('});\n');
|
|
||||||
callback();
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
function compressJS(values)
|
function compressJS(values)
|
||||||
{
|
{
|
||||||
var complete = values.join("\n");
|
var complete = values.join("\n");
|
||||||
|
|
|
@ -11,6 +11,7 @@
|
||||||
],
|
],
|
||||||
"dependencies" : {
|
"dependencies" : {
|
||||||
"yajsml" : "1.1.1",
|
"yajsml" : "1.1.1",
|
||||||
|
"request" : "2.9.100",
|
||||||
"require-kernel" : "1.0.3",
|
"require-kernel" : "1.0.3",
|
||||||
"socket.io" : "0.8.7",
|
"socket.io" : "0.8.7",
|
||||||
"ueberDB" : "0.1.7",
|
"ueberDB" : "0.1.7",
|
||||||
|
|
|
@ -228,17 +228,15 @@ function Ace2Editor()
|
||||||
}
|
}
|
||||||
function pushScriptsTo(buffer) {
|
function pushScriptsTo(buffer) {
|
||||||
/* Folling is for packaging regular expression. */
|
/* Folling is for packaging regular expression. */
|
||||||
/* $$INCLUDE_JS("../static/js/ace2_inner.js"); */
|
/* $$INCLUDE_JS("../minified/ace2_inner.js?callback=require.define"); */
|
||||||
var ACE_SOURCE = '../static/js/ace2_inner.js';
|
var ACE_SOURCE = '../minified/ace2_inner.js?callback=require.define';
|
||||||
if (Ace2Editor.EMBEDED && Ace2Editor.EMBEDED[ACE_SOURCE]) {
|
if (Ace2Editor.EMBEDED && Ace2Editor.EMBEDED[ACE_SOURCE]) {
|
||||||
buffer.push('<script type="text/javascript">');
|
buffer.push('<script type="text/javascript">');
|
||||||
buffer.push(Ace2Editor.EMBEDED[ACE_SOURCE]);
|
buffer.push(Ace2Editor.EMBEDED[ACE_SOURCE]);
|
||||||
buffer.push('require("/ace2_inner");');
|
buffer.push('require("/ace2_inner");');
|
||||||
buffer.push('<\/script>');
|
buffer.push('<\/script>');
|
||||||
} else {
|
} else {
|
||||||
file = ACE_SOURCE;
|
buffer.push('<script type="application/javascript" src="' + ACE_SOURCE + '"><\/script>');
|
||||||
file = file.replace(/^\.\.\/static\/js\//, '../minified/');
|
|
||||||
buffer.push('<script type="application/javascript" src="' + file + '?callback=require.define"><\/script>');
|
|
||||||
buffer.push('<script type="text/javascript">');
|
buffer.push('<script type="text/javascript">');
|
||||||
buffer.push('require("/ace2_inner");');
|
buffer.push('require("/ace2_inner");');
|
||||||
buffer.push('<\/script>');
|
buffer.push('<\/script>');
|
||||||
|
|
Loading…
Reference in New Issue