From 705651eddcffe444f25f19e2894f0ced95e6ef5a Mon Sep 17 00:00:00 2001 From: shmyga Date: Thu, 12 Nov 2026 20:30:05 +0300 Subject: [PATCH] refactor(task): rework setup task --- src/core/sdk.ts | 8 +++-- src/impl/android.ts | 4 ++- src/impl/flashplayer.ts | 6 ++-- src/impl/innosetup.ts | 4 +-- src/project/impl/builder/haxe.ts | 53 +++++++++++++++----------------- src/task/impl/setup.ts | 11 ++++--- 6 files changed, 43 insertions(+), 43 deletions(-) diff --git a/src/core/sdk.ts b/src/core/sdk.ts index 079e0be..1fc0641 100755 --- a/src/core/sdk.ts +++ b/src/core/sdk.ts @@ -18,7 +18,7 @@ export class Sdk { } static path(name: string, version: string) { - return path.join(this.dir, name, version); + return path.resolve(path.join(this.dir, name, version)); } public name: string; @@ -26,6 +26,8 @@ export class Sdk { public log: Logger; public path: string; + protected strip: number = 1; + constructor(name: string, version: string) { this.name = name; this.log = new Logger(name); @@ -55,14 +57,14 @@ export class Sdk { }; } - prepare(strip = 1): Promise { + prepare(): Promise { this.log.i("version: *%s*", this.version); if (this.prepared) { return Promise.resolve(); } else { const url = resolveLink(this.link, { name: this.name, version: this.version }); this.log.i("download: *%s*", url); - return download(url, this.path, { strip }); + return download(url, this.path, { strip: this.strip }); } } } diff --git a/src/impl/android.ts b/src/impl/android.ts index 4047979..45f098f 100755 --- a/src/impl/android.ts +++ b/src/impl/android.ts @@ -40,6 +40,8 @@ export class Android extends Sdk { url = "https://dl.google.com/android/repository/commandlinetools-<%= os_name %>-<%= version %>_latest.zip"; + protected strip = 0; + constructor(version?: string, ndkVersion?: string) { super(Android.ID, version || Android.VERSION); this.ndk = new AndroidNdk(ndkVersion); @@ -67,7 +69,7 @@ export class Android extends Sdk { prepare(): Promise { const result = []; - result.push(super.prepare(0)); + result.push(super.prepare()); result.push(this.ndk.prepare()); return Promise.all(result); } diff --git a/src/impl/flashplayer.ts b/src/impl/flashplayer.ts index a4fc362..3a15657 100755 --- a/src/impl/flashplayer.ts +++ b/src/impl/flashplayer.ts @@ -26,6 +26,8 @@ export class FlashPlayer extends Sdk { private debug: boolean; + protected strip = 0; + url = "https://fpdownload.macromedia.com/pub/flashplayer/updaters/" + "<%= version %>/" + @@ -36,10 +38,6 @@ export class FlashPlayer extends Sdk { this.debug = debug; } - prepare() { - return super.prepare(0); - } - get prepared() { try { return fs.existsSync(this.flashPlayerBin); diff --git a/src/impl/innosetup.ts b/src/impl/innosetup.ts index 23a5fbc..f2906e7 100755 --- a/src/impl/innosetup.ts +++ b/src/impl/innosetup.ts @@ -19,8 +19,8 @@ export class InnoSetup extends Sdk { return "http://www.jrsoftware.org/download.php/is.exe"; } - prepare(strip = 1) { - let result = super.prepare(strip); + prepare() { + let result = super.prepare(); if (!this.prepared) { result = result.then(() => { return exec(this.path, `is.exe /VERYSILENT /SUPPRESSMSGBOXES /DIR=${this.path}`); diff --git a/src/project/impl/builder/haxe.ts b/src/project/impl/builder/haxe.ts index 8dea5d3..eebfc67 100644 --- a/src/project/impl/builder/haxe.ts +++ b/src/project/impl/builder/haxe.ts @@ -1,3 +1,4 @@ +import type Stream from "stream"; import vfs from "vinyl-fs"; import exec from "../../../common/exec"; import { streamToPromise } from "../../../common/util"; @@ -16,47 +17,43 @@ export class HaxeBuilder extends Builder { this.android = new Android(); } - setup() { - let result: Promise = this.haxe.prepare().then(() => this.haxe.install(this.config.libs)); + async setup(): Promise { + await this.haxe.prepare(); + await 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", - ]), - ); + await this.android.prepare(); + this.android.activate(); + await 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(" ")); - }); + await exec(".", [answer, "|", this.haxe.haxelibBin, "run", "openfl", "setup", this.platform].join(" ")); } } - return result; } - call() { + async call(): Promise { const target = this.targetPath; + let stream: Stream; 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))); - }); + stream = await this.haxe.openfl("build", this.platform, this.config, this.debug); + if (this.platform === Platform.ANDROID && this.config.key) { + stream = stream.pipe(this.android.sign(this.config.key.store, this.config.key.pass)); + } + return streamToPromise(stream.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)))); + stream = await this.haxe.build(this.platform, this.config, this.debug); + return streamToPromise(stream.pipe(vfs.dest(target))); + default: + return super.call(); } } } diff --git a/src/task/impl/setup.ts b/src/task/impl/setup.ts index 4d7c56c..d048d1a 100644 --- a/src/task/impl/setup.ts +++ b/src/task/impl/setup.ts @@ -1,14 +1,15 @@ -import { Builder } from "../../project"; +import { Haxe } from "../../impl/haxe"; import { TaskCompilerImpl, type TaskDef } from "../core"; export class SetupTaskCompiler extends TaskCompilerImpl { *compile(): Iterable { yield [ "setup", - () => - Promise.all( - this.config.platforms.map((platform) => Builder.new(this.config, platform, this.config.buildSystem).setup()), - ), + async () => { + const haxe = new Haxe(this.config.haxe); + await haxe.prepare(); + await haxe.install(this.config.libs); + }, ]; } }