Files
gulp-haxetool/src/core/sdk.ts
T
2026-10-27 01:04:16 +03:00

62 lines
1.3 KiB
TypeScript
Executable File

import os from "os";
import path from "path";
import download from "../common/download";
import { Logger } from "../common/log";
export class Sdk {
static _dir: string;
static set dir(value) {
Sdk._dir = value;
}
static get dir() {
return Sdk._dir || path.join(os.homedir(), "sdk");
}
static path(name: string, version: string) {
return path.join(this.dir, name, version);
}
public name: string;
public version: string;
public log: Logger;
public path: string;
constructor(name: string, version: string) {
this.name = name;
this.log = new Logger(name);
this.version = version;
this.path = Sdk.path(name, version);
}
get intVersion() {
const vArr = this.version.split("\.").reverse();
let m = 1;
let r = 0;
for (let v of vArr) {
r += parseInt(v) * m;
m *= 10;
}
return r;
}
get prepared(): boolean {
throw "Not implemented";
}
get link(): string {
throw "Not implemented";
}
prepare(strip = 1): Promise<any> {
this.log.i("version: *%s*", this.version);
if (this.prepared) {
return Promise.resolve();
} else {
this.log.i("download: *%s*", this.link);
return download(this.link, this.path, { strip });
}
}
}