Created
November 13, 2009 19:34
-
-
Save fictorial/234093 to your computer and use it in GitHub Desktop.
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
GLOBAL.import_package = function(name) { | |
var package = {}; | |
require("posix").readdir(name).wait() | |
.filter(function (filename) { | |
return filename.match(/^(.+)\.js$/); | |
}) | |
.forEach(function (filename) { | |
var basename = filename.split(/^(.+)\.js$/)[1]; | |
package[basename] = require("./" + name + "/" + basename); | |
}); | |
return package; | |
}; | |
// in test/foo.js: | |
// this.bar = function () { return 42 } | |
// | |
// in runme.js: | |
// var pkg = import_package("test"); | |
// require("sys").debug(pkg.foo.bar()); | |
// | |
// $ node runme.js | |
// DEBUG: 42 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment