Extract file retrieval.
This commit is contained in:
parent
e68413d998
commit
ebb5055ce8
|
@ -73,7 +73,7 @@ function _handle(req, res, jsFilename, jsFiles) {
|
||||||
//minifying is enabled
|
//minifying is enabled
|
||||||
if(settings.minify)
|
if(settings.minify)
|
||||||
{
|
{
|
||||||
var fileValues = {};
|
var result = undefined;
|
||||||
var latestModification = 0;
|
var latestModification = 0;
|
||||||
|
|
||||||
async.series([
|
async.series([
|
||||||
|
@ -142,30 +142,20 @@ function _handle(req, res, jsFilename, jsFiles) {
|
||||||
//load all js files
|
//load all js files
|
||||||
function (callback)
|
function (callback)
|
||||||
{
|
{
|
||||||
async.forEach(jsFiles, function (item, callback)
|
var values = [];
|
||||||
{
|
tarCode(
|
||||||
if (item == 'ace.js') {
|
jsFiles
|
||||||
getAceFile(handleFile);
|
, function (content) {values.push(content)}
|
||||||
} else {
|
, function (err) {
|
||||||
fs.readFile(JS_DIR + item, "utf-8", handleFile);
|
if(ERR(err)) return;
|
||||||
}
|
|
||||||
|
|
||||||
function handleFile(err, data)
|
result = values.join('');
|
||||||
{
|
callback();
|
||||||
if(ERR(err, callback)) return;
|
});
|
||||||
fileValues[item] = data;
|
|
||||||
callback();
|
|
||||||
}
|
|
||||||
}, callback);
|
|
||||||
},
|
},
|
||||||
//put all together and write it into a file
|
//put all together and write it into a file
|
||||||
function(callback)
|
function(callback)
|
||||||
{
|
{
|
||||||
//minify all javascript files to one
|
|
||||||
var values = [];
|
|
||||||
tarCode(jsFiles, fileValues, function (content) {values.push(content)});
|
|
||||||
var result = compressJS(values);
|
|
||||||
|
|
||||||
async.parallel([
|
async.parallel([
|
||||||
//write the results plain in a file
|
//write the results plain in a file
|
||||||
function(callback)
|
function(callback)
|
||||||
|
@ -213,25 +203,11 @@ function _handle(req, res, jsFilename, jsFiles) {
|
||||||
//minifying is disabled, so put the files together in one file
|
//minifying is disabled, so put the files together in one file
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
var fileValues = {};
|
tarCode(
|
||||||
|
jsFiles
|
||||||
//read all js files
|
, function (content) {res.write(content)}
|
||||||
async.forEach(jsFiles, function (item, callback)
|
, function (err) {
|
||||||
{
|
|
||||||
fs.readFile(JS_DIR + item, "utf-8", function(err, data)
|
|
||||||
{
|
|
||||||
if(ERR(err, callback)) return;
|
|
||||||
fileValues[item] = data;
|
|
||||||
callback();
|
|
||||||
});
|
|
||||||
},
|
|
||||||
//send all files together
|
|
||||||
function(err)
|
|
||||||
{
|
|
||||||
if(ERR(err)) return;
|
if(ERR(err)) return;
|
||||||
|
|
||||||
tarCode(jsFiles, fileValues, function (content) {res.write(content)});
|
|
||||||
|
|
||||||
res.end();
|
res.end();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -301,12 +277,25 @@ function requireDefinition() {
|
||||||
return 'var require = ' + RequireKernel.kernelSource + ';\n';
|
return 'var require = ' + RequireKernel.kernelSource + ';\n';
|
||||||
}
|
}
|
||||||
|
|
||||||
function tarCode(filesInOrder, files, write) {
|
function tarCode(jsFiles, write, callback) {
|
||||||
for(var i = 0, ii = filesInOrder.length; i < filesInOrder.length; i++) {
|
async.forEach(jsFiles, function (item, callback){
|
||||||
var filename = filesInOrder[i];
|
if (item == 'ace.js') {
|
||||||
write("\n\n\n/*** File: static/js/" + filename + " ***/\n\n\n");
|
getAceFile(handleFile);
|
||||||
write(isolateJS(files[filename], filename));
|
} else {
|
||||||
}
|
fs.readFile(JS_DIR + item, "utf8", handleFile);
|
||||||
|
}
|
||||||
|
|
||||||
|
function handleFile(err, data) {
|
||||||
|
if(ERR(err, callback)) return;
|
||||||
|
write("\n\n\n/*** File: static/js/" + item + " ***/\n\n\n");
|
||||||
|
if (settings.minify) {
|
||||||
|
write(compressJS([isolateJS(data, item)]) + ';\n');
|
||||||
|
} else {
|
||||||
|
write(isolateJS(data, item));
|
||||||
|
}
|
||||||
|
callback();
|
||||||
|
}
|
||||||
|
}, callback);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Wrap the following code in a self executing function and assign exports to
|
// Wrap the following code in a self executing function and assign exports to
|
||||||
|
|
Loading…
Reference in New Issue