filter files before minify, removed unused ctime

v1.18.x
barisusakli 11 years ago
parent ab80016910
commit d1b4efeaa3

@ -15,6 +15,10 @@ var uglifyjs = require('uglify-js'),
Minifier.js.minify = function (scripts, minify, callback) { Minifier.js.minify = function (scripts, minify, callback) {
var options = {}; var options = {};
scripts = scripts.filter(function(file) {
return fs.existsSync(file);
});
if (!minify) { if (!minify) {
options.sourceMapURL = '/nodebb.min.js.map'; options.sourceMapURL = '/nodebb.min.js.map';
options.outSourceMap = 'nodebb.min.js.map'; options.outSourceMap = 'nodebb.min.js.map';
@ -32,7 +36,9 @@ Minifier.js.minify = function (scripts, minify, callback) {
} catch(err) { } catch(err) {
process.send({ process.send({
action: 'error', action: 'error',
error: err error: {
message: err.message
}
}); });
} }
}; };

@ -281,32 +281,31 @@ var fs = require('fs'),
}, },
prepare: function (callback) { prepare: function (callback) {
plugins.fireHook('filter:scripts.get', this.scripts, function(err, scripts) { plugins.fireHook('filter:scripts.get', this.scripts, function(err, scripts) {
var ctime, var jsPaths = scripts.map(function (jsPath) {
jsPaths = scripts.map(function (jsPath) { jsPath = path.normalize(jsPath);
jsPath = path.normalize(jsPath);
if (jsPath.substring(0, 7) === 'plugins') {
var matches = _.map(plugins.staticDirs, function(realPath, mappedPath) {
if (jsPath.match(mappedPath)) {
return mappedPath;
} else {
return null;
}
}).filter(function(a) { return a; });
if (matches.length) {
var relPath = jsPath.slice(('plugins/' + matches[0]).length),
pluginId = matches[0].split(path.sep)[0];
return plugins.staticDirs[matches[0]] + relPath; if (jsPath.substring(0, 7) === 'plugins') {
var matches = _.map(plugins.staticDirs, function(realPath, mappedPath) {
if (jsPath.match(mappedPath)) {
return mappedPath;
} else { } else {
winston.warn('[meta.scripts.get] Could not resolve mapped path: ' + jsPath + '. Are you sure it is defined by a plugin?');
return null; return null;
} }
}).filter(function(a) { return a; });
if (matches.length) {
var relPath = jsPath.slice(('plugins/' + matches[0]).length),
pluginId = matches[0].split(path.sep)[0];
return plugins.staticDirs[matches[0]] + relPath;
} else { } else {
return path.join(__dirname, '..', '/public', jsPath); winston.warn('[meta.scripts.get] Could not resolve mapped path: ' + jsPath + '. Are you sure it is defined by a plugin?');
return null;
} }
}); } else {
return path.join(__dirname, '..', '/public', jsPath);
}
});
Meta.js.scripts = jsPaths.filter(function(path) { Meta.js.scripts = jsPaths.filter(function(path) {
return path !== null; return path !== null;
@ -332,8 +331,7 @@ var fs = require('fs'),
emitter.emit('meta:js.compiled'); emitter.emit('meta:js.compiled');
} else { } else {
winston.error('[meta/js] Could not compile client-side scripts!'); winston.error('[meta/js] Could not compile client-side scripts! ' + payload.error.message);
winston.error('[meta/js] ' + payload.error.message);
minifier.kill(); minifier.kill();
process.exit(); process.exit();
} }

Loading…
Cancel
Save