Skip to content

Commit

Permalink
Merge pull request #285 from skrenek/master
Browse files Browse the repository at this point in the history
Efficiency improvements
  • Loading branch information
skrenek committed Jun 11, 2014
2 parents 9b0584c + b1971de commit 69e2dfa
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 41 deletions.
9 changes: 6 additions & 3 deletions lib/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,10 @@
"port": 8081,
"host": "localhost",
"log level": 1,
"log level docs": "0 = error, 1 = warn, 2 = info, 3 = debug"
"log level docs": "0 = error, 1 = warn, 2 = info, 3 = debug",
"browser client minification": true,
"browser client etag": true,
"browser client gzip": true
},

"auth": {
Expand Down Expand Up @@ -220,7 +223,7 @@
{
"name": "bootstrap",
"jsFiles": [
"/feather-client/lib/bootstrap/js/bootstrap.min.js",
"//netdna.bootstrapcdn.com/twitter-bootstrap/2.0.4/js/bootstrap.min.js",
"/feather-client/ui-bootstrap.js"
],
"cssFiles": [
Expand All @@ -231,7 +234,7 @@
{
"name": "bootstrap3",
"jsFiles": [
"/feather-client/lib/bootstrap3/js/bootstrap.min.js",
"//netdna.bootstrapcdn.com/bootstrap/3.0.0/js/bootstrap.min.js",
"/feather-client/ui-bootstrap3.js"
],
"cssFiles": [
Expand Down
12 changes: 4 additions & 8 deletions lib/middleware.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
var Connect = require("connect"),
router = require("./router"),
cache = require("./simple-cache");
gzip = require('connect-gzip'),
cache = require("./simple-cache"),
feather = require('./feather'),
Semaphore = require('./semaphore'),
_ = require("underscore")._,
Expand Down Expand Up @@ -73,11 +72,7 @@ exports.getMiddleware = function(options, cb) {

router.getRouter(options, function(err, _router) {
if (err) cb(err); else {
if(options.resources.publish.gzip){
var staticHandler = gzip.staticGzip(options.publicRoot);
} else {
var staticHandler = Connect.static(options.publicRoot);
}
var staticHandler = Connect.static(options.publicRoot);
var bodyParserMiddleware = bodyParser();
var multerOptions = _.extend({}, appOptions.safeGet('connect.bodyParser.multipart'), appOptions.fileUploadOptions);

Expand Down Expand Up @@ -278,7 +273,8 @@ exports.getMiddleware = function(options, cb) {
];

if(options.resources.publish.gzip){
middleware.unshift(gzip.gzip());
logger.debug('enabling gzip');
middleware.unshift(Connect.compress({threshold: 2048}));
}

function completeMiddleware() {
Expand Down
65 changes: 36 additions & 29 deletions lib/resource-packager.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ var getPackagePublisher = function(options, callback) {
var newCache = false,
hrefPrefix = typeof options.hrefPrefix === "undefined" ? "/" : options.hrefPrefix,
resourceOptions = options.appOptions.resources,
pkg = _.detect(resourceOptions.packages, function(pkg) {
return pkg.name === options.cacheName || pkg.publishType === options.publishType;
pkg = _.detect(resourceOptions.packages, function(pkg) {
return pkg.name === options.cacheName || pkg.publishType === options.publishType;
}),
publisherOptions = null;

Expand All @@ -65,10 +65,10 @@ var getPackagePublisher = function(options, callback) {
});
publisher.publishers.add(availableResourcePublishers.findById(publisherOptions.id));
resourcePublishersInUse.add(publisher);
}
}

callback(null, _.extend({
publisher: publisher,
publisher: publisher,
packageOptions: pkgOptions,
newCache: newCache,
}, options));
Expand All @@ -88,18 +88,18 @@ var getPackagePublisher = function(options, callback) {
* }</pre>
* @name resourcePackager.packageResources
* @param {Object} options see example in description above.
* @function
* @function
*/
exports.packageResources = function(options, callback) {
if (!options.files || !options.files.length) {
callback("Cannot package resources; the files array is either empty or not present.");
} else {
simpleCache.getItem("feather-logger", function(err, logger) {

getPackagePublisher(options, function(err, getPubResults) {

var publisher = getPubResults.publisher,
packageOptions = getPubResults.packageOptions,
var publisher = getPubResults.publisher,
packageOptions = getPubResults.packageOptions,
//publisherOptions = _.extend(getPubResults.publisher.publisherOptions, pkgOptions),
newCache = getPubResults.newCache,
consolidate = packageOptions.consolidate,
Expand Down Expand Up @@ -129,7 +129,7 @@ exports.packageResources = function(options, callback) {
$j.tmpl(options.template, {
href: component.url
}).appendTo($j('resources'));
});
});
}
}
}
Expand All @@ -140,7 +140,7 @@ exports.packageResources = function(options, callback) {
var sem = new Semaphore(function() {
publisher.publish({
publisherOptions: publisher.publisherOptions,
packageOptions: packageOptions
packageOptions: packageOptions
}, finalizePublish);
});
sem.semaphore = options.files.length;
Expand All @@ -151,7 +151,7 @@ exports.packageResources = function(options, callback) {
var filePath = path.join(file.prefix+file.path),
minifyAllowed = (!file.minifyAllowed || file.minifyAllowed === true); // if it's true or missing, minify is allowed.

fs.readFile(filePath, "utf8", function(err, content) {
fs.readFile(filePath, "utf8", function(err, content) {
if (err) {
if(!filePath.match(/\.css$/)) { //not an error state if we're missing a css file - don't log
logger.error({message:"unable to open " + filePath + ": " + err, immediately: true, category:"feather.respack"});
Expand Down Expand Up @@ -244,15 +244,16 @@ exports.packageFrameworkResources = function(options, callback) {
var prefix = options.appOptions.featherRoot,
featherFiles = items['feather-files'],
restProxyInfo = items['feather-restProxyInfo'];

var cssFiles = [];

// js -----------------------------------------------------------------
var jsFiles = [
{path: "/feather-client/lib/underscore-min.js", prefix: prefix},
options.appOptions["socket.io"].enabled ? {path: "/socket.io/socket.io.js", prefix: prefix, virtual: true} : null,
{path: "/feather-client/lib/json2.js", prefix: prefix, minifyAllowed: false},
{path: "/feather-client/lib/jquery-1.7.min.js", prefix: prefix},
//{path: "/feather-client/lib/jquery-1.7.min.js", prefix: prefix},
{path: "https://code.jquery.com/jquery-1.7.2.min.js", prefix: prefix, virtual: true},
// {path: "/feather-client/lib/jquery-1.9.migrate.min.js", prefix: prefix},
{path: "/feather-client/lib/jquery.tmpl.js", prefix: prefix},
{path: "/feather-client/lib/jquery.cookie.js", prefix: prefix},
Expand All @@ -277,20 +278,20 @@ exports.packageFrameworkResources = function(options, callback) {
prefix: restProxyInfo.prefix
});
}

// Only add the auth scripts if this app has auth enabled.
if (options.appOptions.auth.enabled) {
//jsFiles.push({path: "feather-client/sha512.js", prefix: prefix});
jsFiles.push({path: "/feather-client/auth-client.js", prefix: prefix});
}

// Add datalinking if enabled
if (options.appOptions.data.datalinking.enabled) {
jsFiles.push({path: "/feather-client/lib/jquery.datalink.js", prefix: prefix});
}

// Add files for the ui provider if enabled
if (options.appOptions.ui.enabled) {
if (options.appOptions.ui.enabled) {
var uiJSPrefix = prefix,
uiCSSPrefix = prefix,
provider = options.appOptions.ui.provider,
Expand All @@ -303,11 +304,17 @@ exports.packageFrameworkResources = function(options, callback) {
}

//get the js files
var nonLocalRegex = /^(\/\/|https?:\/\/)/;
var appFiles = _.keys(featherFiles.appFiles);
if (provider.jsRoot === "/") uiJSPrefix = options.appOptions.publicRoot;
_.each(provider.jsFiles, function(file) {
var _path = file,
_prefix = uiJSPrefix;
_prefix = uiJSPrefix,
virtual = false;

if (nonLocalRegex.test(_path)) {
virtual = true;
}

//detect automatic app overrides (via dropping in new files in the /public/_ui folder)
var fileName = path.basename(file);
Expand All @@ -319,8 +326,8 @@ exports.packageFrameworkResources = function(options, callback) {
_prefix = options.appOptions.publicRoot;
_path = '/' + path.relative(options.appOptions.publicRoot, overrideFile);
}
jsFiles.push({path: _path, prefix: _prefix});

jsFiles.push({path: _path, prefix: _prefix, virtual: virtual});
});

//get the css files
Expand All @@ -339,7 +346,7 @@ exports.packageFrameworkResources = function(options, callback) {
_prefix = options.appOptions.publicRoot;
_path = '/' + path.relative(options.appOptions.publicRoot, overrideFile);
}

cssFiles.push({path: _path, prefix: _prefix});
});
}
Expand All @@ -353,12 +360,12 @@ exports.packageFrameworkResources = function(options, callback) {
});

var frameworkPackaged = new Semaphore(callback);

frameworkPackaged.increment();
exports.packageResources(jsOptions, function(err) {
frameworkPackaged.execute(err);
});

if (cssFiles.length) {

var cssOptions = _.extend(_.clone(options), {
Expand Down Expand Up @@ -412,7 +419,7 @@ exports.packageWidgetResources = function(options, callback) {
* url(i.jpg);
*/
exports.resolveCssUrls = function (filePath, content) {

// TODO: Make sure http urls work.
var urlRegex = /url\((["']?)([^\/|^"\/|^'\/].+)(["']?)\)/g
var dir = path.dirname(filePath);
Expand All @@ -436,7 +443,7 @@ function packageWidgetJs(options, callback) {
contentType: "text/javascript",
files: []
});

options.widgetClassRegistry.each(function(widgetClass) {
var widgetJsFiles = [];
if (widgetClass.classDef && !widgetClass.classDef.prototype.serverOnly) {
Expand All @@ -447,8 +454,8 @@ function packageWidgetJs(options, callback) {

// Include any other js files in the widget's folder.
widgetJsFiles = _.filter(fs.readdirSync(path.join(options.appOptions.publicRoot, widgetClass.widgetRoot)), function(filename) {
return path.extname(filename) === ".js"
&& filename !== path.basename(widgetClass.clientHrefPath)
return path.extname(filename) === ".js"
&& filename !== path.basename(widgetClass.clientHrefPath)
&& filename !== (widgetClass.widgetName + '.server.js');
});

Expand All @@ -464,7 +471,7 @@ function packageWidgetJs(options, callback) {
}

function packageWidgetCss(options, callback) {

var packageInfo = _.extend(_.clone(options), {
template: '<link rel="stylesheet" type="text/css" href="${href}" />',
cacheName: path.relative(options.appOptions.publicRoot, path.resolve(options.appOptions.publicRoot, options.request.page)) + '.css',
Expand Down
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
"cli": "~0.4.5",
"colorize": "~0.1.0",
"connect": "~2.12.0",
"connect-gzip": "git+http://github.com/tikonen/connect-gzip.git#44bccfe4b3",
"connect-redis": "1.4.6",
"cradle": "git+http://github.com/ryedin/cradle.git#4246311c3b87",
"daemon": "~1.1.0",
Expand Down

0 comments on commit 69e2dfa

Please sign in to comment.