refactor: rewrite on typescript

This commit is contained in:
2026-10-13 21:11:57 +03:00
parent be54ce5d25
commit f735be8bf9
40 changed files with 2333 additions and 2175 deletions
+91
View File
@@ -0,0 +1,91 @@
import fs from "fs";
import os from "os";
import path from "path";
import { Env } from "../common/env";
import { Sdk } from "../core/sdk";
import run from "../run/index";
export class NekoLink {
static get type() {
switch (os.type()) {
case "Linux":
return "linux";
case "Windows_NT":
return "win";
}
}
static get arch() {
switch (os.arch()) {
case "ia32":
return "";
case "x64":
return "64";
}
}
static get ext() {
switch (os.type()) {
case "Linux":
return "tar.gz";
case "Windows_NT":
return "zip";
}
}
static get(version: string) {
const vv = version.split("\.").join("-");
const filename = `neko-${version}-${NekoLink.type}${NekoLink.arch}.${NekoLink.ext}`;
return `https://github.com/HaxeFoundation/neko/releases/download/v${vv}/${filename}`;
}
}
export class Neko extends Sdk {
static ID = "neko";
static VERSION_2_2_0 = "2.2.0";
static VERSION = Neko.VERSION_2_2_0;
constructor(version?: string) {
super(Neko.ID, version || Neko.VERSION);
}
get link() {
return NekoLink.get(this.version);
}
get prepared() {
try {
return fs.existsSync(this.nekoBin);
} catch (e) {
return false;
}
}
activate() {
Env.set("NEKO_INSTPATH", this.path);
Env.addPath(this.path);
Env.addPath(this.path, "LD_LIBRARY_PATH");
}
prepare() {
return Promise.all([super.prepare()]).then(() => {
fs.copyFileSync(
path.resolve(import.meta.dirname, "..", "template/neko/activate"),
path.resolve(this.path, "activate"),
);
});
}
get nekoBin() {
let binname = "neko";
if (os.type() === "Windows_NT") binname += ".exe";
return path.join(this.path, binname);
}
run(filename: string, params: any) {
this.log.i("_run_ *%s*", filename);
this.activate();
return run(`${this.nekoBin} ${filename}`, params).exec();
}
}