@dbcube/core
Version:
309 lines (306 loc) • 10.2 kB
JavaScript
;
var __create = Object.create;
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __getProtoOf = Object.getPrototypeOf;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __copyProps = (to, from, except, desc) => {
if (from && typeof from === "object" || typeof from === "function") {
for (let key of __getOwnPropNames(from))
if (!__hasOwnProp.call(to, key) && key !== except)
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
}
return to;
};
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
// If the importer is in node compatibility mode or this is not an ESM
// file that has been converted to a CommonJS file using a Babel-
// compatible transform (i.e. "__esModule" has not been set), then set
// "default" to the CommonJS "module.exports" for node compatibility.
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
mod
));
// src/lib/Arquitecture.ts
var os = __toESM(require("os"));
var Arquitecture = class {
systemInfo;
constructor() {
this.systemInfo = this.detectSystemInfo();
}
/**
* Detecta información completa del sistema
*/
detectSystemInfo() {
return {
platform: os.platform(),
arch: os.arch(),
release: os.release(),
type: os.type(),
endianness: os.endianness(),
cpus: os.cpus().length
};
}
/**
* Obtiene la plataforma normalizada
*/
getPlatform() {
const platform2 = this.systemInfo.platform;
switch (platform2) {
case "win32":
return "windows";
case "darwin":
return "macos";
case "linux":
return "linux";
case "freebsd":
return "freebsd";
case "openbsd":
return "openbsd";
case "sunos":
return "solaris";
default:
return platform2;
}
}
/**
* Obtiene la arquitectura normalizada
*/
getArchitecture() {
const arch2 = this.systemInfo.arch;
switch (arch2) {
case "x64":
return "x86_64";
case "x32":
case "ia32":
return "i686";
case "arm64":
return "aarch64";
case "arm":
return "armv7";
case "ppc64":
return "powerpc64";
case "ppc":
return "powerpc";
case "s390x":
return "s390x";
case "mips":
return "mips";
case "mipsel":
return "mipsel";
default:
return arch2;
}
}
/**
* Genera el nombre del binario basado en la arquitectura
*/
getBinaryName(baseName) {
const platform2 = this.getPlatform();
const arch2 = this.getArchitecture();
const extension = platform2 === "windows" ? ".exe" : "";
return `${baseName}-${platform2}-${arch2}${extension}`;
}
/**
* Obtiene información completa del sistema
*/
getSystemInfo() {
return { ...this.systemInfo };
}
/**
* Obtiene el triple de destino (target triple) para Rust
*/
getRustTargetTriple() {
const platform2 = this.getPlatform();
const arch2 = this.getArchitecture();
const targetMap = {
"linux-x86_64": "x86_64-unknown-linux-gnu",
"linux-i686": "i686-unknown-linux-gnu",
"linux-aarch64": "aarch64-unknown-linux-gnu",
"linux-armv7": "armv7-unknown-linux-gnueabihf",
"macos-x86_64": "x86_64-apple-darwin",
"macos-aarch64": "aarch64-apple-darwin",
"windows-x86_64": "x86_64-pc-windows-msvc",
"windows-i686": "i686-pc-windows-msvc",
"windows-aarch64": "aarch64-pc-windows-msvc",
"freebsd-x86_64": "x86_64-unknown-freebsd"
};
const key = `${platform2}-${arch2}`;
return targetMap[key] || `${arch2}-unknown-${platform2}`;
}
/**
* Muestra información detallada del sistema
*/
printSystemInfo() {
console.log("\u{1F5A5}\uFE0F System Information:");
console.log("\u251C\u2500 Platform:", this.getPlatform());
console.log("\u251C\u2500 Arquitecture:", this.getArchitecture());
console.log("\u251C\u2500 OS Type:", this.systemInfo.type);
console.log("\u251C\u2500 OS Release:", this.systemInfo.release);
console.log("\u251C\u2500 Endianness:", this.systemInfo.endianness);
console.log("\u251C\u2500 CPUs:", this.systemInfo.cpus);
console.log("\u2514\u2500 Rust Target:", this.getRustTargetTriple());
}
};
// src/lib/Donwloader.ts
var fs = __toESM(require("fs"));
var path = __toESM(require("path"));
var os2 = __toESM(require("os"));
var import_follow_redirects = require("follow-redirects");
var unzipper = __toESM(require("unzipper"));
var Downloader = class {
static get(prefix) {
const arch2 = new Arquitecture();
const platform2 = arch2.getPlatform();
const architecture = arch2.getArchitecture();
const platformMap = {
windows: "windows",
linux: "linux",
darwin: "macos"
};
const archMap = {
x86_64: "x64",
arm64: "arm64"
};
const plat = platformMap[platform2];
const archSuffix = archMap[architecture];
if (plat && archSuffix) {
const baseName = `${prefix}-engine-${plat}-${archSuffix}`;
const binaryName = platform2 === "windows" ? `${baseName}.exe` : baseName;
const url = `https://github.com/Dbcube/binaries/releases/download/${prefix}-engine/${prefix}-engine-latest-${plat}-${archSuffix}.zip`;
return {
name: binaryName,
url,
query_engine: binaryName,
schema_engine: `${prefix}-engine-${plat}-${archSuffix}${platform2 === "windows" ? ".exe" : ""}`
};
}
return {
name: "",
url: "",
query_engine: "",
schema_engine: ""
};
}
static async download() {
const binaries = ["schema", "query"];
const binDir = path.resolve(__dirname, "..", "bin");
fs.mkdirSync(binDir, { recursive: true });
for (const prefix of binaries) {
try {
console.log(`==> Empezando descarga para: ${prefix}`);
const binaryInfo = this.get(prefix);
console.log(`Descargando: ${binaryInfo.name}`);
console.log(`URL: ${binaryInfo.url}`);
if (!binaryInfo.name) {
throw new Error("Unsupported platform or architecture");
}
const tempZipPath = path.join(os2.tmpdir(), `binary-${prefix}-${Date.now()}.zip`);
const finalBinaryPath = path.join(binDir, binaryInfo.name);
if (fs.existsSync(finalBinaryPath)) {
console.log(`\u26A0\uFE0F El binario ya existe, omitiendo: ${finalBinaryPath}`);
continue;
}
await new Promise((resolve2, reject) => {
const file = fs.createWriteStream(tempZipPath);
import_follow_redirects.https.get(binaryInfo.url, (response) => {
console.log(`Respuesta HTTP para ${prefix}: ${response.statusCode}`);
if (response.statusCode !== 200) {
file.close();
try {
fs.unlinkSync(tempZipPath);
} catch {
}
reject(new Error(`Failed to download file: ${response.statusCode}`));
return;
}
response.pipe(file);
file.on("finish", () => {
file.close();
resolve2();
});
file.on("error", (err) => {
file.close();
try {
fs.unlinkSync(tempZipPath);
} catch {
}
reject(err);
});
}).on("error", (err) => {
file.close();
try {
fs.unlinkSync(tempZipPath);
} catch {
}
reject(err);
});
});
console.log(`Zip descargado para ${prefix}, extrayendo...`);
await new Promise((resolve2, reject) => {
let extracted = false;
fs.createReadStream(tempZipPath).pipe(unzipper.Parse()).on("entry", (entry) => {
const fileName = entry.path;
const type2 = entry.type;
console.log(`Encontrado en ZIP: ${fileName} (${type2})`);
if (type2 === "File" && !extracted) {
extracted = true;
const writeStream = fs.createWriteStream(finalBinaryPath);
entry.pipe(writeStream);
writeStream.on("finish", () => {
if (process.platform !== "win32") {
fs.chmodSync(finalBinaryPath, 493);
}
try {
fs.unlinkSync(tempZipPath);
} catch {
}
console.log(`Binario extra\xEDdo y guardado: ${finalBinaryPath}`);
resolve2();
});
writeStream.on("error", (err) => {
try {
fs.unlinkSync(tempZipPath);
} catch {
}
reject(err);
});
} else {
entry.autodrain();
}
}).on("error", (err) => {
try {
fs.unlinkSync(tempZipPath);
} catch {
}
reject(err);
}).on("close", () => {
if (!extracted) {
try {
fs.unlinkSync(tempZipPath);
} catch {
}
reject(new Error(`No se encontr\xF3 ning\xFAn archivo v\xE1lido en el ZIP para ${prefix}`));
}
});
});
console.log(`==> Finaliz\xF3 descarga y extracci\xF3n para: ${prefix}`);
} catch (error) {
const errorMessage = error instanceof Error ? error.message : "Error desconocido";
console.error(`Error descargando binario ${prefix}:`, errorMessage);
throw error;
}
}
}
};
// src/install.ts
(async () => {
const binaries = ["schema", "query"];
for (const prefix of binaries) {
const binary = Downloader.get(prefix);
console.log("Descargando:", binary.name);
console.log("URL:", binary.url);
}
await Downloader.download();
})();
//# sourceMappingURL=install.cjs.map