import os from "os"; import path from "path"; import download from "../common/download"; import { Logger } from "../common/log"; import { resolveLink, type Link } from "./link"; export class Sdk { static _dir: string; url!: 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 | Link { return { version: this.version, url: this.url, }; } prepare(strip = 1): Promise { this.log.i("version: *%s*", this.version); if (this.prepared) { return Promise.resolve(); } else { this.log.i("download: *%s*", this.link); return download(resolveLink(this.link, this), this.path, { strip }); } } }