@dbcube/core 1.0.28 → 1.0.30
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/bin.cjs +66 -19
- package/dist/bin.cjs.map +1 -1
- package/dist/bin.js +66 -19
- package/dist/bin.js.map +1 -1
- package/dist/index.cjs +67 -22
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +67 -22
- package/dist/index.js.map +1 -1
- package/package.json +3 -1
package/dist/index.cjs
CHANGED
|
@@ -173,7 +173,11 @@ var path = __toESM(require("path"));
|
|
|
173
173
|
var os2 = __toESM(require("os"));
|
|
174
174
|
var import_follow_redirects = require("follow-redirects");
|
|
175
175
|
var unzipper = __toESM(require("unzipper"));
|
|
176
|
+
var import_ora = __toESM(require("ora"));
|
|
177
|
+
var import_chalk = __toESM(require("chalk"));
|
|
176
178
|
var Downloader = class {
|
|
179
|
+
static mainSpinner = null;
|
|
180
|
+
static currentSpinner = null;
|
|
177
181
|
static get(prefix) {
|
|
178
182
|
const arch2 = new Arquitecture();
|
|
179
183
|
const platform2 = arch2.getPlatform();
|
|
@@ -211,12 +215,16 @@ var Downloader = class {
|
|
|
211
215
|
const binaries = ["schema", "query", "sqlite"];
|
|
212
216
|
const binDir = targetDir || this.getDefaultBinDir();
|
|
213
217
|
fs.mkdirSync(binDir, { recursive: true });
|
|
214
|
-
|
|
218
|
+
this.mainSpinner = (0, import_ora.default)({
|
|
219
|
+
text: import_chalk.default.blue("Descargando binarios necesarios..."),
|
|
220
|
+
spinner: "dots12"
|
|
221
|
+
}).start();
|
|
222
|
+
for (let i = 0; i < binaries.length; i++) {
|
|
223
|
+
const prefix = binaries[i];
|
|
215
224
|
const maxRetries = 3;
|
|
216
225
|
let attempt = 0;
|
|
217
226
|
while (attempt <= maxRetries) {
|
|
218
227
|
try {
|
|
219
|
-
console.log(`\u{1F4E5} Descargando ${prefix} (intento ${attempt + 1}/${maxRetries + 1})...`);
|
|
220
228
|
const binaryInfo = this.get(prefix);
|
|
221
229
|
if (!binaryInfo.name || !binaryInfo.url) {
|
|
222
230
|
throw new Error("Plataforma o arquitectura no soportada");
|
|
@@ -224,35 +232,65 @@ var Downloader = class {
|
|
|
224
232
|
const tempZipPath = path.join(os2.tmpdir(), `dbcube-${prefix}-${Date.now()}.zip`);
|
|
225
233
|
const finalBinaryPath = path.join(binDir, binaryInfo.name);
|
|
226
234
|
if (fs.existsSync(finalBinaryPath)) {
|
|
227
|
-
|
|
235
|
+
this.updateMainProgress(prefix, i + 1, binaries.length, "exists");
|
|
228
236
|
break;
|
|
229
237
|
}
|
|
230
|
-
|
|
238
|
+
this.updateMainProgress(prefix, i + 1, binaries.length, "downloading");
|
|
239
|
+
await this.downloadFileWithProgress(binaryInfo.url, tempZipPath, prefix);
|
|
240
|
+
this.updateMainProgress(prefix, i + 1, binaries.length, "extracting");
|
|
231
241
|
await this.extractBinary(tempZipPath, finalBinaryPath, prefix);
|
|
232
|
-
|
|
242
|
+
this.updateMainProgress(prefix, i + 1, binaries.length, "completed");
|
|
233
243
|
break;
|
|
234
244
|
} catch (error) {
|
|
235
245
|
const errorMessage = error instanceof Error ? error.message : "Error desconocido";
|
|
236
246
|
if (attempt < maxRetries && (errorMessage.includes("ECONNRESET") || errorMessage.includes("timeout") || errorMessage.includes("ETIMEDOUT") || errorMessage.includes("ENOTFOUND"))) {
|
|
237
|
-
console.warn(`\u26A0\uFE0F Error de red para ${prefix}: ${errorMessage}`);
|
|
238
|
-
console.log(`\u{1F504} Reintentando en 3 segundos...`);
|
|
239
247
|
attempt++;
|
|
240
|
-
|
|
248
|
+
this.updateMainProgress(prefix, i + 1, binaries.length, "retrying", attempt);
|
|
249
|
+
await new Promise((resolve5) => setTimeout(resolve5, 2e3));
|
|
241
250
|
} else {
|
|
242
|
-
|
|
251
|
+
this.mainSpinner.fail(import_chalk.default.red(`Error descargando ${prefix}: ${errorMessage}`));
|
|
243
252
|
throw error;
|
|
244
253
|
}
|
|
245
254
|
}
|
|
246
255
|
}
|
|
247
256
|
}
|
|
248
|
-
|
|
249
|
-
|
|
257
|
+
this.mainSpinner.succeed(import_chalk.default.green("Binarios descargados correctamente"));
|
|
258
|
+
}
|
|
259
|
+
static updateMainProgress(binary, current, total, status, attempt) {
|
|
260
|
+
const progressBar = this.createProgressBar(current, total);
|
|
261
|
+
const statusEmojis = {
|
|
262
|
+
downloading: "\u{1F4E5}",
|
|
263
|
+
extracting: "\u{1F4E6}",
|
|
264
|
+
completed: "\u2705",
|
|
265
|
+
exists: "\u2705",
|
|
266
|
+
retrying: "\u{1F504}"
|
|
267
|
+
};
|
|
268
|
+
const statusMessages = {
|
|
269
|
+
downloading: import_chalk.default.blue("descargando"),
|
|
270
|
+
extracting: import_chalk.default.yellow("extrayendo"),
|
|
271
|
+
completed: import_chalk.default.green("completado"),
|
|
272
|
+
exists: import_chalk.default.gray("existe"),
|
|
273
|
+
retrying: import_chalk.default.orange(`reintentando (${attempt}/${3})`)
|
|
274
|
+
};
|
|
275
|
+
const emoji = statusEmojis[status] || "\u{1F4E5}";
|
|
276
|
+
const message = statusMessages[status] || status;
|
|
277
|
+
this.mainSpinner.text = `${progressBar} ${emoji} ${import_chalk.default.bold(binary)} - ${message}`;
|
|
278
|
+
}
|
|
279
|
+
static createProgressBar(current, total, width = 20) {
|
|
280
|
+
const filled = Math.round(current / total * width);
|
|
281
|
+
const empty = width - filled;
|
|
282
|
+
const filledBar = import_chalk.default.green("\u2588".repeat(filled));
|
|
283
|
+
const emptyBar = import_chalk.default.gray("\u2591".repeat(empty));
|
|
284
|
+
const percentage = import_chalk.default.bold(`${current}/${total}`);
|
|
285
|
+
return `[${filledBar}${emptyBar}] ${percentage}`;
|
|
286
|
+
}
|
|
287
|
+
static downloadFileWithProgress(url, outputPath, prefix) {
|
|
250
288
|
return new Promise((resolve5, reject) => {
|
|
251
289
|
const request = import_follow_redirects.https.get(url, { timeout: 6e4 }, (response) => {
|
|
252
290
|
if (response.statusCode === 302 || response.statusCode === 301) {
|
|
253
291
|
const redirectUrl = response.headers.location;
|
|
254
292
|
if (redirectUrl) {
|
|
255
|
-
return this.
|
|
293
|
+
return this.downloadFileWithProgress(redirectUrl, outputPath, prefix).then(resolve5).catch(reject);
|
|
256
294
|
}
|
|
257
295
|
}
|
|
258
296
|
if (response.statusCode !== 200) {
|
|
@@ -262,21 +300,20 @@ var Downloader = class {
|
|
|
262
300
|
const file = fs.createWriteStream(outputPath);
|
|
263
301
|
const totalBytes = parseInt(response.headers["content-length"] || "0", 10);
|
|
264
302
|
let downloadedBytes = 0;
|
|
265
|
-
if (totalBytes > 0) {
|
|
266
|
-
console.log(`\u{1F4E6} Descargando ${(totalBytes / 1024 / 1024).toFixed(1)}MB...`);
|
|
267
|
-
}
|
|
268
303
|
response.on("data", (chunk) => {
|
|
269
304
|
downloadedBytes += chunk.length;
|
|
270
305
|
file.write(chunk);
|
|
271
306
|
if (totalBytes > 0) {
|
|
272
|
-
const progress =
|
|
273
|
-
|
|
307
|
+
const progress = {
|
|
308
|
+
downloaded: downloadedBytes,
|
|
309
|
+
total: totalBytes,
|
|
310
|
+
percentage: downloadedBytes / totalBytes * 100
|
|
311
|
+
};
|
|
312
|
+
this.updateDownloadProgress(prefix, progress);
|
|
274
313
|
}
|
|
275
314
|
});
|
|
276
315
|
response.on("end", () => {
|
|
277
316
|
file.end();
|
|
278
|
-
console.log(`
|
|
279
|
-
\u2705 Descarga de ${prefix} completada`);
|
|
280
317
|
resolve5();
|
|
281
318
|
});
|
|
282
319
|
response.on("error", (err) => {
|
|
@@ -297,6 +334,17 @@ var Downloader = class {
|
|
|
297
334
|
});
|
|
298
335
|
});
|
|
299
336
|
}
|
|
337
|
+
static updateDownloadProgress(binary, progress) {
|
|
338
|
+
const percentage = progress.percentage.toFixed(1);
|
|
339
|
+
const downloaded = (progress.downloaded / 1024 / 1024).toFixed(1);
|
|
340
|
+
const total = (progress.total / 1024 / 1024).toFixed(1);
|
|
341
|
+
const barWidth = 15;
|
|
342
|
+
const filled = Math.round(progress.percentage / 100 * barWidth);
|
|
343
|
+
const empty = barWidth - filled;
|
|
344
|
+
const progressBar = import_chalk.default.green("\u2588".repeat(filled)) + import_chalk.default.gray("\u2591".repeat(empty));
|
|
345
|
+
const progressText = `[${progressBar}] ${percentage}% (${downloaded}/${total}MB)`;
|
|
346
|
+
this.mainSpinner.text = `\u{1F4E5} ${import_chalk.default.bold(binary)} - ${progressText}`;
|
|
347
|
+
}
|
|
300
348
|
static extractBinary(zipPath, outputPath, prefix) {
|
|
301
349
|
return new Promise((resolve5, reject) => {
|
|
302
350
|
let extracted = false;
|
|
@@ -310,7 +358,6 @@ var Downloader = class {
|
|
|
310
358
|
fs.chmodSync(outputPath, 493);
|
|
311
359
|
}
|
|
312
360
|
this.cleanupFile(zipPath);
|
|
313
|
-
console.log(`\u{1F4C1} ${prefix} extra\xEDdo correctamente`);
|
|
314
361
|
resolve5();
|
|
315
362
|
});
|
|
316
363
|
writeStream.on("error", (err) => {
|
|
@@ -398,11 +445,9 @@ var Binary = class {
|
|
|
398
445
|
}
|
|
399
446
|
}
|
|
400
447
|
static async downloadBinaries() {
|
|
401
|
-
console.log("\u{1F680} DBCube: Descargando binarios necesarios...");
|
|
402
448
|
try {
|
|
403
449
|
const binDir = this.getBinDir();
|
|
404
450
|
await Downloader.download(binDir);
|
|
405
|
-
console.log("\u2705 DBCube: Binarios descargados correctamente");
|
|
406
451
|
} catch (error) {
|
|
407
452
|
console.warn("\u26A0\uFE0F DBCube: Error descargando binarios:", error.message);
|
|
408
453
|
console.log("\u{1F527} Los binarios se intentar\xE1n descargar en la pr\xF3xima ejecuci\xF3n");
|