Skip to content

Instantly share code, notes, and snippets.

@justinrainbow
Created January 23, 2012 19:03
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save justinrainbow/1664897 to your computer and use it in GitHub Desktop.
Save justinrainbow/1664897 to your computer and use it in GitHub Desktop.
Builds a YUI Loader config for all your custom YUI3 modules
var util = require('util'),
exec = require('child_process').exec,
modules = {},
// what to strip off the pathname (/my/dir/web becomes /web)
docroot = __dirname+'/webroot',
// where to search for YUI.add in files
path = __dirname+'/webroot/bundles',
file,
child;
global.YUI = {
add: function (name, fn, version, opts) {
opts = (opts || {});
opts.fullpath = getUrl(file);
modules[name] = opts;
}
};
function getUrl(file) {
return file.replace(docroot, '');
}
child = exec('grep -l -R "YUI.add" '+path,
function (error, stdout, stderr) {
var files = stdout.split("\n");
for (var i = 0; i < files.length; i++) {
file = files[i];
if (file.length > 0) {
require(files[i]);
}
}
console.log("var YUI_config = { \"modules\": { "+JSON.stringify(modules)+" } };");
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment