Skip to content

Commit

Permalink
add hxp add hxformat.json
Browse files Browse the repository at this point in the history
  • Loading branch information
Geokureli committed Mar 7, 2024
1 parent 61b09c4 commit 4899a48
Show file tree
Hide file tree
Showing 5 changed files with 121 additions and 60 deletions.
16 changes: 11 additions & 5 deletions Build.hx
Original file line number Diff line number Diff line change
@@ -1,17 +1,23 @@
import haxe.macro.Compiler;
import sys.io.File;

function main() {
function main()
{
trace("Running: ncc build build/haxe-output.js -o build");
Sys.command("ncc build build/haxe-output.js -o build");

final path = "build/index.js";
final file = File.getContent(path);
if (file == null) {
if (file == null)
{
trace('No file named index.js found, creation unsuccesful');
} else if (file.indexOf('// Generated by Haxe') == 0) {
}
else if (file.indexOf('// Generated by Haxe') == 0)
{
trace('File index.js was not updated');
} else {
}
else
{
trace('index.js created or updated, successfully');
final haxe = Compiler.getDefine("haxe");
File.saveContent(path, '// Generated by Haxe $haxe\n' + file);
Expand Down
50 changes: 29 additions & 21 deletions build/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 18 additions & 0 deletions hxformat.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"lineEnds": {
"leftCurly": "both",
"rightCurly": "both",
"objectLiteralCurly": {
"leftCurly": "after"
}
},
"sameLine": {
"ifElse": "next",
"doWhile": "next",
"tryBody": "next",
"tryCatch": "next"
},
"indentation":{
"trailingWhitespace": true
}
}
27 changes: 18 additions & 9 deletions src/Haxelib.hx
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
import Command.ExitCode;
import Main.LibVersion;

function run(args:Array<String>):ExitCode {
function run(args:Array<String>):ExitCode
{
return Command.run("haxelib", ["run"].concat(args));
}

function fromVersion(defaultUser:String, lib:String, version:LibVersion):ExitCode {
return switch (version) {
function fromVersion(defaultUser:String, lib:String, version:LibVersion):ExitCode
{
return switch (version)
{
case Dev:
Haxelib.git(defaultUser, lib);
case Release | "" | null:
Expand All @@ -16,25 +19,31 @@ function fromVersion(defaultUser:String, lib:String, version:LibVersion):ExitCod
}
}

function install(lib:String, ?version:String):ExitCode {
function install(lib:String, ?version:String):ExitCode
{
final args = ["install", lib];
if (version != null) {
if (version != null)
{
args.push(version);
}
args.push("--quiet");
args.push("--global");
return Command.run("haxelib", args);
}

function git(user:String, haxelib:String, ?githubLib:String, ?branch:String, ?path:String):ExitCode {
if (githubLib == null) {
function git(user:String, haxelib:String, ?githubLib:String, ?branch:String, ?path:String):ExitCode
{
if (githubLib == null)
{
githubLib = haxelib;
}
final args = ["git", haxelib, 'https://github.com/$user/$githubLib'];
if (branch != null) {
if (branch != null)
{
args.push(branch);
}
if (path != null) {
if (path != null)
{
args.push(path);
}
args.push("--quiet");
Expand Down
70 changes: 45 additions & 25 deletions src/Main.hx
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,20 @@ import sys.io.File;

using StringTools;

enum abstract LibVersion(String) from String {
enum abstract LibVersion(String) from String
{
final Dev = "dev";
final Release = "release";
}

enum abstract TestLocation(String) from String {
enum abstract TestLocation(String) from String
{
final Local = "local";
final Git = "git";
}

enum abstract HaxeVersion(String) from String to String {
enum abstract HaxeVersion(String) from String to String
{
final Latest = "latest";
final Stable = "stable";
final Nightly = "nightly";
Expand All @@ -27,21 +30,24 @@ enum abstract HaxeVersion(String) from String to String {

private final HaxelibRepo = Path.join([Sys.getEnv("HOME"), "haxe/haxelib"]);

function main() {
function main()
{
final haxeVersion:HaxeVersion = Core.getInput("haxe-version");
final limeVersion:LibVersion = Core.getInput("lime-version");
final openflVersion:LibVersion = Core.getInput("openfl-version");
final flixelVersions:LibVersion = Core.getInput("flixel-versions");
final testLocation:TestLocation = Core.getInput("test-location");
final target:Target = Core.getInput("target");
final runTests:Bool = Core.getInput("run-tests") == "true";

if (runTests) {
if (target == Hl && haxeVersion.startsWith("3")) {

if (runTests)
{
if (target == Hl && haxeVersion.startsWith("3"))
{
return; // OpenFL's HL target and Haxe 3 don't work together
}
}

Core.startGroup("Installing Haxe Dependencies");
final installationResult = runUntilFailure([
setupLix.bind(haxeVersion),
Expand All @@ -53,12 +59,13 @@ function main() {
installHaxelibs.bind(limeVersion, openflVersion, flixelVersions),
installHxcpp.bind(target)
]);
if (installationResult != Success) {
if (installationResult != Success)
{
Sys.exit(Failure);
}
Core.exportVariable("HAXELIB_REPO", HaxelibRepo);
Core.endGroup();

Core.startGroup("Listing Dependencies");
if (haxeVersion != Current)
run("lix -v");
Expand All @@ -69,40 +76,44 @@ function main() {
run("haxelib fixrepo");
run("haxelib list");
Core.endGroup();

if (runTests) {

if (runTests)
{
Core.startGroup("Test Preparation");

if (testLocation == Local)
// When testing changes to flixel, flixel is set to the dev version
cd("tests");
else
// otherwise use git version
cd(Path.join([HaxelibRepo, "flixel/git/tests"]));

putEnv("HXCPP_SILENT", "1");
putEnv("HXCPP_COMPILE_CACHE", Sys.getEnv("HOME") + "/hxcpp_cache");
putEnv("HXCPP_CACHE_MB", "5000");
Core.endGroup();

Sys.exit(runAllNamed(Tests.make(target)));
}
}

private function setupLix(haxeVersion):ExitCode {
private function setupLix(haxeVersion):ExitCode
{
if (haxeVersion == Current)
return Success;

Sys.command("lix scope");
final path = Path.join([Sys.getEnv("HOME"), "haxe/.haxerc"]);
if (!FileSystem.exists(path)) {
if (!FileSystem.exists(path))
{
return Failure;
}
File.saveContent(path, '{"version": "stable", "resolveLibs": "haxelib"}');
return run('lix install haxe $haxeVersion --global');
}

private function installHaxelibs(limeVersion:LibVersion, openflVersion:LibVersion, flixelVersions:LibVersion):ExitCode {
private function installHaxelibs(limeVersion:LibVersion, openflVersion:LibVersion, flixelVersions:LibVersion):ExitCode
{
final libs = [
// TODO: fix git version failing on nightly
// Haxelib.git.bind("massive-oss", "munit", "MassiveUnit", "master", "src"),
Expand All @@ -114,27 +125,36 @@ private function installHaxelibs(limeVersion:LibVersion, openflVersion:LibVersio
Haxelib.install.bind("nape-haxe4"),
Haxelib.install.bind("haxeui-core"),
Haxelib.install.bind("haxeui-flixel"),
Haxelib.install.bind("format"), // needed for git lime

Haxelib.git.bind("HaxeFoundation", "hscript"),
Haxelib.git.bind("larsiusprime", "firetongue"),
Haxelib.git.bind("Geokureli", "spinehaxe", "spinehaxe", "haxe4.3.1"),
Haxelib.git.bind("larsiusprime", "steamwrap"),

Haxelib.fromVersion.bind("openfl", "lime", limeVersion),
Haxelib.fromVersion.bind("openfl", "openfl", openflVersion),

Haxelib.fromVersion.bind("HaxeFlixel", "flixel", flixelVersions),
Haxelib.fromVersion.bind("HaxeFlixel", "flixel-tools", flixelVersions),
Haxelib.fromVersion.bind("HaxeFlixel", "flixel-templates", flixelVersions),
Haxelib.fromVersion.bind("HaxeFlixel", "flixel-demos", flixelVersions),
Haxelib.fromVersion.bind("HaxeFlixel", "flixel-addons", flixelVersions),
Haxelib.fromVersion.bind("HaxeFlixel", "flixel-ui", flixelVersions),
Haxelib.fromVersion.bind("HaxeFlixel", "flixel-ui", flixelVersions)
];

if (limeVersion == Dev)
{
// needed for git lime
libs.push(Haxelib.install.bind("format"));
libs.push(Haxelib.install.bind("hxp"));
}
return runUntilFailure(libs);
}

private function installHxcpp(target:Target):ExitCode {
if (target != Cpp) {
private function installHxcpp(target:Target):ExitCode
{
if (target != Cpp)
{
return Success;
}
final hxcppDir = Path.join([HaxelibRepo, "hxcpp/git/"]);
Expand Down

0 comments on commit 4899a48

Please sign in to comment.