This commit is contained in:
committed by
Valentin Lemière
parent
668f59ae1c
commit
f0c605d091
20
lime/project/CLICommand.hx
Normal file
20
lime/project/CLICommand.hx
Normal file
@@ -0,0 +1,20 @@
|
||||
package lime.project;
|
||||
|
||||
|
||||
//"Command-Line Interface Command"
|
||||
class CLICommand {
|
||||
|
||||
|
||||
public var command:String;
|
||||
public var args:Array <String>;
|
||||
|
||||
|
||||
public function new (command:String, args:Array <String> = null) {
|
||||
|
||||
this.command = command;
|
||||
this.args = args != null ? args : new Array <String> ();
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -51,6 +51,8 @@ class HXProject {
|
||||
public var meta:MetaData;
|
||||
public var ndlls:Array <NDLL>;
|
||||
public var platformType:PlatformType;
|
||||
public var postBuildCallbacks:Array <CLICommand>;
|
||||
public var preBuildCallbacks:Array <CLICommand>;
|
||||
public var samplePaths:Array <String>;
|
||||
public var sources:Array <String>;
|
||||
public var splashScreens:Array <SplashScreen>;
|
||||
@@ -217,6 +219,8 @@ class HXProject {
|
||||
libraries = new Array <Library> ();
|
||||
libraryHandlers = new Map <String, String> ();
|
||||
ndlls = new Array <NDLL> ();
|
||||
postBuildCallbacks = new Array <CLICommand> ();
|
||||
preBuildCallbacks = new Array <CLICommand> ();
|
||||
sources = new Array <String> ();
|
||||
samplePaths = new Array <String> ();
|
||||
splashScreens = new Array <SplashScreen> ();
|
||||
@@ -310,6 +314,8 @@ class HXProject {
|
||||
}
|
||||
|
||||
project.platformType = platformType;
|
||||
project.postBuildCallbacks = postBuildCallbacks.copy ();
|
||||
project.preBuildCallbacks = preBuildCallbacks.copy ();
|
||||
project.samplePaths = samplePaths.copy ();
|
||||
project.sources = sources.copy ();
|
||||
|
||||
@@ -714,6 +720,8 @@ class HXProject {
|
||||
javaPaths = ArrayHelper.concatUnique (javaPaths, project.javaPaths, true);
|
||||
libraries = ArrayHelper.concatUnique (libraries, project.libraries, true);
|
||||
ndlls = ArrayHelper.concatUnique (ndlls, project.ndlls);
|
||||
postBuildCallbacks = postBuildCallbacks.concat (project.postBuildCallbacks);
|
||||
preBuildCallbacks = preBuildCallbacks.concat (project.preBuildCallbacks);
|
||||
samplePaths = ArrayHelper.concatUnique (samplePaths, project.samplePaths, true);
|
||||
sources = ArrayHelper.concatUnique (sources, project.sources, true);
|
||||
splashScreens = ArrayHelper.concatUnique (splashScreens, project.splashScreens);
|
||||
|
||||
@@ -3,6 +3,7 @@ package lime.project;
|
||||
|
||||
import haxe.rtti.Meta;
|
||||
import lime.tools.helpers.AssetHelper;
|
||||
import lime.tools.helpers.CommandHelper;
|
||||
import lime.tools.helpers.LogHelper;
|
||||
|
||||
|
||||
@@ -73,9 +74,13 @@ class PlatformTarget {
|
||||
|
||||
if (!Reflect.hasField (metaFields.build, "ignore") && (command == "build" || command == "test")) {
|
||||
|
||||
CommandHelper.executeCommands (project.preBuildCallbacks);
|
||||
|
||||
LogHelper.info ("", "\n" + LogHelper.accentColor + "Running command: BUILD" + LogHelper.resetColor);
|
||||
build ();
|
||||
|
||||
CommandHelper.executeCommands (project.postBuildCallbacks);
|
||||
|
||||
}
|
||||
|
||||
if (!Reflect.hasField (metaFields.deploy, "deploy") && (command == "deploy")) {
|
||||
|
||||
@@ -4,6 +4,7 @@ package lime.project;
|
||||
import haxe.io.Path;
|
||||
import haxe.xml.Fast;
|
||||
import lime.tools.helpers.ArrayHelper;
|
||||
import lime.tools.helpers.CommandHelper;
|
||||
import lime.tools.helpers.LogHelper;
|
||||
import lime.tools.helpers.ObjectHelper;
|
||||
import lime.tools.helpers.PathHelper;
|
||||
@@ -775,6 +776,53 @@ class ProjectXMLParser extends HXProject {
|
||||
}
|
||||
|
||||
|
||||
private function parseCommandElement (element:Fast, commandList:Array<CLICommand>):Void {
|
||||
|
||||
var command:CLICommand = null;
|
||||
|
||||
if (element.has.haxe) {
|
||||
|
||||
command = CommandHelper.interpretHaxe (substitute (element.att.haxe));
|
||||
|
||||
}
|
||||
|
||||
if (element.has.open) {
|
||||
|
||||
command = CommandHelper.openFile (substitute (element.att.open));
|
||||
|
||||
}
|
||||
|
||||
if (element.has.command) {
|
||||
|
||||
command = CommandHelper.fromSingleString (substitute (element.att.command));
|
||||
|
||||
}
|
||||
|
||||
if (element.has.cmd) {
|
||||
|
||||
command = CommandHelper.fromSingleString (substitute (element.att.cmd));
|
||||
|
||||
}
|
||||
|
||||
if (command != null) {
|
||||
|
||||
for (arg in element.elements) {
|
||||
|
||||
if (arg.name == "arg") {
|
||||
|
||||
command.args.push (arg.innerData);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
commandList.push (command);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
private function parseXML (xml:Fast, section:String, extensionPath:String = ""):Void {
|
||||
|
||||
for (element in xml.elements) {
|
||||
@@ -1678,6 +1726,14 @@ class ProjectXMLParser extends HXProject {
|
||||
|
||||
config.parse (element);
|
||||
|
||||
case "prebuild":
|
||||
|
||||
parseCommandElement (element, preBuildCallbacks);
|
||||
|
||||
case "postbuild":
|
||||
|
||||
parseCommandElement (element, postBuildCallbacks);
|
||||
|
||||
default :
|
||||
|
||||
if (StringTools.startsWith (element.name, "config:")) {
|
||||
|
||||
56
lime/tools/helpers/CommandHelper.hx
Normal file
56
lime/tools/helpers/CommandHelper.hx
Normal file
@@ -0,0 +1,56 @@
|
||||
package lime.tools.helpers;
|
||||
|
||||
|
||||
import lime.project.CLICommand;
|
||||
import lime.project.Platform;
|
||||
|
||||
|
||||
class CommandHelper {
|
||||
|
||||
|
||||
public static function executeCommands (commands:Array <CLICommand>):Void {
|
||||
|
||||
for (c in commands) {
|
||||
|
||||
Sys.command(c.command, c.args);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public static function openFile (file:String):CLICommand {
|
||||
|
||||
if (PlatformHelper.hostPlatform == Platform.WINDOWS) {
|
||||
|
||||
return new CLICommand ("start", [ file ]);
|
||||
|
||||
} else if (PlatformHelper.hostPlatform == Platform.MAC) {
|
||||
|
||||
return new CLICommand ("/usr/bin/open", [ file ]);
|
||||
|
||||
} else {
|
||||
|
||||
return new CLICommand ("/usr/bin/xdg-open", [ file ]);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
public static function interpretHaxe (mainFile:String):CLICommand {
|
||||
|
||||
return new CLICommand ("haxe", [ "-main", mainFile, "--interp" ]);
|
||||
|
||||
}
|
||||
|
||||
|
||||
public static function fromSingleString (command:String):CLICommand {
|
||||
|
||||
var args:Array<String> = command.split (" ");
|
||||
command = args.shift ();
|
||||
return new CLICommand (command, args);
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -511,6 +511,12 @@ class CommandLineTools {
|
||||
|
||||
if (project.targetHandlers.exists (Std.string (project.target))) {
|
||||
|
||||
if (command == "build" || command == "test") {
|
||||
|
||||
CommandHelper.executeCommands (project.preBuildCallbacks);
|
||||
|
||||
}
|
||||
|
||||
LogHelper.info ("", LogHelper.accentColor + "Using target platform: " + Std.string (project.target).toUpperCase () + "\x1b[0m");
|
||||
|
||||
var handler = project.targetHandlers.get (Std.string (project.target));
|
||||
@@ -551,6 +557,12 @@ class CommandLineTools {
|
||||
|
||||
} catch (e:Dynamic) {}
|
||||
|
||||
if (command == "build" || command == "test") {
|
||||
|
||||
CommandHelper.executeCommands (project.postBuildCallbacks);
|
||||
|
||||
}
|
||||
|
||||
} else {
|
||||
|
||||
var platform:PlatformTarget = null;
|
||||
|
||||
Reference in New Issue
Block a user