Write scripts in Haxe, and execute them on Windows, macOS or Linux.
// script.hx
class Script {
public function new () {
trace ("Hello from my script");
var hxml = new HXML ({ cp: ["src"], main: "Main", js: "bin/index.js" });
hxml.build ();
PlatformTools.launchWebServer ("bin");
}
}hxp looks for a script file in the current directory, or optionally, you can pass a directory or script path
cd path/with/script && hxp
hxp script.hx
hxp path/with/scriptIf you prefer to use multiple script files, HXP will prefer files which match the command name you are executing.
For example:
hxp build # prefers "build.hx"
hxp run # prefers "run.hx"class Script extends hxp.Script {
public function new () {
super ();
trace (command);
trace (commandArgs);
trace (flags.keys ());
trace (defines.keys ());
trace (options.keys ());
}
}When you extend hxp.Script, default argument parsing is included for you. Arguments which begin with a single dash (such as -debug) will be treated as a "flag", starting with -D is a "define", and starting with two dashes (such as --out-dir) is an "option". All other arguments will be considered a command (first), then command arguments.
For example:
hxp command arg1 arg2 -debug -Ddefine -Ddefine2=value --option=valueUsing HXP works on Haxe 4 (using eval internally) or Haxe 3 (using Neko).
HXP includes convenience methods for working with file paths, directories, executing child processes and creating quality CLI tools.
The Lime and OpenFL use HXP to develop cross-platform tools for delivering consistent content on Windows, macOS, Linux, iOS, Android, tvOS, Flash, HTML5 and other environments.
HXP is free, open-source software under the MIT license.
You can easily install HXP with haxelib:
haxelib install hxp
Once installed, run the following command to install the hxp command alias:
haxelib run hxp --install-hxp-alias
Log.section("Build");
if (Git.isRepository())
Log.info("Commit " + Git.getCommitHash(null, true) + " on " + Git.getBranch());
if (!System.commandExists("git"))
Log.warn("git is not installed");
var lime = Haxelib.getActivePath("lime");
var limeCommit = Haxelib.getGitCommit("lime", true);
var config = System.readJSON("config.json", {});
System.writeJSON({version: "1.0.0"}, "export/build.json");
for (png in System.listFiles("assets", true, ["png"]))
Log.info(png + " " + System.formatBytes(sys.FileSystem.stat(png).size));
System.measure("Packing", () -> System.compress("export/bin", "export/game.zip"));
Log.success("Build ready");Skip work that is already done, and run tasks on every core:
var cache = new Cache();
cache.run("textures", System.listFiles("assets/images", true, ["png"]), function()
{
System.parallel([for (png in System.listFiles("assets/images", true, ["png"])) () -> compressTexture(png)]);
});
cache.save();Scripts can read their arguments with getOption("mode", "release"), getBoolOption("fast"), defineValue("TARGET") and hasFlag("v"). System.loadEnvFile() reads a .env file, System.download() fetches a file and System.extract() unpacks a zip.
Define tasks with dependencies; tasks with inputs are skipped when those files did not change:
Tasks.cache = new Cache();
Tasks.add("assets", () -> copyAssets(), [], "Copy assets", ["assets/**/*.{png,xml,json}"]);
Tasks.add("build", () -> System.runCommand("", "haxe", ["build.hxml"]), ["assets"], "Compile");
Tasks.alias("all", ["build"]);
Tasks.runFromArgs(commandArgs, "all");Glob matches paths with *, **, ?, [...], {a,b} and ! negation, and Glob.find("source", ["*.hx"], ["export/"]) lists files. System.zipDirectory() zips a folder with patterns, System.exec() returns the exit code, stdout and stderr, and System.retry() repeats flaky steps.
On CI, CI detects GitHub Actions, GitLab, Azure and others and reads the branch, commit, tag and build number. It writes collapsible groups, error and warning annotations, step outputs, environment variables, the job summary and cache keys:
CI.group("Android", () -> buildAndroid());
CI.setOutput("version", "1.0.0");
CI.summaryTable(["Platform", "Size"], [["Android", System.formatBytes(size)]]);
CI.error("Missing texture", "assets/images/bf.png");Hmm reads hmm.json, checks installed libraries against it (Hmm.report()), installs the outdated ones, changes refs and versions and pins git libraries to their installed commit with Hmm.lock().
Create a new script with:
hxp init build.hxp
Clone the HXP repository:
git clone https://github.com/MultiSliceCrew/hxp
Tell haxelib where your development copy of HXP is installed:
haxelib dev hxp hxp
To return to release builds:
haxelib dev hxp