refactor(env): refactor env module
test / test (push) Failing after 31m39s

This commit is contained in:
2026-10-27 01:18:23 +03:00
parent cf3a707a47
commit fc7f97b520
6 changed files with 33 additions and 27 deletions
+15 -9
View File
@@ -1,19 +1,25 @@
import path from "path"; import path from "path";
export class Env { export class Env {
static set(key: string, value: string) { constructor(private target: Record<string, string | undefined>) {}
process.env[key] = value;
set(key: string, value: string) {
this.target[key] = value;
} }
static get(key: string) { get(key: string) {
return process.env[key]; return this.target[key];
} }
static addPath(value: string, key = "PATH") { addPath(value: string, key: string = "PATH") {
if (!process.env[key]) { if (!this.target[key]) {
process.env[key] = value; this.target[key] = value;
} else if (process.env[key].split(path.delimiter).indexOf(value) === -1) { } else if (this.target[key].split(path.delimiter).indexOf(value) === -1) {
process.env[key] = [process.env[key], value].join(path.delimiter); this.target[key] = [this.target[key], value].join(path.delimiter);
} }
} }
} }
export const env = new Env(process.env);
export default env;
+4 -4
View File
@@ -3,7 +3,7 @@ import os from "os";
import path from "path"; import path from "path";
import through from "through2"; import through from "through2";
import download from "../common/download"; import download from "../common/download";
import { Env } from "../common/env"; import env from "../common/env";
import exec from "../common/exec"; import exec from "../common/exec";
import { System } from "../common/system"; import { System } from "../common/system";
import { HandlerWriter } from "../common/tail"; import { HandlerWriter } from "../common/tail";
@@ -101,9 +101,9 @@ export class Android extends Sdk {
} }
activate() { activate() {
Env.set("ANDROID_HOME", this.android_home); env.set("ANDROID_HOME", this.android_home);
Env.set("ANDROID_NDK_HOME", this.ndk_home); env.set("ANDROID_NDK_HOME", this.ndk_home);
Env.set("NDK_HOME", this.ndk_home); env.set("NDK_HOME", this.ndk_home);
} }
get adbBin(): string { get adbBin(): string {
+2 -2
View File
@@ -2,7 +2,7 @@ import fs from "fs";
import fse from "fs-extra"; import fse from "fs-extra";
import os from "os"; import os from "os";
import path from "path"; import path from "path";
import { Env } from "../common/env"; import env from "../common/env";
import { System } from "../common/system"; import { System } from "../common/system";
import { watch } from "../common/watch"; import { watch } from "../common/watch";
import { Sdk } from "../core/sdk"; import { Sdk } from "../core/sdk";
@@ -31,7 +31,7 @@ export class FlashPlayer extends Sdk {
constructor(debug: boolean = false, version?: string, playerId = FlashPlayer.ID) { constructor(debug: boolean = false, version?: string, playerId = FlashPlayer.ID) {
super(playerId, version || FlashPlayer.VERSION); super(playerId, version || FlashPlayer.VERSION);
this.debug = debug; this.debug = debug;
this.baseUrl = Env.get("FLASHPLAYER_URL") || this.BASE_URL; this.baseUrl = env.get("FLASHPLAYER_URL") || this.BASE_URL;
} }
prepare() { prepare() {
+6 -6
View File
@@ -4,7 +4,7 @@ import rename from "gulp-rename";
import os from "os"; import os from "os";
import path from "path"; import path from "path";
import vfs from "vinyl-fs"; import vfs from "vinyl-fs";
import { Env } from "../common/env"; import env from "../common/env";
import exec from "../common/exec"; import exec from "../common/exec";
import { System } from "../common/system"; import { System } from "../common/system";
import template from "../common/template"; import template from "../common/template";
@@ -68,11 +68,11 @@ export class Haxe extends Sdk {
activate() { activate() {
this.neko.activate(); this.neko.activate();
Env.set("HAXE_VERSION", this.version); env.set("HAXE_VERSION", this.version);
Env.set("HAXE_STD_PATH", path.join(this.path, "std")); env.set("HAXE_STD_PATH", path.join(this.path, "std"));
Env.set("HAXE_HOME", this.path); env.set("HAXE_HOME", this.path);
Env.addPath(this.path); env.addPath(this.path);
Env.addPath(this.path, "LD_LIBRARY_PATH"); env.addPath(this.path, "LD_LIBRARY_PATH");
} }
prepare() { prepare() {
+4 -4
View File
@@ -1,7 +1,7 @@
import fs from "fs"; import fs from "fs";
import os from "os"; import os from "os";
import path from "path"; import path from "path";
import { Env } from "../common/env"; import env from "../common/env";
import { Sdk } from "../core/sdk"; import { Sdk } from "../core/sdk";
import run from "../run/index"; import run from "../run/index";
@@ -63,9 +63,9 @@ export class Neko extends Sdk {
} }
activate() { activate() {
Env.set("NEKO_INSTPATH", this.path); env.set("NEKO_INSTPATH", this.path);
Env.addPath(this.path); env.addPath(this.path);
Env.addPath(this.path, "LD_LIBRARY_PATH"); env.addPath(this.path, "LD_LIBRARY_PATH");
} }
prepare() { prepare() {
+2 -2
View File
@@ -1,6 +1,6 @@
import os from "os"; import os from "os";
import path from "path"; import path from "path";
import { Env } from "../common/env"; import env from "../common/env";
import { System } from "../common/system"; import { System } from "../common/system";
import { watch } from "../common/watch"; import { watch } from "../common/watch";
import run from "../run"; import run from "../run";
@@ -20,7 +20,7 @@ export class RufflePlayer extends FlashPlayer {
constructor(debug: boolean, version: string) { constructor(debug: boolean, version: string) {
super(debug, version || RufflePlayer.VERSION, RufflePlayer.ID); super(debug, version || RufflePlayer.VERSION, RufflePlayer.ID);
this.baseUrl = Env.get("RUFFLE_URL") || this.BASE_URL; this.baseUrl = env.get("RUFFLE_URL") || this.BASE_URL;
} }
get link(): string { get link(): string {