fictorial (owner)

Revisions

gist: 234093 Download_button fork
public
Public Clone URL: git://gist.github.com/234093.git
Embed All Files: show embed
JavaScript #
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
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