-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added simple steps system
- Loading branch information
Showing
20 changed files
with
467 additions
and
93 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,6 @@ | ||
--interp | ||
-main hxextern.Main | ||
-cp src/ | ||
-lib hscript | ||
-lib hxargs | ||
-lib minject |
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
package hxextern; | ||
|
||
import haxe.io.Path; | ||
import haxe.macro.Context; | ||
import haxe.macro.Expr; | ||
import haxe.macro.Type; | ||
import haxe.macro.TypeTools; | ||
import sys.FileSystem; | ||
|
||
using StringTools; | ||
|
||
class Macro | ||
{ | ||
private static inline var STEP_META : String = ':step'; | ||
|
||
public static macro function listSteps(injector : Expr) : Expr | ||
{ | ||
var injections = []; | ||
var modules = Macro.listTypes('hxextern.step'); | ||
for (module in modules) { | ||
var type = switch (module) { | ||
case TInst(inst, _): inst.get(); | ||
case _: null; | ||
} | ||
if (null == type) { | ||
continue; | ||
} | ||
|
||
if (type.isExtern || type.isInterface || !type.meta.has(Macro.STEP_META) || !Macro.doesImplement(type, 'hxextern.step.IStep')) { | ||
continue; | ||
} | ||
var step = switch (type.meta.extract(Macro.STEP_META)) { | ||
case [{ params: [{ expr: EConst(CString(name)) }] }]: name; | ||
case _: null; | ||
} | ||
if (null == step) { | ||
continue; | ||
} | ||
|
||
var moduleName = type.name; | ||
injections.push(macro $injector.mapClass(hxextern.step.IStep, hxextern.step.$moduleName, $v{step})); | ||
} | ||
return macro { $a{injections} }; | ||
} | ||
|
||
public static macro function listCommands(injector : Expr) : Expr | ||
{ | ||
var injections = []; | ||
var modules = Macro.listTypes('hxextern.step'); | ||
for (module in modules) { | ||
var type = switch (module) { | ||
case TInst(inst, _): inst.get(); | ||
case _: null; | ||
} | ||
if (null == type) { | ||
continue; | ||
} | ||
|
||
if (type.isExtern || type.isInterface || !Macro.doesImplement(type, 'hxextern.command.ICommand')) { | ||
continue; | ||
} | ||
|
||
var moduleName = type.name; | ||
injections.push(macro $injector.mapClass(hxextern.command.$moduleName, hxextern.command.$moduleName)); | ||
injections.push(macro $injector.mapClass(hxextern.command.ICommand, hxextern.command.$moduleName, $v{moduleName})); | ||
} | ||
return macro { $a{injections} }; | ||
} | ||
|
||
#if macro | ||
private static function listTypes(pack : String) : Array<Type> | ||
{ | ||
var types = []; | ||
for (cp in Context.getClassPath()) { | ||
var directory = Path.addTrailingSlash(cp) + pack.replace('.', '/'); | ||
if (!FileSystem.exists(directory) || !FileSystem.isDirectory(directory)) { | ||
continue; | ||
} | ||
|
||
for (file in FileSystem.readDirectory(directory)) { | ||
if (!file.endsWith('.hx')) { | ||
continue; | ||
} | ||
|
||
var moduleName = file.substr(0, -3); | ||
var module = try Context.getType('${pack}.${moduleName}') catch(e : String) null; | ||
if (null == module) { | ||
continue; | ||
} | ||
types.push(module); | ||
} | ||
} | ||
return types; | ||
} | ||
|
||
private static function doesImplement(type : ClassType, interfaceType : String) : Bool | ||
{ | ||
for (entry in type.interfaces) { | ||
if (entry.t.toString() == interfaceType || Macro.doesImplement(entry.t.get(), interfaceType)) { | ||
return true; | ||
} | ||
} | ||
|
||
return (null != type.superClass ? Macro.doesImplement(type.superClass.t.get(), interfaceType) : false); | ||
} | ||
#end | ||
} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,30 @@ | ||
package hxextern; | ||
|
||
import hxextern.service.*; | ||
import minject.Injector; | ||
|
||
class Main | ||
{ | ||
public static function main() : Void | ||
{ | ||
// Get arguments | ||
var args = Sys.args(); | ||
args.pop(); | ||
var cwd = args.pop(); | ||
|
||
// Prepare injector | ||
var injector = new Injector(); | ||
injector.mapValue(Injector, injector); | ||
injector.mapSingleton(Console); | ||
injector.mapSingleton(Haxelib); | ||
injector.mapSingleton(Process); | ||
injector.mapSingleton(Repository); | ||
Macro.listSteps(injector); | ||
|
||
// Update cwd | ||
Sys.setCwd(cwd); | ||
|
||
// Run | ||
var cli = new Cli(); | ||
var cli = injector.instantiate(Cli); | ||
cli.run(args); | ||
} | ||
} |
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
package hxextern.command; | ||
|
||
import hxextern.service.Haxelib; | ||
import hxextern.step.*; | ||
import hxextern.step.IStep; | ||
import sys.FileSystem; | ||
|
||
using StringTools; | ||
|
||
class GenerateCommand implements ICommand | ||
{ | ||
@inject | ||
public var haxelib(default, null) : Haxelib; | ||
|
||
public function new() | ||
{ | ||
/* | ||
this.path = path; | ||
this.steps = new Map(); | ||
var types : Array<Class<IStep>> = [ScriptStep, NpmStep]; | ||
for (type in types) { | ||
var instance = Type.createInstance(type, []); | ||
this.steps[instance.type] = instance; | ||
} | ||
*/ | ||
} | ||
|
||
public function run(args : Array<Dynamic>) : Void | ||
{ | ||
var path : Null<String> = args[0]; | ||
|
||
// Find haxelib file | ||
var file = (null != path ? | ||
this.haxelib.findFile(path) : | ||
this.haxelib.findFromPath(Sys.getCwd()) | ||
); | ||
|
||
// Extract datas | ||
var data = this.haxelib.extract(file); | ||
this.executeSteps(data.steps); | ||
} | ||
|
||
private function executeSteps(steps : Array<HaxelibHxExternStep>) : Void | ||
{ | ||
/* | ||
var definitions = new TypeDefinitionMap(); | ||
for (step in steps) { | ||
// Get step name | ||
var name = step.type.trim().toLowerCase(); | ||
if (!this.steps.exists(name)) { | ||
throw 'Step "${step.type}" has not been found'; | ||
} | ||
// Run step | ||
var instance = this.steps[name]; | ||
definitions = instance.run(definitions, step.options); | ||
} | ||
trace(definitions); | ||
*/ | ||
} | ||
} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,25 @@ | ||
package hxextern.command; | ||
|
||
import hxextern.service.Console; | ||
|
||
class HelpCommand implements ICommand | ||
{ | ||
private var doc : String; | ||
@inject | ||
public var console(default, null) : Console; | ||
|
||
public function new(doc : String) | ||
public function new() | ||
{ | ||
this.doc = doc; | ||
|
||
} | ||
|
||
public function run() : Void | ||
public function run(args : Array<Dynamic>) : Void | ||
{ | ||
Sys.println(this.doc); | ||
var doc : String = args[0]; | ||
|
||
this.console | ||
.info('HxExtern Manager 1.0.0') | ||
.message(' Usage: hxextern [command] <arguments>') | ||
.message(' ' + doc.split('\n').join('\n ')) | ||
; | ||
} | ||
} |
This file contains 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
Oops, something went wrong.