@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.js
CHANGED
|
@@ -136,7 +136,11 @@ import * as path from "path";
|
|
|
136
136
|
import * as os2 from "os";
|
|
137
137
|
import { https } from "follow-redirects";
|
|
138
138
|
import * as unzipper from "unzipper";
|
|
139
|
+
import ora from "ora";
|
|
140
|
+
import chalk from "chalk";
|
|
139
141
|
var Downloader = class {
|
|
142
|
+
static mainSpinner = null;
|
|
143
|
+
static currentSpinner = null;
|
|
140
144
|
static get(prefix) {
|
|
141
145
|
const arch2 = new Arquitecture();
|
|
142
146
|
const platform2 = arch2.getPlatform();
|
|
@@ -174,12 +178,16 @@ var Downloader = class {
|
|
|
174
178
|
const binaries = ["schema", "query", "sqlite"];
|
|
175
179
|
const binDir = targetDir || this.getDefaultBinDir();
|
|
176
180
|
fs.mkdirSync(binDir, { recursive: true });
|
|
177
|
-
|
|
181
|
+
this.mainSpinner = ora({
|
|
182
|
+
text: chalk.blue("Descargando binarios necesarios..."),
|
|
183
|
+
spinner: "dots12"
|
|
184
|
+
}).start();
|
|
185
|
+
for (let i = 0; i < binaries.length; i++) {
|
|
186
|
+
const prefix = binaries[i];
|
|
178
187
|
const maxRetries = 3;
|
|
179
188
|
let attempt = 0;
|
|
180
189
|
while (attempt <= maxRetries) {
|
|
181
190
|
try {
|
|
182
|
-
console.log(`\u{1F4E5} Descargando ${prefix} (intento ${attempt + 1}/${maxRetries + 1})...`);
|
|
183
191
|
const binaryInfo = this.get(prefix);
|
|
184
192
|
if (!binaryInfo.name || !binaryInfo.url) {
|
|
185
193
|
throw new Error("Plataforma o arquitectura no soportada");
|
|
@@ -187,35 +195,65 @@ var Downloader = class {
|
|
|
187
195
|
const tempZipPath = path.join(os2.tmpdir(), `dbcube-${prefix}-${Date.now()}.zip`);
|
|
188
196
|
const finalBinaryPath = path.join(binDir, binaryInfo.name);
|
|
189
197
|
if (fs.existsSync(finalBinaryPath)) {
|
|
190
|
-
|
|
198
|
+
this.updateMainProgress(prefix, i + 1, binaries.length, "exists");
|
|
191
199
|
break;
|
|
192
200
|
}
|
|
193
|
-
|
|
201
|
+
this.updateMainProgress(prefix, i + 1, binaries.length, "downloading");
|
|
202
|
+
await this.downloadFileWithProgress(binaryInfo.url, tempZipPath, prefix);
|
|
203
|
+
this.updateMainProgress(prefix, i + 1, binaries.length, "extracting");
|
|
194
204
|
await this.extractBinary(tempZipPath, finalBinaryPath, prefix);
|
|
195
|
-
|
|
205
|
+
this.updateMainProgress(prefix, i + 1, binaries.length, "completed");
|
|
196
206
|
break;
|
|
197
207
|
} catch (error) {
|
|
198
208
|
const errorMessage = error instanceof Error ? error.message : "Error desconocido";
|
|
199
209
|
if (attempt < maxRetries && (errorMessage.includes("ECONNRESET") || errorMessage.includes("timeout") || errorMessage.includes("ETIMEDOUT") || errorMessage.includes("ENOTFOUND"))) {
|
|
200
|
-
console.warn(`\u26A0\uFE0F Error de red para ${prefix}: ${errorMessage}`);
|
|
201
|
-
console.log(`\u{1F504} Reintentando en 3 segundos...`);
|
|
202
210
|
attempt++;
|
|
203
|
-
|
|
211
|
+
this.updateMainProgress(prefix, i + 1, binaries.length, "retrying", attempt);
|
|
212
|
+
await new Promise((resolve5) => setTimeout(resolve5, 2e3));
|
|
204
213
|
} else {
|
|
205
|
-
|
|
214
|
+
this.mainSpinner.fail(chalk.red(`Error descargando ${prefix}: ${errorMessage}`));
|
|
206
215
|
throw error;
|
|
207
216
|
}
|
|
208
217
|
}
|
|
209
218
|
}
|
|
210
219
|
}
|
|
211
|
-
|
|
212
|
-
|
|
220
|
+
this.mainSpinner.succeed(chalk.green("Binarios descargados correctamente"));
|
|
221
|
+
}
|
|
222
|
+
static updateMainProgress(binary, current, total, status, attempt) {
|
|
223
|
+
const progressBar = this.createProgressBar(current, total);
|
|
224
|
+
const statusEmojis = {
|
|
225
|
+
downloading: "\u{1F4E5}",
|
|
226
|
+
extracting: "\u{1F4E6}",
|
|
227
|
+
completed: "\u2705",
|
|
228
|
+
exists: "\u2705",
|
|
229
|
+
retrying: "\u{1F504}"
|
|
230
|
+
};
|
|
231
|
+
const statusMessages = {
|
|
232
|
+
downloading: chalk.blue("descargando"),
|
|
233
|
+
extracting: chalk.yellow("extrayendo"),
|
|
234
|
+
completed: chalk.green("completado"),
|
|
235
|
+
exists: chalk.gray("existe"),
|
|
236
|
+
retrying: chalk.orange(`reintentando (${attempt}/${3})`)
|
|
237
|
+
};
|
|
238
|
+
const emoji = statusEmojis[status] || "\u{1F4E5}";
|
|
239
|
+
const message = statusMessages[status] || status;
|
|
240
|
+
this.mainSpinner.text = `${progressBar} ${emoji} ${chalk.bold(binary)} - ${message}`;
|
|
241
|
+
}
|
|
242
|
+
static createProgressBar(current, total, width = 20) {
|
|
243
|
+
const filled = Math.round(current / total * width);
|
|
244
|
+
const empty = width - filled;
|
|
245
|
+
const filledBar = chalk.green("\u2588".repeat(filled));
|
|
246
|
+
const emptyBar = chalk.gray("\u2591".repeat(empty));
|
|
247
|
+
const percentage = chalk.bold(`${current}/${total}`);
|
|
248
|
+
return `[${filledBar}${emptyBar}] ${percentage}`;
|
|
249
|
+
}
|
|
250
|
+
static downloadFileWithProgress(url, outputPath, prefix) {
|
|
213
251
|
return new Promise((resolve5, reject) => {
|
|
214
252
|
const request = https.get(url, { timeout: 6e4 }, (response) => {
|
|
215
253
|
if (response.statusCode === 302 || response.statusCode === 301) {
|
|
216
254
|
const redirectUrl = response.headers.location;
|
|
217
255
|
if (redirectUrl) {
|
|
218
|
-
return this.
|
|
256
|
+
return this.downloadFileWithProgress(redirectUrl, outputPath, prefix).then(resolve5).catch(reject);
|
|
219
257
|
}
|
|
220
258
|
}
|
|
221
259
|
if (response.statusCode !== 200) {
|
|
@@ -225,21 +263,20 @@ var Downloader = class {
|
|
|
225
263
|
const file = fs.createWriteStream(outputPath);
|
|
226
264
|
const totalBytes = parseInt(response.headers["content-length"] || "0", 10);
|
|
227
265
|
let downloadedBytes = 0;
|
|
228
|
-
if (totalBytes > 0) {
|
|
229
|
-
console.log(`\u{1F4E6} Descargando ${(totalBytes / 1024 / 1024).toFixed(1)}MB...`);
|
|
230
|
-
}
|
|
231
266
|
response.on("data", (chunk) => {
|
|
232
267
|
downloadedBytes += chunk.length;
|
|
233
268
|
file.write(chunk);
|
|
234
269
|
if (totalBytes > 0) {
|
|
235
|
-
const progress =
|
|
236
|
-
|
|
270
|
+
const progress = {
|
|
271
|
+
downloaded: downloadedBytes,
|
|
272
|
+
total: totalBytes,
|
|
273
|
+
percentage: downloadedBytes / totalBytes * 100
|
|
274
|
+
};
|
|
275
|
+
this.updateDownloadProgress(prefix, progress);
|
|
237
276
|
}
|
|
238
277
|
});
|
|
239
278
|
response.on("end", () => {
|
|
240
279
|
file.end();
|
|
241
|
-
console.log(`
|
|
242
|
-
\u2705 Descarga de ${prefix} completada`);
|
|
243
280
|
resolve5();
|
|
244
281
|
});
|
|
245
282
|
response.on("error", (err) => {
|
|
@@ -260,6 +297,17 @@ var Downloader = class {
|
|
|
260
297
|
});
|
|
261
298
|
});
|
|
262
299
|
}
|
|
300
|
+
static updateDownloadProgress(binary, progress) {
|
|
301
|
+
const percentage = progress.percentage.toFixed(1);
|
|
302
|
+
const downloaded = (progress.downloaded / 1024 / 1024).toFixed(1);
|
|
303
|
+
const total = (progress.total / 1024 / 1024).toFixed(1);
|
|
304
|
+
const barWidth = 15;
|
|
305
|
+
const filled = Math.round(progress.percentage / 100 * barWidth);
|
|
306
|
+
const empty = barWidth - filled;
|
|
307
|
+
const progressBar = chalk.green("\u2588".repeat(filled)) + chalk.gray("\u2591".repeat(empty));
|
|
308
|
+
const progressText = `[${progressBar}] ${percentage}% (${downloaded}/${total}MB)`;
|
|
309
|
+
this.mainSpinner.text = `\u{1F4E5} ${chalk.bold(binary)} - ${progressText}`;
|
|
310
|
+
}
|
|
263
311
|
static extractBinary(zipPath, outputPath, prefix) {
|
|
264
312
|
return new Promise((resolve5, reject) => {
|
|
265
313
|
let extracted = false;
|
|
@@ -273,7 +321,6 @@ var Downloader = class {
|
|
|
273
321
|
fs.chmodSync(outputPath, 493);
|
|
274
322
|
}
|
|
275
323
|
this.cleanupFile(zipPath);
|
|
276
|
-
console.log(`\u{1F4C1} ${prefix} extra\xEDdo correctamente`);
|
|
277
324
|
resolve5();
|
|
278
325
|
});
|
|
279
326
|
writeStream.on("error", (err) => {
|
|
@@ -361,11 +408,9 @@ var Binary = class {
|
|
|
361
408
|
}
|
|
362
409
|
}
|
|
363
410
|
static async downloadBinaries() {
|
|
364
|
-
console.log("\u{1F680} DBCube: Descargando binarios necesarios...");
|
|
365
411
|
try {
|
|
366
412
|
const binDir = this.getBinDir();
|
|
367
413
|
await Downloader.download(binDir);
|
|
368
|
-
console.log("\u2705 DBCube: Binarios descargados correctamente");
|
|
369
414
|
} catch (error) {
|
|
370
415
|
console.warn("\u26A0\uFE0F DBCube: Error descargando binarios:", error.message);
|
|
371
416
|
console.log("\u{1F527} Los binarios se intentar\xE1n descargar en la pr\xF3xima ejecuci\xF3n");
|