Skip to content

Instantly share code, notes, and snippets.

@back2dos
Created October 23, 2017 09:24
Show Gist options
  • Save back2dos/3b01e56c6d6f82c8620d00d9da956fe7 to your computer and use it in GitHub Desktop.
Save back2dos/3b01e56c6d6f82c8620d00d9da956fe7 to your computer and use it in GitHub Desktop.
Handwritten include all.
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