This repository has been archived by the owner on Dec 13, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 5
/
ImportAll.hx
44 lines (37 loc) · 1.45 KB
/
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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
import sys.FileSystem;
import haxe.macro.Context;
/** Macro to import all modules, in order to generate documentation for them. */
class ImportAll {
static var whitelist = ["kong"];
public static function run() {
for (path in Context.getClassPath()) {
if (path == "") {
path = ".";
}
importDirectory(path);
}
}
static function importDirectory(path:String, packageName:String="") {
path = ~/\/*$/.replace(path, "");
for (fileName in FileSystem.readDirectory(path)) {
if (StringTools.startsWith(fileName, ".")) {
continue;
}
var filePath = path + "/" + fileName;
if (FileSystem.isDirectory(filePath)) {
var filePackageName = if (packageName == "") fileName else packageName + "." + fileName;
importDirectory(path + "/" + fileName, filePackageName);
} else if (StringTools.endsWith(fileName, ".hx")) {
var moduleName = fileName.substr(0, fileName.length - 3);
if (packageName != "") {
moduleName = packageName + "." + moduleName;
}
if (Lambda.exists(whitelist, function(whitelistItem) {
return StringTools.startsWith(moduleName, whitelistItem + ".");
})) {
Context.getModule(moduleName);
}
}
}
}
}