Make sure Minify.js finds its files

pull/314/head
Azul 2012-01-05 11:31:39 +01:00
parent 33ffda19b1
commit b1faa8e0f8
1 changed files with 11 additions and 9 deletions

View File

@ -58,7 +58,9 @@ exports.minifyJS = function(req, res, jsFilename)
{
throw new Error("there is no profile for creating " + name);
}
var rootPath = path.normalize(__dirname + "/../../" );
//minifying is enabled
if(settings.minify)
{
@ -70,7 +72,7 @@ exports.minifyJS = function(req, res, jsFilename)
//find out the highest modification date
function(callback)
{
var folders2check = ["../static/css","../static/js"];
var folders2check = [rootPath + "static/css", rootPath + "static/js"];
//go trough this two folders
async.forEach(folders2check, function(path, callback)
@ -109,7 +111,7 @@ exports.minifyJS = function(req, res, jsFilename)
function(callback)
{
//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")
{
@ -134,7 +136,7 @@ exports.minifyJS = function(req, res, jsFilename)
{
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;
fileValues[item] = data;
@ -228,7 +230,7 @@ exports.minifyJS = function(req, res, jsFilename)
//write the results plain in a file
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
function(callback)
@ -242,7 +244,7 @@ exports.minifyJS = function(req, res, jsFilename)
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
@ -266,12 +268,12 @@ exports.minifyJS = function(req, res, jsFilename)
var pathStr;
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');
}
else
{
pathStr = path.normalize(__dirname + "/../../var/minified_" + jsFilename );
pathStr = path.normalize(rootPath + "var/minified_" + jsFilename );
}
res.sendfile(pathStr, { maxAge: server.maxAge });
@ -285,7 +287,7 @@ exports.minifyJS = function(req, res, jsFilename)
//read all js files
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;
fileValues[item] = data;