@dbcube/cli 4.1.3 → 4.1.5

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/bun.lock CHANGED
@@ -4,7 +4,7 @@
4
4
  "": {
5
5
  "name": "@dbcube/cli",
6
6
  "dependencies": {
7
- "@dbcube/schema-builder": "^4.1.3",
7
+ "@dbcube/schema-builder": "^4.1.5",
8
8
  "@inquirer/prompts": "^8.0.2",
9
9
  "alwait": "^1.0.0",
10
10
  "chalk": "^5.6.2",
@@ -17,9 +17,9 @@
17
17
  },
18
18
  },
19
19
  "packages": {
20
- "@dbcube/core": ["@dbcube/core@4.1.6", "", { "dependencies": { "chalk": "^5.6.2", "deasync": "^0.1.31", "follow-redirects": "^1.15.11", "ora": "^9.0.0", "unzipper": "^0.12.3" }, "bin": { "dbcube-core": "dist/bin.cjs" } }, "sha512-o6uhIc+h/3F6Ay32bMu6bIxxR4cYnZ5mWYR7LxnJ2Wdx8Nfg1udqq1WSorhRVRxxz7YjFmkXtNP035NQgMwYag=="],
20
+ "@dbcube/core": ["@dbcube/core@4.1.8", "", { "dependencies": { "chalk": "^5.6.2", "deasync": "^0.1.31", "follow-redirects": "^1.15.11", "ora": "^9.0.0", "unzipper": "^0.12.3" }, "bin": { "dbcube-core": "dist/bin.cjs" } }, "sha512-EXwrTot6GTL1LbGviFmoKzngqFizoyKddrRTfqWMsq1wEQuo0n7i5LB/F4KHp9IG6gEOBpE9xa5nsWs4A/W5VQ=="],
21
21
 
22
- "@dbcube/schema-builder": ["@dbcube/schema-builder@4.1.3", "", { "dependencies": { "@dbcube/core": "^4.1.6", "chalk": "^5.6.2", "ora": "^9.0.0" } }, "sha512-l9mlxavWxMqy8B0QOs6CNhPjeU4lH8nJUHGCrm9afdbvWAYUFCg2l4gfg7wlbz8t1j2DRkZDjnGlUxPlGYAcQQ=="],
22
+ "@dbcube/schema-builder": ["@dbcube/schema-builder@4.1.5", "", { "dependencies": { "@dbcube/core": "^4.1.8", "chalk": "^5.6.2", "ora": "^9.0.0" } }, "sha512-FIywbSIUg/4ppXf0vH6jcYq6qsxmBx89PzdArs0AnCUoJEZ47KIQ6baa1RT8MLOFmVyt56hJ+grQ04Uu3NhWQw=="],
23
23
 
24
24
  "@inquirer/ansi": ["@inquirer/ansi@2.0.2", "", {}, "sha512-SYLX05PwJVnW+WVegZt1T4Ip1qba1ik+pNJPDiqvk6zS5Y/i8PhRzLpGEtVd7sW0G8cMtkD8t4AZYhQwm8vnww=="],
25
25
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dbcube/cli",
3
- "version": "4.1.3",
3
+ "version": "4.1.5",
4
4
  "main": "index.js",
5
5
  "scripts": {
6
6
  "dbcube": "node src/index.js"
@@ -13,7 +13,7 @@
13
13
  "license": "ISC",
14
14
  "description": "",
15
15
  "dependencies": {
16
- "@dbcube/schema-builder": "^4.1.3",
16
+ "@dbcube/schema-builder": "^4.1.5",
17
17
  "@inquirer/prompts": "^8.0.2",
18
18
  "alwait": "^1.0.0",
19
19
  "chalk": "^5.6.2",
@@ -28,11 +28,10 @@ async function showHelp() {
28
28
  console.log(` ${chalk.yellow('run seeder:add')} ${chalk.white('Add test data from seeder .cube files')}\n`);
29
29
 
30
30
  console.log(`${chalk.cyan.bold('BINARY MANAGEMENT:')}`);
31
+ console.log(` ${chalk.yellow('update')} ${chalk.white('Check and update binaries to latest version')}`);
31
32
  console.log(` ${chalk.yellow('run download')} ${chalk.white('Download binaries interactively')}`);
32
33
  console.log(` ${chalk.yellow('run download <engine>')} ${chalk.white('Download specific engine (latest version)')}`);
33
34
  console.log(` ${chalk.yellow('run download <engine> <ver>')} ${chalk.white('Download specific engine version')}`);
34
- console.log(` ${chalk.yellow('run update')} ${chalk.white('Check and update binaries to latest version')}`);
35
- console.log(` ${chalk.yellow('run upgrade')} ${chalk.white('Force update all binaries to latest version')}`);
36
35
  console.log(` ${chalk.gray(' Engines:')} query-engine, schema-engine, sqlite-engine\n`);
37
36
 
38
37
  console.log(`${chalk.cyan.bold('UTILITY COMMANDS:')}`);
@@ -60,10 +59,7 @@ async function showHelp() {
60
59
  console.log(` ${chalk.white('npx dbcube run download query-engine v3.1.1')}\n`);
61
60
 
62
61
  console.log(` ${chalk.gray('# Check and update binaries if needed')}`);
63
- console.log(` ${chalk.white('npx dbcube run update')}\n`);
64
-
65
- console.log(` ${chalk.gray('# Force upgrade all binaries to latest version')}`);
66
- console.log(` ${chalk.white('npx dbcube run upgrade')}\n`);
62
+ console.log(` ${chalk.white('npx dbcube update')}\n`);
67
63
 
68
64
  console.log(`${chalk.cyan.bold('CONFIGURATION:')}`);
69
65
  console.log(` ${chalk.white('Create a')} ${chalk.yellow('dbcube.config.js')} ${chalk.white('file in your project root:')}`);
@@ -1,11 +1,11 @@
1
1
  #!/usr/bin/env node
2
- const chalk = require('chalk');
2
+ const { default: chalk } = require('chalk');
3
+ const { default: ora } = require('ora');
3
4
  const path = require('path');
4
5
  const fs = require('fs');
5
6
  const https = require('https');
6
7
  const os = require('os');
7
8
  const unzipper = require('unzipper');
8
- const ora = require('ora');
9
9
 
10
10
  const VERSION_URLS = {
11
11
  'query-engine': 'https://raw.githubusercontent.com/Dbcube/binaries/main/query-engines.json',
package/src/index.js CHANGED
@@ -47,9 +47,10 @@ const commandMap = {
47
47
  'run:database:create:physical': '../src/commands/run/database/create/createDatabase.js',
48
48
 
49
49
  'run:download': '../src/commands/run/download.js',
50
- 'run:upgrade': '../src/commands/run/upgrade.js',
51
50
  'run:update': '../src/commands/run/update.js',
52
51
 
52
+ 'update': '../src/commands/update.js',
53
+
53
54
  '--version': '../src/commands/version.js',
54
55
  '-v': '../src/commands/version.js',
55
56
 
@@ -1,302 +0,0 @@
1
- #!/usr/bin/env node
2
- const chalk = require('chalk');
3
- const path = require('path');
4
- const fs = require('fs');
5
- const https = require('https');
6
- const os = require('os');
7
- const unzipper = require('unzipper');
8
- const ora = require('ora');
9
-
10
- const BINARIES = ['query-engine', 'schema-engine', 'sqlite-engine'];
11
-
12
- const BINARY_PREFIX_MAP = {
13
- 'query-engine': 'query',
14
- 'schema-engine': 'schema',
15
- 'sqlite-engine': 'sqlite'
16
- };
17
-
18
- const PLATFORM_MAP = {
19
- win32: 'windows',
20
- linux: 'linux',
21
- darwin: 'macos'
22
- };
23
-
24
- const ARCH_MAP = {
25
- x64: 'x64',
26
- arm64: 'arm64'
27
- };
28
-
29
- function getPlatformInfo() {
30
- const platform = PLATFORM_MAP[process.platform];
31
- const arch = ARCH_MAP[process.arch];
32
-
33
- if (!platform || !arch) {
34
- throw new Error(`Plataforma no soportada: ${process.platform} ${process.arch}`);
35
- }
36
-
37
- return { platform, arch };
38
- }
39
-
40
- function getBinDir() {
41
- const possibleDirs = [
42
- path.resolve(process.cwd(), '.dbcube', 'bin'),
43
- path.resolve(process.cwd(), 'node_modules', '.dbcube', 'bin'),
44
- ];
45
-
46
- for (const dir of possibleDirs) {
47
- try {
48
- if (!fs.existsSync(dir)) {
49
- fs.mkdirSync(dir, { recursive: true });
50
- }
51
- return dir;
52
- } catch {
53
- continue;
54
- }
55
- }
56
-
57
- const tempDir = path.join(os.tmpdir(), '.dbcube', 'bin');
58
- fs.mkdirSync(tempDir, { recursive: true });
59
- return tempDir;
60
- }
61
-
62
- function cleanBinDirectory(binDir) {
63
- if (!fs.existsSync(binDir)) {
64
- return 0;
65
- }
66
-
67
- const files = fs.readdirSync(binDir);
68
- let deletedCount = 0;
69
-
70
- for (const file of files) {
71
- const filePath = path.join(binDir, file);
72
- try {
73
- const stat = fs.statSync(filePath);
74
- if (stat.isFile()) {
75
- fs.unlinkSync(filePath);
76
- deletedCount++;
77
- }
78
- } catch (err) {
79
- console.warn(chalk.yellow(`⚠️ No se pudo eliminar: ${file}`));
80
- }
81
- }
82
-
83
- return deletedCount;
84
- }
85
-
86
- async function downloadBinary(engineType, version, spinner) {
87
- const { platform, arch } = getPlatformInfo();
88
- const prefix = BINARY_PREFIX_MAP[engineType];
89
-
90
- if (!prefix) {
91
- throw new Error(`Tipo de binario no soportado: ${engineType}`);
92
- }
93
-
94
- const baseName = `${prefix}-engine-${platform}-${arch}`;
95
- const binaryName = platform === 'windows' ? `${baseName}.exe` : baseName;
96
-
97
- // Build download URL
98
- const versionTag = version === 'latest' ? version : `v${version}`;
99
- const url = `https://github.com/Dbcube/binaries/releases/download/${prefix}-engine/${prefix}-engine-${versionTag}-${platform}-${arch}.zip`;
100
-
101
- const binDir = getBinDir();
102
- const tempZipPath = path.join(os.tmpdir(), `dbcube-${prefix}-${Date.now()}.zip`);
103
- const finalBinaryPath = path.join(binDir, binaryName);
104
-
105
- spinner.text = `📥 Descargando ${chalk.cyan(engineType)}...`;
106
-
107
- // Download
108
- await downloadFile(url, tempZipPath, (progress) => {
109
- const percentage = progress.percentage.toFixed(1);
110
- spinner.text = `📥 ${chalk.cyan(engineType)}: ${percentage}%`;
111
- });
112
-
113
- spinner.text = `📦 Extrayendo ${chalk.cyan(engineType)}...`;
114
-
115
- // Extract
116
- await extractBinary(tempZipPath, finalBinaryPath);
117
-
118
- // Cleanup
119
- cleanupFile(tempZipPath);
120
-
121
- return finalBinaryPath;
122
- }
123
-
124
- function downloadFile(url, outputPath, onProgress) {
125
- return new Promise((resolve, reject) => {
126
- https.get(url, { timeout: 30000 }, (response) => {
127
- // Handle redirects
128
- if (response.statusCode === 302 || response.statusCode === 301) {
129
- const redirectUrl = response.headers.location;
130
- if (redirectUrl) {
131
- return downloadFile(redirectUrl, outputPath, onProgress).then(resolve).catch(reject);
132
- }
133
- }
134
-
135
- if (response.statusCode !== 200) {
136
- reject(new Error(`HTTP ${response.statusCode}: El binario no existe`));
137
- return;
138
- }
139
-
140
- const file = fs.createWriteStream(outputPath);
141
- const totalBytes = parseInt(response.headers['content-length'] || '0', 10);
142
- let downloadedBytes = 0;
143
-
144
- response.on('data', (chunk) => {
145
- downloadedBytes += chunk.length;
146
- file.write(chunk);
147
-
148
- if (totalBytes > 0 && onProgress) {
149
- onProgress({
150
- downloaded: downloadedBytes,
151
- total: totalBytes,
152
- percentage: (downloadedBytes / totalBytes) * 100
153
- });
154
- }
155
- });
156
-
157
- response.on('end', () => {
158
- file.end();
159
- resolve();
160
- });
161
-
162
- response.on('error', (err) => {
163
- file.close();
164
- cleanupFile(outputPath);
165
- reject(err);
166
- });
167
-
168
- file.on('error', (err) => {
169
- file.close();
170
- cleanupFile(outputPath);
171
- reject(err);
172
- });
173
- }).on('error', reject).on('timeout', () => {
174
- reject(new Error('Timeout descargando el archivo'));
175
- });
176
- });
177
- }
178
-
179
- function extractBinary(zipPath, outputPath) {
180
- return new Promise((resolve, reject) => {
181
- let extracted = false;
182
-
183
- fs.createReadStream(zipPath)
184
- .pipe(unzipper.Parse())
185
- .on('entry', (entry) => {
186
- if (entry.type === 'File' && !extracted) {
187
- extracted = true;
188
- const writeStream = fs.createWriteStream(outputPath);
189
-
190
- entry.pipe(writeStream);
191
-
192
- writeStream.on('finish', () => {
193
- if (process.platform !== 'win32') {
194
- fs.chmodSync(outputPath, 0o755);
195
- }
196
- resolve();
197
- });
198
-
199
- writeStream.on('error', (err) => {
200
- reject(err);
201
- });
202
- } else {
203
- entry.autodrain();
204
- }
205
- })
206
- .on('error', (err) => {
207
- reject(err);
208
- })
209
- .on('close', () => {
210
- if (!extracted) {
211
- reject(new Error('No se encontró archivo válido en el ZIP'));
212
- }
213
- });
214
- });
215
- }
216
-
217
- function cleanupFile(filePath) {
218
- try {
219
- if (fs.existsSync(filePath)) {
220
- fs.unlinkSync(filePath);
221
- }
222
- } catch {
223
- // Ignore cleanup errors
224
- }
225
- }
226
-
227
- async function main() {
228
- console.log(chalk.blue('\n🔄 Dbcube Upgrade - Actualización de Binarios\n'));
229
-
230
- const spinner = ora('Iniciando proceso de actualización...').start();
231
-
232
- try {
233
- const binDir = getBinDir();
234
-
235
- // Step 1: Clean bin directory
236
- spinner.text = '🗑️ Limpiando directorio de binarios...';
237
- const deletedCount = cleanBinDirectory(binDir);
238
-
239
- if (deletedCount > 0) {
240
- spinner.succeed(chalk.green(`✓ ${deletedCount} archivo(s) eliminado(s)`));
241
- } else {
242
- spinner.info(chalk.gray('No había binarios previos'));
243
- }
244
-
245
- // Step 2: Download all binaries
246
- console.log(chalk.cyan('\n📦 Descargando binarios latest...\n'));
247
-
248
- const results = [];
249
- let successCount = 0;
250
- let failCount = 0;
251
-
252
- for (const binary of BINARIES) {
253
- const binarySpinner = ora(`Procesando ${chalk.cyan(binary)}...`).start();
254
-
255
- try {
256
- const binaryPath = await downloadBinary(binary, 'latest', binarySpinner);
257
- binarySpinner.succeed(chalk.green(`✓ ${binary} descargado`));
258
- results.push({ binary, success: true, path: binaryPath });
259
- successCount++;
260
- } catch (error) {
261
- binarySpinner.fail(chalk.red(`✗ ${binary} falló: ${error.message}`));
262
- results.push({ binary, success: false, error: error.message });
263
- failCount++;
264
- }
265
- }
266
-
267
- // Summary
268
- console.log(chalk.cyan('\n📊 Resumen de actualización:\n'));
269
-
270
- for (const result of results) {
271
- if (result.success) {
272
- console.log(chalk.green(` ✓ ${result.binary}`));
273
- console.log(chalk.gray(` ${result.path}`));
274
- } else {
275
- console.log(chalk.red(` ✗ ${result.binary}`));
276
- console.log(chalk.gray(` Error: ${result.error}`));
277
- }
278
- }
279
-
280
- console.log('');
281
-
282
- if (failCount === 0) {
283
- console.log(chalk.green.bold(`✅ Todos los binarios (${successCount}/${BINARIES.length}) actualizados exitosamente\n`));
284
- } else if (successCount > 0) {
285
- console.log(chalk.yellow.bold(`⚠️ Actualización parcial: ${successCount}/${BINARIES.length} binarios descargados\n`));
286
- process.exit(1);
287
- } else {
288
- console.log(chalk.red.bold(`❌ No se pudo descargar ningún binario\n`));
289
- process.exit(1);
290
- }
291
-
292
- } catch (error) {
293
- spinner.fail(chalk.red('Error en el proceso de actualización'));
294
- console.error(chalk.red(`\n❌ ${error.message}\n`));
295
- process.exit(1);
296
- }
297
- }
298
-
299
- main().catch(err => {
300
- console.error(chalk.red('\n❌ Error inesperado:'), err.message);
301
- process.exit(1);
302
- });