Make sure Minify.js finds its files
parent
33ffda19b1
commit
b1faa8e0f8
|
@ -58,7 +58,9 @@ exports.minifyJS = function(req, res, jsFilename)
|
||||||
{
|
{
|
||||||
throw new Error("there is no profile for creating " + name);
|
throw new Error("there is no profile for creating " + name);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var rootPath = path.normalize(__dirname + "/../../" );
|
||||||
|
|
||||||
//minifying is enabled
|
//minifying is enabled
|
||||||
if(settings.minify)
|
if(settings.minify)
|
||||||
{
|
{
|
||||||
|
@ -70,7 +72,7 @@ exports.minifyJS = function(req, res, jsFilename)
|
||||||
//find out the highest modification date
|
//find out the highest modification date
|
||||||
function(callback)
|
function(callback)
|
||||||
{
|
{
|
||||||
var folders2check = ["../static/css","../static/js"];
|
var folders2check = [rootPath + "static/css", rootPath + "static/js"];
|
||||||
|
|
||||||
//go trough this two folders
|
//go trough this two folders
|
||||||
async.forEach(folders2check, function(path, callback)
|
async.forEach(folders2check, function(path, callback)
|
||||||
|
@ -109,7 +111,7 @@ exports.minifyJS = function(req, res, jsFilename)
|
||||||
function(callback)
|
function(callback)
|
||||||
{
|
{
|
||||||
//check the modification time of the minified js
|
//check the modification time of the minified js
|
||||||
fs.stat("../var/minified_" + jsFilename, function(err, stats)
|
fs.stat(rootPath + "var/minified_" + jsFilename, function(err, stats)
|
||||||
{
|
{
|
||||||
if(err && err.code != "ENOENT")
|
if(err && err.code != "ENOENT")
|
||||||
{
|
{
|
||||||
|
@ -134,7 +136,7 @@ exports.minifyJS = function(req, res, jsFilename)
|
||||||
{
|
{
|
||||||
async.forEach(jsFiles, function (item, callback)
|
async.forEach(jsFiles, function (item, callback)
|
||||||
{
|
{
|
||||||
fs.readFile("../static/js/" + item, "utf-8", function(err, data)
|
fs.readFile(rootPath + "static/js/" + item, "utf-8", function(err, data)
|
||||||
{
|
{
|
||||||
if(ERR(err, callback)) return;
|
if(ERR(err, callback)) return;
|
||||||
fileValues[item] = data;
|
fileValues[item] = data;
|
||||||
|
@ -228,7 +230,7 @@ exports.minifyJS = function(req, res, jsFilename)
|
||||||
//write the results plain in a file
|
//write the results plain in a file
|
||||||
function(callback)
|
function(callback)
|
||||||
{
|
{
|
||||||
fs.writeFile("../var/minified_" + jsFilename, result, "utf8", callback);
|
fs.writeFile(rootPath + "var/minified_" + jsFilename, result, "utf8", callback);
|
||||||
},
|
},
|
||||||
//write the results compressed in a file
|
//write the results compressed in a file
|
||||||
function(callback)
|
function(callback)
|
||||||
|
@ -242,7 +244,7 @@ exports.minifyJS = function(req, res, jsFilename)
|
||||||
|
|
||||||
if(ERR(err, callback)) return;
|
if(ERR(err, callback)) return;
|
||||||
|
|
||||||
fs.writeFile("../var/minified_" + jsFilename + ".gz", compressedResult, callback);
|
fs.writeFile(rootPath + "var/minified_" + jsFilename + ".gz", compressedResult, callback);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
//skip this step on windows
|
//skip this step on windows
|
||||||
|
@ -266,12 +268,12 @@ exports.minifyJS = function(req, res, jsFilename)
|
||||||
var pathStr;
|
var pathStr;
|
||||||
if(gzipSupport && os.type().indexOf("Windows") == -1)
|
if(gzipSupport && os.type().indexOf("Windows") == -1)
|
||||||
{
|
{
|
||||||
pathStr = path.normalize(__dirname + "/../../var/minified_" + jsFilename + ".gz");
|
pathStr = path.normalize(rootPath + "var/minified_" + jsFilename + ".gz");
|
||||||
res.header('Content-Encoding', 'gzip');
|
res.header('Content-Encoding', 'gzip');
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
pathStr = path.normalize(__dirname + "/../../var/minified_" + jsFilename );
|
pathStr = path.normalize(rootPath + "var/minified_" + jsFilename );
|
||||||
}
|
}
|
||||||
|
|
||||||
res.sendfile(pathStr, { maxAge: server.maxAge });
|
res.sendfile(pathStr, { maxAge: server.maxAge });
|
||||||
|
@ -285,7 +287,7 @@ exports.minifyJS = function(req, res, jsFilename)
|
||||||
//read all js files
|
//read all js files
|
||||||
async.forEach(jsFiles, function (item, callback)
|
async.forEach(jsFiles, function (item, callback)
|
||||||
{
|
{
|
||||||
fs.readFile("../static/js/" + item, "utf-8", function(err, data)
|
fs.readFile(rootPath + "static/js/" + item, "utf-8", function(err, data)
|
||||||
{
|
{
|
||||||
if(ERR(err, callback)) return;
|
if(ERR(err, callback)) return;
|
||||||
fileValues[item] = data;
|
fileValues[item] = data;
|
||||||
|
|
Loading…
Reference in New Issue