@dbcube/core 1.0.28 → 1.0.32
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 +68 -21
- package/dist/bin.cjs.map +1 -1
- package/dist/bin.js +68 -21
- package/dist/bin.js.map +1 -1
- package/dist/index.cjs +92 -26
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.mts +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +92 -26
- package/dist/index.js.map +1 -1
- package/package.json +3 -1
package/dist/index.d.mts
CHANGED
package/dist/index.d.ts
CHANGED
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) => {
|
|
@@ -304,7 +351,7 @@ var Downloader = class {
|
|
|
304
351
|
}
|
|
305
352
|
static getDefaultBinDir() {
|
|
306
353
|
const possibleDirs = [
|
|
307
|
-
path.resolve(process.cwd(), "bin"),
|
|
354
|
+
path.resolve(process.cwd(), ".dbcube", "bin"),
|
|
308
355
|
path.resolve(process.cwd(), "node_modules", ".dbcube", "bin"),
|
|
309
356
|
path.resolve(__dirname, "..", "bin")
|
|
310
357
|
];
|
|
@@ -321,7 +368,7 @@ var Downloader = class {
|
|
|
321
368
|
continue;
|
|
322
369
|
}
|
|
323
370
|
}
|
|
324
|
-
const tempDir = path.join(os2.tmpdir(), "dbcube
|
|
371
|
+
const tempDir = path.join(os2.tmpdir(), ".dbcube", "bin");
|
|
325
372
|
fs.mkdirSync(tempDir, { recursive: true });
|
|
326
373
|
return tempDir;
|
|
327
374
|
}
|
|
@@ -330,6 +377,7 @@ var Downloader = class {
|
|
|
330
377
|
// src/lib/Binary.ts
|
|
331
378
|
import * as fs2 from "fs";
|
|
332
379
|
import * as path2 from "path";
|
|
380
|
+
import * as os3 from "os";
|
|
333
381
|
var Binary = class {
|
|
334
382
|
static isDownloading = false;
|
|
335
383
|
static downloadPromise = null;
|
|
@@ -361,11 +409,9 @@ var Binary = class {
|
|
|
361
409
|
}
|
|
362
410
|
}
|
|
363
411
|
static async downloadBinaries() {
|
|
364
|
-
console.log("\u{1F680} DBCube: Descargando binarios necesarios...");
|
|
365
412
|
try {
|
|
366
413
|
const binDir = this.getBinDir();
|
|
367
414
|
await Downloader.download(binDir);
|
|
368
|
-
console.log("\u2705 DBCube: Binarios descargados correctamente");
|
|
369
415
|
} catch (error) {
|
|
370
416
|
console.warn("\u26A0\uFE0F DBCube: Error descargando binarios:", error.message);
|
|
371
417
|
console.log("\u{1F527} Los binarios se intentar\xE1n descargar en la pr\xF3xima ejecuci\xF3n");
|
|
@@ -373,7 +419,7 @@ var Binary = class {
|
|
|
373
419
|
}
|
|
374
420
|
static getBinDir() {
|
|
375
421
|
const possibleDirs = [
|
|
376
|
-
path2.resolve(process.cwd(), "bin"),
|
|
422
|
+
path2.resolve(process.cwd(), ".dbcube", "bin"),
|
|
377
423
|
path2.resolve(process.cwd(), "node_modules", ".dbcube", "bin"),
|
|
378
424
|
path2.resolve(__dirname, "..", "bin")
|
|
379
425
|
];
|
|
@@ -382,12 +428,32 @@ var Binary = class {
|
|
|
382
428
|
if (!fs2.existsSync(dir)) {
|
|
383
429
|
fs2.mkdirSync(dir, { recursive: true });
|
|
384
430
|
}
|
|
431
|
+
if (dir.includes(path2.resolve(process.cwd(), ".dbcube"))) {
|
|
432
|
+
this.ensureGitIgnore(path2.resolve(process.cwd(), ".dbcube"));
|
|
433
|
+
}
|
|
385
434
|
return dir;
|
|
386
435
|
} catch {
|
|
387
436
|
continue;
|
|
388
437
|
}
|
|
389
438
|
}
|
|
390
|
-
|
|
439
|
+
const tempDir = path2.join(os3.tmpdir(), ".dbcube", "bin");
|
|
440
|
+
fs2.mkdirSync(tempDir, { recursive: true });
|
|
441
|
+
return tempDir;
|
|
442
|
+
}
|
|
443
|
+
static ensureGitIgnore(dbcubeDir) {
|
|
444
|
+
try {
|
|
445
|
+
const gitignorePath = path2.join(dbcubeDir, ".gitignore");
|
|
446
|
+
if (!fs2.existsSync(gitignorePath)) {
|
|
447
|
+
const gitignoreContent = `# DBCube binaries
|
|
448
|
+
bin/
|
|
449
|
+
*.exe
|
|
450
|
+
*.log
|
|
451
|
+
*.tmp
|
|
452
|
+
`;
|
|
453
|
+
fs2.writeFileSync(gitignorePath, gitignoreContent);
|
|
454
|
+
}
|
|
455
|
+
} catch {
|
|
456
|
+
}
|
|
391
457
|
}
|
|
392
458
|
static async get() {
|
|
393
459
|
await this.ensureBinariesExist();
|