Created
October 23, 2017 09:24
-
-
Save back2dos/3b01e56c6d6f82c8620d00d9da956fe7 to your computer and use it in GitHub Desktop.
Handwritten include all.
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
package ; | |
import haxe.macro.Context; | |
using sys.FileSystem; | |
using StringTools; | |
@:forward | |
abstract Entry(haxe.io.Path) { | |
public inline function new(s) | |
this = new haxe.io.Path(s); | |
public inline function isDirectory() | |
return this.toString().isDirectory(); | |
} | |
class Include { | |
static public function modules(path:String, ?rec:Bool = true) { | |
function ls(dir:String) | |
return [for (file in dir.readDirectory()) new Entry('$dir/$file')]; | |
var dir = path.replace('.', '/'); | |
var paths = []; | |
for (cp in Context.getClassPath()) | |
for (entry in ls('$cp/$dir')) { | |
var sub = '$path.${entry.file}'; | |
if (rec && entry.isDirectory()) | |
modules(sub) | |
else if (entry.ext == 'hx' && entry.file != 'import') | |
paths.push(sub); | |
//Context.getModule(sub); | |
} | |
var pos = (macro _).pos; | |
Context.defineModule(Std.string(Date.now().getTime()), [], [for (p in paths) { | |
mode: INormal, | |
path: [for (name in p.split('.')) { pos: pos, name: name }], | |
}]); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment