import vfs from "vinyl-fs"; import exec from "../../../common/exec"; import { streamToPromise } from "../../../common/util"; import { BuildSystem, type Config, Platform } from "../../../core/type"; import { Android } from "../../../impl/android"; import { Haxe } from "../../../impl/haxe"; import { Builder } from "../../core/builder"; export class HaxeBuilder extends Builder { public haxe: Haxe; public android: Android; constructor(config: Config, platform: Platform, buildSystem: BuildSystem, debug: boolean = false) { super(config, platform, buildSystem, debug); this.haxe = new Haxe(config.haxe ? config.haxe : undefined); this.android = new Android(); } setup() { let result: Promise = this.haxe.prepare().then(() => this.haxe.install(this.config.libs)); if (this.buildSystem === BuildSystem.OPENFL) { if (this.platform === Platform.ANDROID) { result = result .then(() => this.android.prepare()) .then(() => this.android.activate()) .then(() => this.android.sdkmanager([ // TODO: android sdk dependencies config? "platform-tools", "build-tools;27.0.3", "platforms;android-28", "cmake;3.6.4111459", ]), ); const AndroidSDK = this.android.android_home; const AndroidNDK = this.android.ndk_home; const answer = `echo "${[AndroidSDK, AndroidNDK].join("\n")}"`; result = result.then(() => { return exec(".", [answer, "|", this.haxe.haxelibBin, "run", "openfl", "setup", this.platform].join(" ")); }); } } return result; } call() { const target = this.targetPath; switch (this.buildSystem) { case BuildSystem.OPENFL: return this.haxe.openfl("build", this.platform, this.config, this.debug).then((result) => { if (this.platform === Platform.ANDROID && this.config.key) { result = result.pipe(this.android.sign(this.config.key.store, this.config.key.pass)); } return streamToPromise(result.pipe(vfs.dest(target))); }); case BuildSystem.HAXE: return this.haxe .build(this.platform, this.config, this.debug) .then((result) => streamToPromise(result.pipe(vfs.dest(target)))); } } } Builder.register(BuildSystem.HAXE, HaxeBuilder); Builder.register(BuildSystem.OPENFL, HaxeBuilder);