Created
January 23, 2012 19:03
-
-
Save justinrainbow/1664897 to your computer and use it in GitHub Desktop.
Builds a YUI Loader config for all your custom YUI3 modules
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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