Skip to content
This repository has been archived by the owner on Oct 30, 2018. It is now read-only.

Commit

Permalink
Merge pull request #714 from caridy/yui-groups
Browse files Browse the repository at this point in the history
meta data and combo consolidation for shaker and offline apps:
- removing support for rollups from store.
- consolidate path attribute for all base and resolved metadata for better integration with offline apps.
- bugfix for failures when the first file in a combo was a synthetic file without stats.
- static seed files without combo when combine is false
- store.yui.getAppGroupConfig and store.yui.getAppSeedFiles methods are the hooks for RS addons to control the composition of app group and the seed files array
  • Loading branch information
caridy committed Nov 8, 2012
2 parents 05aa295 + 8b3621c commit 2fe0f3e
Show file tree
Hide file tree
Showing 6 changed files with 353 additions and 355 deletions.
43 changes: 30 additions & 13 deletions lib/app/addons/ac/deploy.server.js
Expand Up @@ -16,8 +16,6 @@ YUI.add('mojito-deploy-addon', function(Y, NAME) {

'use strict';

var fs = require('fs');

/**
* <strong>Access point:</strong> <em>ac.deploy.*</em>
* Provides ability to create client runtime deployment HTML
Expand Down Expand Up @@ -59,13 +57,16 @@ YUI.add('mojito-deploy-addon', function(Y, NAME) {

var store = this.rs,
contextServer = this.ac.context,

appConfigServer = store.getAppConfig(contextServer),
appGroupConfig = store.yui.getAppGroupConfig(),
seedFiles = store.yui.getAppSeedFiles(contextServer),

contextClient,
appConfigClient,
yuiConfig = {},
yuiConfigEscaped,
yuiConfigStr,
closestLang,
viewId,
i,
clientConfig = {},
Expand All @@ -91,8 +92,9 @@ YUI.add('mojito-deploy-addon', function(Y, NAME) {
// a fragment to prepend to the path attribute when
// when building combo urls
root: Y.version + '/build/',
seed: "/static/combo?yui-base.js&loader-base.js&" +
"loader-yui3.js&loader-app-base{langPath}.js&loader.js"
groups: {
app: appGroupConfig
}

}, ((appConfigClient.yui && appConfigClient.yui.config) || {}), {
lang: contextServer.lang // same as contextClient.lang
Expand All @@ -103,15 +105,30 @@ YUI.add('mojito-deploy-addon', function(Y, NAME) {
delete appConfigClient.yui.config;
}

// adjusting the seed based on {langPath} to facilitate
// the customization of the combo url.
closestLang = store.yui.getClosestLang(contextServer.lang);
yuiConfig.seed = yuiConfig.seed.replace('{langPath}',
(closestLang ? '_' + closestLang : ''));

// Set the YUI URL to use on the client (This has to be done
// before any other scripts are added)
assetHandler.addAsset('js', 'top', yuiConfig.seed);
// Set the YUI seed file to use on the client. This has to be done
// before any other scripts are added and can be controlled through
// application.json->yui->config->seed in a form of
// a array with the list of modules or fullpath urls.
if (appGroupConfig.combine === false) {

// if the combo is disabled, then we need to insert one by one
// this is useful for offline and hybrid apps where the combo
// does not work.
for (i = 0; i < seedFiles.length; i += 1) {
assetHandler.addAsset('js', 'top', appGroupConfig.base +
appGroupConfig.root + seedFiles[i]);
}

} else {

// using combo for the seed files
assetHandler.addAsset('js', 'top', appGroupConfig.comboBase +
appGroupConfig.root + seedFiles.join(appGroupConfig.comboSep +
appGroupConfig.root));

}


// adding the default module for the Y.use statement in the client
initialModuleList['mojito-client'] = true;
Expand Down
60 changes: 21 additions & 39 deletions lib/app/addons/rs/url.js
Expand Up @@ -4,7 +4,7 @@
* See the accompanying LICENSE file for terms.
*/

/*jslint anon:true, sloppy:true, nomen:true, stupid:true*/
/*jslint anon:true, sloppy:true, nomen:true, stupid:true, node:true */
/*global YUI*/


Expand All @@ -18,7 +18,10 @@
*/
YUI.add('addon-rs-url', function(Y, NAME) {

var libfs = require('fs'),
'use strict';

var libfs = require('fs'),
liburl = require('url'),
libpath = require('path'),
existsSync = libfs.existsSync || libpath.existsSync,
URL_PARTS = ['frameworkName', 'appName', 'prefix'];
Expand Down Expand Up @@ -61,9 +64,6 @@ YUI.add('addon-rs-url', function(Y, NAME) {
this.config[part] = defaults[part] || '';
}
}

// FUTURE: deprecate appConfig.assumeRollups
this.assumeRollups = this.config.assumeRollups || appConfig.assumeRollups;
},


Expand Down Expand Up @@ -98,10 +98,7 @@ YUI.add('addon-rs-url', function(Y, NAME) {
}

// Server-only framework mojits like DaliProxy and HTMLFrameMojit
// should never have URLs associated with them. This never used
// to be an issue until we added the "assumeRollups" feature to
// preload JSON specs for specific mojits during the compile step
// (`mojito compile json`) for Livestand.
// should never have URLs associated with them.
if ('shared' !== mojit && 'mojito' === mojitRes.source.pkg.name) {
mojitControllerRess = store.getResourceVersions({mojit: mojit, id: 'controller--controller'});
if (mojitControllerRess.length === 1 &&
Expand All @@ -124,7 +121,6 @@ YUI.add('addon-rs-url', function(Y, NAME) {
ress = store.getResourceVersions({mojit: mojit});
for (r = 0; r < ress.length; r += 1) {
res = ress[r];

skip = false;
if ('config' === res.type) {
skip = true;
Expand Down Expand Up @@ -177,18 +173,23 @@ YUI.add('addon-rs-url', function(Y, NAME) {
_calcResourceURL: function(res, mojitRes) {
var fs = res.source.fs,
relativePath = fs.fullPath.substr(fs.rootDir.length + 1),
urlParts = [],
rollupParts = [],
rollupFsPath;
urlParts = [liburl.resolve('/', (this.config.prefix || 'static'))];

// Don't clobber a URL calculated by another RS addon.
if (res.hasOwnProperty('url')) {
// Don't clobber a URL calculated by another RS addon, or bother to
// proceed for server affinity resources that don't need uris
if (res.hasOwnProperty('url') || ('server' === res.affinity.affinity)) {
return;
}

if (this.config.prefix) {
urlParts.push(this.config.prefix);
rollupParts.push(this.config.prefix);
if (res.yui && res.yui.name) {
// any yui module in our app will have a fixed path
// that has to be really short to optimize combo
// urls as much as possible. This url will also work
// in conjuntion with "base", "comboBase" and "root"
// from application.json->yui->config
urlParts.push(res.yui.name + '.js');
res.url = urlParts.join('/');
return;
}

if ('shared' === res.mojit) {
Expand All @@ -201,42 +202,23 @@ YUI.add('addon-rs-url', function(Y, NAME) {
urlParts.push(this.config.appName);
}
}
// fw resources are also put into the app-level rollup
if (res.yui && res.yui.name) {
if (this.config.appName) {
rollupParts.push(this.config.appName);
}
rollupParts.push('rollup.client.js');
rollupFsPath = libpath.join(this.appRoot, 'rollup.client.js');
}
} else {
if ('mojit' === res.type) {
urlParts.push(res.name);
} else {
urlParts.push(res.mojit);
}
if (res.yui && res.yui.name) {
rollupParts.push(res.mojit);
rollupParts.push('rollup.client.js');
rollupFsPath = libpath.join(mojitRes.source.fs.fullPath, 'rollup.client.js');
}
}

if ('mojit' === res.type) {
if ('shared' !== res.name) {
res.url = '/' + urlParts.join('/');
res.url = urlParts.join('/');
}
return;
}

urlParts.push(relativePath);

if (rollupFsPath && (this.assumeRollups || existsSync(rollupFsPath))) {
res.url = '/' + rollupParts.join('/');
fs.rollupPath = rollupFsPath;
} else {
res.url = '/' + urlParts.join('/');
}
res.url = urlParts.join('/');
}


Expand Down

0 comments on commit 2fe0f3e

Please sign in to comment.