refactor: rework BuildSystem and Platorm with enum
test / test (push) Failing after 5m53s

This commit is contained in:
2026-10-28 00:41:52 +03:00
parent 428f9d100e
commit 0672f2a1e0
9 changed files with 65 additions and 52 deletions
+14 -14
View File
@@ -1,15 +1,15 @@
export const BuildSystem = {
HAXE: "haxe",
OPENFL: "openfl",
ADOBE_AIR: "adobe_air",
};
export enum BuildSystem {
HAXE = "haxe",
OPENFL = "openfl",
ADOBE_AIR = "adobe_air",
}
export const Platform = {
FLASH: "flash",
HTML5: "html5",
LINUX: "linux",
WINDOWS: "windows",
ANDROID: "android",
NEKO: "neko",
CPP: "cpp",
};
export enum Platform {
FLASH = "flash",
HTML5 = "html5",
LINUX = "linux",
WINDOWS = "windows",
ANDROID = "android",
NEKO = "neko",
CPP = "cpp",
}
+22 -13
View File
@@ -10,6 +10,7 @@ import { System } from "../common/system";
import template from "../common/template";
import type { Config, LibDef } from "../core/config";
import { Sdk } from "../core/sdk";
import { Platform } from "../core/type";
import { Neko } from "./neko";
export class Haxe extends Sdk {
@@ -109,7 +110,7 @@ export class Haxe extends Sdk {
return path.join(Haxe.buildDir, config.name);
}
openfl(command: string, platform: string, config: Config, debug = false) {
openfl(command: string, platform: Platform, config: Config, debug = false) {
this.log.i("_openfl_ _build_ *%s*", platform);
this.activate();
const buildDir = this.resolveBuildDir(config);
@@ -125,35 +126,41 @@ export class Haxe extends Sdk {
const target = path.resolve(buildDir, platform, "bin");
fse.emptyDirSync(target);
const result =
(
{
android: `app/build/outputs/**/${config.meta.filename}-debug.apk`,
flash: "*.swf",
}[platform] || "**/*";
[Platform.ANDROID]: `app/build/outputs/**/${config.meta.filename}-debug.apk`,
[Platform.FLASH]: "*.swf",
} as Record<Platform, string>
)[platform] || "**/*";
return this.haxelib(args).then(() => {
let r = vfs.src(`${target}/${result}`, { encoding: false });
if (platform === "android") {
if (platform === Platform.ANDROID) {
r = r.pipe(rename(`${config.meta.filename}_${config.meta.version}.apk`));
}
return r;
});
}
build(platform: string, config: Config, debug = false) {
build(platform: Platform, config: Config, debug = false) {
this.log.i("_build_ *%s*", platform);
this.activate();
const buildDir = this.resolveBuildDir(config);
fse.ensureDirSync(buildDir);
const ext =
(
{
flash: ".swf",
neko: ".n",
}[platform] || "";
[Platform.FLASH]: ".swf",
[Platform.NEKO]: ".n",
} as Record<Platform, string>
)[platform] || "";
const out =
(
{
flash: "swf",
}[platform] || platform;
[Platform.FLASH]: "swf",
} as Record<Platform, string>
)[platform] || platform;
const project = template.render("project.hxml", {
...config,
@@ -177,9 +184,11 @@ export class Haxe extends Sdk {
fse.copySync(asset, path.join(target, asset.split("/").pop()!));
}
const result =
(
{
cpp: `${config.meta.filename}/${config.main.split(".").pop()}${debug ? "-debug" : ""}`,
}[platform] || "**/*";
[Platform.CPP]: `${config.meta.filename}/${config.main.split(".").pop()}${debug ? "-debug" : ""}`,
} as Record<Platform, string>
)[platform] || "**/*";
return this.haxe(args).then(() => {
let r = vfs.src(`${target}/${result}`, { encoding: false });
if (platform === "cpp") {
+3 -2
View File
@@ -1,4 +1,5 @@
import type { Config } from "../../core/config";
import type { BuildSystem, Platform } from "../../core/type";
import { Target } from "./target";
export class Builder extends Target {
@@ -7,7 +8,7 @@ export class Builder extends Target {
public buildSystem: string;
public debug: boolean;
constructor(config: Config, platform: string, buildSystem: string, debug: boolean = false) {
constructor(config: Config, platform: Platform, buildSystem: BuildSystem, debug: boolean = false) {
super(config, platform);
this.buildSystem = buildSystem;
this.debug = debug;
@@ -17,7 +18,7 @@ export class Builder extends Target {
Builder.factory[buildSystem] = builder;
}
static new(config: Config, platform: string, buildSystem: string, debug: boolean = false): Builder {
static new(config: Config, platform: Platform, buildSystem: BuildSystem, debug: boolean = false): Builder {
return new Builder.factory[buildSystem](config, platform, buildSystem, debug);
}
}
+5 -4
View File
@@ -1,21 +1,22 @@
import type { Config } from "../../core/config";
import type { Platform } from "../../core/type";
import { Target } from "./target";
export type PackerFactory = new (config: Config) => Packer;
export class Packer extends Target {
static factory: Record<string, Record<string, PackerFactory>> = {};
static factory: Partial<Record<Platform, Record<string, PackerFactory>>> = {};
call() {
throw "Not Implemented";
}
static register(platform: string, name: string, packer: PackerFactory) {
static register(platform: Platform, name: string, packer: PackerFactory) {
if (!Packer.factory[platform]) Packer.factory[platform] = {};
Packer.factory[platform][name] = packer;
}
static new(config: Config, platform: string, name: string): Packer {
return new Packer.factory[platform][name](config);
static new(config: Config, platform: Platform, name: string): Packer {
return new Packer.factory[platform]![name](config);
}
}
+2 -1
View File
@@ -3,6 +3,7 @@ import rename from "gulp-rename";
import output from "../../common/output";
import { tail } from "../../common/tail";
import { Config } from "../../core/config";
import type { Platform } from "../../core/type";
import { Target } from "./target";
export type RunnerFactory = new (config: Config, debug: boolean) => Runner;
@@ -12,7 +13,7 @@ export class Runner extends Target {
public debug: boolean;
constructor(config: Config, platform: string, debug: boolean) {
constructor(config: Config, platform: Platform, debug: boolean) {
super(config, platform);
this.debug = debug;
}
+4 -3
View File
@@ -1,12 +1,13 @@
import path from "path";
import type { Config } from "../../core/config";
import type { Platform } from "../../core/type";
export class Target {
public config: Config;
public platform: string;
public platform: Platform;
public target: string;
constructor(config: Config, platform: string) {
constructor(config: Config, platform: Platform) {
this.config = config;
this.platform = platform;
this.target = "target";
@@ -20,7 +21,7 @@ export class Target {
throw "Not Implemented";
}
resolveTargetPath(platform = this.platform): string {
resolveTargetPath(platform: Platform | string = this.platform): string {
return path.resolve(this.target, this.config.name, platform);
}
+1 -1
View File
@@ -11,7 +11,7 @@ export class HaxeBuilder extends Builder {
public haxe: Haxe;
public android: Android;
constructor(config: Config, platform: string, buildSystem: string, debug: boolean = false) {
constructor(config: Config, platform: Platform, buildSystem: BuildSystem, debug: boolean = false) {
super(config, platform, buildSystem, debug);
this.haxe = new Haxe();
this.android = new Android();
+7 -7
View File
@@ -15,11 +15,11 @@ export class Project {
static Platform = Platform;
static Builder = Builder;
public buildSystem: string;
public platforms: string[];
public buildSystem: BuildSystem;
public platforms: Platform[];
public config: Config;
constructor(buildSystem: string, platforms: string[] | string, config: Config) {
constructor(buildSystem: BuildSystem, platforms: Platform[] | Platform, config: Config) {
this.buildSystem = buildSystem;
this.platforms = Array.isArray(platforms) ? platforms : [platforms];
this.config = config;
@@ -34,23 +34,23 @@ export class Project {
return false;
}
build(platform: string, debug: boolean = false): Task[] {
build(platform: Platform, debug: boolean = false): Task[] {
const builder = Builder.new(this.config, platform, this.buildSystem, debug);
const tasks: Task[] = [builder.prepare.bind(builder)];
tasks.push(builder.call.bind(builder));
return tasks;
}
run(platform: string, debug: boolean = false): Task[] {
run(platform: Platform, debug: boolean = false): Task[] {
const runner = Runner.new(this.config, platform, debug);
return [runner.prepare.bind(runner), runner.call.bind(runner)];
}
test(platform: string, debug: boolean = true): Task[] {
test(platform: Platform, debug: boolean = true): Task[] {
return this.build(platform, debug).concat(this.run(platform, debug));
}
pack(platform: string, name: string) {
pack(platform: Platform, name: string) {
const packer = Packer.new(this.config, platform, name);
return [packer.prepare.bind(packer), packer.call.bind(packer)];
}
+3 -3
View File
@@ -8,7 +8,7 @@ import { System } from "../common/system";
import template from "../common/template";
import { Config, type ConfigParams, type SignKey } from "../core/config";
import { Sdk } from "../core/sdk";
import { Platform } from "../core/type";
import { BuildSystem, Platform } from "../core/type";
import { Haxe } from "../impl/haxe";
export interface PresetConfig {
@@ -24,8 +24,8 @@ export const DEFAULT_CONFIG: PresetConfig = {
};
export interface ProjectPreset {
buildSystem?: string;
platforms?: string[];
buildSystem?: BuildSystem;
platforms?: Platform[];
config: ConfigParams;
}