Created
May 2, 2012 20:48
-
-
Save davglass/2580376 to your computer and use it in GitHub Desktop.
Resolve module meta-data (including gallery) in Node.js with YUI's Loader
This file contains hidden or 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
#!/usr/bin/env node | |
var Y = require('yui/io-base'), | |
//API call to gallery's API | |
url = 'http://yuilibrary.com/gallery/api/all', | |
//What module should we resolve? | |
mod = process.argv[2] || 'gallery-aui-calendar', | |
//Hack up the JSON from the API into Loader Meta-Data | |
hack = function(str) { | |
var json = {}; | |
var j = JSON.parse(str); | |
Y.Object.each(j.modules, function(mod) { | |
var name = 'gallery-' + mod.module; | |
json[name] = { | |
name: name, | |
requires: mod.requires, | |
supersedes: mod.supersedes, | |
optional: mod.optional, | |
path: (mod.buildtag ? mod.buildtag + '/' : '') + name + '/' + name + '-min.js' | |
}; | |
}); | |
return json; | |
}, | |
//Resolve the module with Loader & print the results | |
resolve = function(name, mods, cb) { | |
var loader = new Y.Loader({ | |
modules: mods, | |
ignoreRegistered: true, | |
require: name | |
}); | |
//This removes conditional loading. | |
//Loader will handle this on the client side | |
loader.conditions = {}; | |
var out = loader.resolve(true); | |
var modules = []; | |
Y.Array.each(out.jsMods, function(m) { | |
modules.push(m.name); | |
}); | |
cb(modules); | |
}; | |
//Is there more than one module? | |
mod = mod.split(','); | |
//IO call to the gallery API | |
Y.io(url, { | |
on: { | |
success: function(id, e) { | |
//Hack, then resolve | |
resolve(mod, hack(e.responseText), function(modules) { | |
console.log(modules); | |
console.log('Resolved ' + modules.length + ' modules for', mod); | |
}); | |
} | |
} | |
}); | |
This file contains hidden or 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
./expand.js gallery-node-full-screen | |
[ 'yui-base', | |
'arraylist', | |
'attribute-core', | |
'base-core', | |
'oop', | |
'event-custom-base', | |
'event-custom-complex', | |
'attribute-events', | |
'attribute-extras', | |
'attribute-base', | |
'base-base', | |
'base-build', | |
'features', | |
'dom-core', | |
'dom-base', | |
'selector-native', | |
'selector', | |
'node-core', | |
'node-base', | |
'event-base', | |
'gallery-full-screen', | |
'plugin', | |
'pluginhost-base', | |
'pluginhost-config', | |
'node-pluginhost', | |
'gallery-node-full-screen' ] | |
Resolved 26 modules for [ 'gallery-node-full-screen' ] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment