-
Notifications
You must be signed in to change notification settings - Fork 63
/
ImportAll.hx
29 lines (27 loc) · 915 Bytes
/
ImportAll.hx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
import haxe.io.Path;
import haxe.macro.Compiler;
import haxe.macro.Context;
import sys.FileSystem;
class ImportAll {
static function run(cp:String):Void {
Compiler.addClassPath(cp);
Compiler.allowPackage("sys");
Compiler.define("nodejs");
function loop(acc:Array<String>):Void {
var path = Path.join([cp].concat(acc));
if (FileSystem.isDirectory(path)) {
if (acc.length > 0 && acc[acc.length - 1].charCodeAt(0) == "_".code) // skip hidden packages
return;
for (file in FileSystem.readDirectory(path))
if (!~/^_/.match(file))
loop(acc.concat([file]));
} else if (Path.extension(path) == "hx") {
var moduleName = Path.withoutExtension(acc[acc.length - 1]);
var modulePath = acc.slice(0, acc.length - 1);
var typePath = if (modulePath.length == 0) moduleName else modulePath.join(".") + "." + moduleName;
Context.getType(typePath);
}
}
loop([]);
}
}