@dbcube/cli 1.0.1
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/.lh/.lhignore +6 -0
- package/.lh/package.json.json +26 -0
- package/package.json +25 -0
- package/src/commands/run/database/create/addDatabaseConfig.js +193 -0
- package/src/commands/run/database/create/createDatabase.js +88 -0
- package/src/commands/run/database/create/index.js +157 -0
- package/src/commands/run/seeder/add.js +76 -0
- package/src/commands/run/table/fresh.js +76 -0
- package/src/commands/run/table/refresh.js +76 -0
- package/src/commands/run/trigger/fresh.js +76 -0
- package/src/index.js +100 -0
- package/src/lib/DBCubeLogger.js +116 -0
- package/src/lib/LoggerConsole.js +262 -0
- package/src/utils/Config.js +49 -0
- package/src/utils/ConfigFileUtils.js +295 -0
- package/src/utils/FileUtils.js +73 -0
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
const { default: Schema } = require('@dbcube/schema-builder');
|
|
2
|
+
const ConfigFileUtils = require('./../../../utils/ConfigFileUtils');
|
|
3
|
+
const fs = require('fs');
|
|
4
|
+
const path = require('path');
|
|
5
|
+
const FileUtils = require('./../../../utils/FileUtils');
|
|
6
|
+
const { default: chalk } = require('chalk');
|
|
7
|
+
const { default: ora } = require('ora');
|
|
8
|
+
const { default: alwait } = require('alwait');
|
|
9
|
+
|
|
10
|
+
async function main() {
|
|
11
|
+
// Suprimir logs de dotenv
|
|
12
|
+
process.env.DOTENV_SILENT = 'true';
|
|
13
|
+
|
|
14
|
+
console.clear();
|
|
15
|
+
console.log(`\n🔄 ${chalk.green("Ejecutando refresh tables...")}`);
|
|
16
|
+
try {
|
|
17
|
+
// Verificar y leer archivos de la carpeta cubes
|
|
18
|
+
const spinner = ora('Preparando refresh de tablas...').start();
|
|
19
|
+
await alwait(500);
|
|
20
|
+
const cubesDir = path.join(process.cwd(), 'dbcube', 'cubes');
|
|
21
|
+
|
|
22
|
+
// Verificar si la carpeta existe
|
|
23
|
+
if (!fs.existsSync(cubesDir)) {
|
|
24
|
+
spinner.fail('Carpeta de cubes no encontrada');
|
|
25
|
+
throw new Error('❌ The cubes folder does not exist');
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
// Leer todos los archivos en la carpeta
|
|
29
|
+
const cubeFiles = FileUtils.getCubeFilesRecursively('dbcube', 'table.cube')
|
|
30
|
+
|
|
31
|
+
if (cubeFiles.length === 0) {
|
|
32
|
+
spinner.fail('No hay cubes para ejecutar');
|
|
33
|
+
throw new Error('❌ There are no cubes to execute');
|
|
34
|
+
} else {
|
|
35
|
+
spinner.succeed('Cubes encontrados correctamente');
|
|
36
|
+
|
|
37
|
+
const loadingSpinner = ora('Cargando configuraciones de base de datos...').start();
|
|
38
|
+
let countTableCreated = 0;
|
|
39
|
+
const configuredDatabases = await ConfigFileUtils.getConfiguredDatabases();
|
|
40
|
+
loadingSpinner.succeed(`Configuraciones cargadas (${configuredDatabases.length} bases de datos)`);
|
|
41
|
+
|
|
42
|
+
// Recorrer cada archivo y mostrar su contenido
|
|
43
|
+
for (const config of configuredDatabases) {
|
|
44
|
+
const refreshSpinner = ora(`Ejecutando refresh tables para: ${config.name} (${config.type})...`).start();
|
|
45
|
+
const schema = new Schema(config.name);
|
|
46
|
+
await schema.refreshTables();
|
|
47
|
+
refreshSpinner.succeed(`Refresh tables ejecutado para: ${config.name}`);
|
|
48
|
+
countTableCreated++;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
if(countTableCreated==0) {
|
|
52
|
+
console.log(`\n⚠️ ${chalk.yellow('No hay tablas para refrescar.')}`);
|
|
53
|
+
} else {
|
|
54
|
+
console.log(`\n🎉 ${chalk.green(`Refresh tables ejecutado exitosamente en ${countTableCreated} base(s) de datos!`)}`);
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
}
|
|
58
|
+
} catch (error) {
|
|
59
|
+
if(error.message.includes("reading 'init'")){
|
|
60
|
+
console.error('❌ Configuracion de base de datos no encontrada\n');
|
|
61
|
+
console.error('Ejecute el comando para crear una nueva base de datos:');
|
|
62
|
+
console.error(`\tdbcube run create:database`);
|
|
63
|
+
console.error('\nO verifique que la base de datos este configurada en el archivo dbcube.config.js\n');
|
|
64
|
+
process.exit(1);
|
|
65
|
+
} else if(error.message.includes("reading 'getDatabase'")){
|
|
66
|
+
console.error('- Se sugiere cambiar el linea o crear la base de datos a la que se hace referencia.');
|
|
67
|
+
}else{
|
|
68
|
+
console.error('Error aqui:', error);
|
|
69
|
+
console.error('Error aqui:', error.message);
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
console.log('\n');
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
// Ejecutar el ejemplo
|
|
76
|
+
main().catch(console.error);
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
const { default: Schema } = require('@dbcube/schema-builder');
|
|
2
|
+
const ConfigFileUtils = require('./../../../utils/ConfigFileUtils');
|
|
3
|
+
const fs = require('fs');
|
|
4
|
+
const path = require('path');
|
|
5
|
+
const FileUtils = require('./../../../utils/FileUtils');
|
|
6
|
+
const { default: chalk } = require('chalk');
|
|
7
|
+
const { default: ora } = require('ora');
|
|
8
|
+
const { default: alwait } = require('alwait');
|
|
9
|
+
|
|
10
|
+
async function main() {
|
|
11
|
+
// Suprimir logs de dotenv
|
|
12
|
+
process.env.DOTENV_SILENT = 'true';
|
|
13
|
+
|
|
14
|
+
console.clear();
|
|
15
|
+
console.log(`\n⚡ ${chalk.green("Ejecutando triggers...")}`);
|
|
16
|
+
try {
|
|
17
|
+
// Verificar y leer archivos de la carpeta cubes
|
|
18
|
+
const spinner = ora('Preparando ejecución de triggers...').start();
|
|
19
|
+
await alwait(500);
|
|
20
|
+
const cubesDir = path.join(process.cwd(), 'dbcube', 'cubes');
|
|
21
|
+
|
|
22
|
+
// Verificar si la carpeta existe
|
|
23
|
+
if (!fs.existsSync(cubesDir)) {
|
|
24
|
+
spinner.fail('Carpeta de cubes no encontrada');
|
|
25
|
+
throw new Error('❌ The cubes folder does not exist');
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
// Leer todos los archivos en la carpeta
|
|
29
|
+
const cubeFiles = FileUtils.getCubeFilesRecursively('dbcube', 'table.cube')
|
|
30
|
+
|
|
31
|
+
if (cubeFiles.length === 0) {
|
|
32
|
+
spinner.fail('No hay cubes para ejecutar');
|
|
33
|
+
throw new Error('❌ There are no cubes to execute');
|
|
34
|
+
} else {
|
|
35
|
+
spinner.succeed('Cubes encontrados correctamente');
|
|
36
|
+
|
|
37
|
+
const loadingSpinner = ora('Cargando configuraciones de base de datos...').start();
|
|
38
|
+
let countTableCreated = 0;
|
|
39
|
+
const configuredDatabases = await ConfigFileUtils.getConfiguredDatabases();
|
|
40
|
+
loadingSpinner.succeed(`Configuraciones cargadas (${configuredDatabases.length} bases de datos)`);
|
|
41
|
+
|
|
42
|
+
// Recorrer cada archivo y mostrar su contenido
|
|
43
|
+
for (const config of configuredDatabases) {
|
|
44
|
+
const triggerSpinner = ora(`Ejecutando triggers para: ${config.name} (${config.type})...`).start();
|
|
45
|
+
const schema = new Schema(config.name);
|
|
46
|
+
await schema.executeTriggers();
|
|
47
|
+
triggerSpinner.succeed(`Triggers ejecutados para: ${config.name}`);
|
|
48
|
+
countTableCreated++;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
if(countTableCreated==0) {
|
|
52
|
+
console.log(`\n⚠️ ${chalk.yellow('No hay triggers para ejecutar.')}`);
|
|
53
|
+
} else {
|
|
54
|
+
console.log(`\n🎉 ${chalk.green(`Triggers ejecutados exitosamente en ${countTableCreated} base(s) de datos!`)}`);
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
}
|
|
58
|
+
} catch (error) {
|
|
59
|
+
if(error.message.includes("reading 'init'")){
|
|
60
|
+
console.error('❌ Configuracion de base de datos no encontrada\n');
|
|
61
|
+
console.error('Ejecute el comando para crear una nueva base de datos:');
|
|
62
|
+
console.error(`\tdbcube run create:database`);
|
|
63
|
+
console.error('\nO verifique que la base de datos este configurada en el archivo dbcube.config.js\n');
|
|
64
|
+
process.exit(1);
|
|
65
|
+
} else if(error.message.includes("reading 'getDatabase'")){
|
|
66
|
+
console.error('- Se sugiere cambiar el linea o crear la base de datos a la que se hace referencia.');
|
|
67
|
+
}else{
|
|
68
|
+
console.error('Error aqui:', error);
|
|
69
|
+
console.error('Error aqui:', error.message);
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
console.log('\n');
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
// Ejecutar el ejemplo
|
|
76
|
+
main().catch(console.error);
|
package/src/index.js
ADDED
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
const path = require('path');
|
|
3
|
+
|
|
4
|
+
// Obtener los argumentos pasados al comando
|
|
5
|
+
const args = process.argv.slice(2);
|
|
6
|
+
|
|
7
|
+
// Procesar los argumentos
|
|
8
|
+
let mainCommand = '';
|
|
9
|
+
const commandArgs = [];
|
|
10
|
+
|
|
11
|
+
if (args.length > 0) {
|
|
12
|
+
// Si el primer argumento es "run", combinamos con el segundo para formar el comando
|
|
13
|
+
if (args[0] === 'run' && args.length > 1) {
|
|
14
|
+
mainCommand = 'run:' + args[1];
|
|
15
|
+
// Añadir el resto de argumentos
|
|
16
|
+
for (let i = 2; i < args.length; i++) {
|
|
17
|
+
commandArgs.push(args[i]);
|
|
18
|
+
}
|
|
19
|
+
} else if (args[0].includes('create:')) {
|
|
20
|
+
// Si es un comando create: lo usamos directamente
|
|
21
|
+
mainCommand = args[0];
|
|
22
|
+
// Añadir el resto de argumentos
|
|
23
|
+
for (let i = 1; i < args.length; i++) {
|
|
24
|
+
commandArgs.push(args[i]);
|
|
25
|
+
}
|
|
26
|
+
} else {
|
|
27
|
+
// Para otros comandos, usamos el primer argumento como comando
|
|
28
|
+
mainCommand = args[0];
|
|
29
|
+
// Añadir el resto de argumentos
|
|
30
|
+
for (let i = 1; i < args.length; i++) {
|
|
31
|
+
commandArgs.push(args[i]);
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
// Mapa de comandos para mapear nombres de comandos a rutas de archivo
|
|
37
|
+
const commandMap = {
|
|
38
|
+
'run:table:fresh': '../src/commands/run/table/fresh.js',
|
|
39
|
+
'run:table:refresh': '../src/commands/run/table/refresh.js',
|
|
40
|
+
|
|
41
|
+
'run:trigger:fresh': '../src/commands/run/trigger/fresh.js',
|
|
42
|
+
|
|
43
|
+
'run:seeder:add': '../src/commands/run/seeder/add.js',
|
|
44
|
+
|
|
45
|
+
'run:database:create': '../src/commands/run/database/create/index.js',
|
|
46
|
+
'run:database:create:config': '../src/commands/run/database/create/addDatabaseConfig.js',
|
|
47
|
+
'run:database:create:physical': '../src/commands/run/database/create/createDatabase.js',
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
// Función para ejecutar comandos basados en los argumentos
|
|
51
|
+
async function executeCommand(command, commandArgs) {
|
|
52
|
+
// Verificar si el comando existe en el mapa
|
|
53
|
+
if (commandMap[command]) {
|
|
54
|
+
const examplePath = path.join(__dirname, commandMap[command]);
|
|
55
|
+
|
|
56
|
+
// Guardamos los argumentos originales
|
|
57
|
+
const originalArgv = process.argv;
|
|
58
|
+
|
|
59
|
+
try {
|
|
60
|
+
// Reemplazamos los argumentos con los que necesitamos pasar al script
|
|
61
|
+
process.argv = [process.argv[0], process.argv[1], ...commandArgs];
|
|
62
|
+
await require(examplePath);
|
|
63
|
+
} finally {
|
|
64
|
+
// Restauramos los argumentos originales
|
|
65
|
+
process.argv = originalArgv;
|
|
66
|
+
}
|
|
67
|
+
} else {
|
|
68
|
+
// Comando desconocido
|
|
69
|
+
console.log(`Comando desconocido: ${command} ${commandArgs.join(' ')}`);
|
|
70
|
+
console.log('Comandos disponibles:');
|
|
71
|
+
for (const cmd in commandMap) {
|
|
72
|
+
let description = '';
|
|
73
|
+
switch (cmd) {
|
|
74
|
+
case 'run:cube:fresh':
|
|
75
|
+
description = 'Ejecuta el ejemplo de migración';
|
|
76
|
+
break;
|
|
77
|
+
case 'run:create:database':
|
|
78
|
+
case 'run:create:db':
|
|
79
|
+
case 'create:database':
|
|
80
|
+
case 'create:db':
|
|
81
|
+
if (!description) description = 'Crea una base de datos [--name=<nombre> | -n <nombre>] [--motor=<motor> | -m <motor>]';
|
|
82
|
+
break;
|
|
83
|
+
case 'run:create:database:config':
|
|
84
|
+
description = 'Agrega configuración de base de datos [--name=<nombre> | -n <nombre>] [--motor=<motor> | -m <motor>]';
|
|
85
|
+
break;
|
|
86
|
+
case 'run:create:database:physical':
|
|
87
|
+
description = 'Crea la base de datos física [--name=<nombre> | -n <nombre>]';
|
|
88
|
+
break;
|
|
89
|
+
}
|
|
90
|
+
if (description) console.log(` ${cmd} - ${description}`);
|
|
91
|
+
}
|
|
92
|
+
process.exit(1);
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
// Ejecutar el comando correspondiente
|
|
97
|
+
executeCommand(mainCommand, commandArgs).catch(err => {
|
|
98
|
+
console.error('Error inesperado:', err);
|
|
99
|
+
process.exit(1);
|
|
100
|
+
});
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
class DBCubeLogger {
|
|
2
|
+
constructor(title) {
|
|
3
|
+
this.logs = [];
|
|
4
|
+
this.maxLogs = 3;
|
|
5
|
+
this.title = title;
|
|
6
|
+
this.isWaiting = false;
|
|
7
|
+
this.animationInterval = null;
|
|
8
|
+
this.currentFace = 0;
|
|
9
|
+
this.faces = ['● ‿ ●', '● ‿ ●', '● ‿ <', '● ‿ <', '● ‿ ●', '● ‿ ●', '> ‿ ●', '> ‿ ●', '● ‿ ●', '● ‿ ●', '> ‿ <', '> ‿ <', '● ‿ ●', '● ‿ ●', '> ‿ <', '> ‿ <'];
|
|
10
|
+
|
|
11
|
+
// Registrar globalmente para que LoggerConsole pueda acceder
|
|
12
|
+
global.dbcubeLogger = this;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
// Función para limpiar solo el área superior de la consola
|
|
16
|
+
clearConsole() {
|
|
17
|
+
// Solo limpiar si estamos en modo división de consola
|
|
18
|
+
if (global.loggerConsoleInstances && global.loggerConsoleInstances.top && global.loggerConsoleInstances.top.isActive) {
|
|
19
|
+
// Usar el método clear interceptado que solo afecta al área superior
|
|
20
|
+
console.clear();
|
|
21
|
+
} else {
|
|
22
|
+
// Comportamiento normal si no hay división
|
|
23
|
+
console.clear();
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
// Función para dibujar el cubo con logs
|
|
28
|
+
drawCube() {
|
|
29
|
+
this.clearConsole();
|
|
30
|
+
console.log(this.title);
|
|
31
|
+
|
|
32
|
+
// Mostrar logs anteriores (máximo 3)
|
|
33
|
+
for (let i = 0; i < this.logs.length - 3; i++) {
|
|
34
|
+
const log = this.logs[i];
|
|
35
|
+
if (i == 0) console.log('╭───────╮');
|
|
36
|
+
console.log('│───────│ ' + log.message);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
if (this.logs.length == 1) {
|
|
40
|
+
console.log('╭───────╮');
|
|
41
|
+
console.log('│───────│');
|
|
42
|
+
console.log('│───────│');
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
if (this.logs.length == 2) {
|
|
46
|
+
const penPastLog = this.logs[this.logs.length - 2];
|
|
47
|
+
console.log('╭───────╮');
|
|
48
|
+
console.log('│───────│');
|
|
49
|
+
console.log('│───────│ ' + penPastLog.message);
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
if (this.logs.length == 3) {
|
|
53
|
+
const penPastLog = this.logs[this.logs.length - 3];
|
|
54
|
+
const penPastLog2 = this.logs[this.logs.length - 2];
|
|
55
|
+
console.log('╭───────╮');
|
|
56
|
+
console.log('│───────│ ' + penPastLog.message);
|
|
57
|
+
console.log('│───────│ ' + penPastLog2.message);
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
// Mostrar el cubo con cara en la última posición
|
|
61
|
+
if (this.logs.length > 0) {
|
|
62
|
+
const lastLog = this.logs[this.logs.length - 1];
|
|
63
|
+
const face = this.isWaiting ? this.faces[this.currentFace] : lastLog.face;
|
|
64
|
+
console.log('│ ' + face + ' │ ' + lastLog.message);
|
|
65
|
+
console.log('╰───────╯');
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
// Función para agregar un log
|
|
70
|
+
addLog(message, face) {
|
|
71
|
+
const log = { message, face };
|
|
72
|
+
this.logs.push(log);
|
|
73
|
+
|
|
74
|
+
// Mantener máximo 3 logs
|
|
75
|
+
if (this.logs.length > this.maxLogs) {
|
|
76
|
+
this.logs.shift();
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
if (!this.isWaiting) {
|
|
80
|
+
this.drawCube();
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
// Función para logs normales
|
|
85
|
+
info(message) {
|
|
86
|
+
this.addLog(message, '● ‿ ●');
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
// Función para logs de error
|
|
90
|
+
error(message) {
|
|
91
|
+
this.addLog(message, 'x _ x');
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
// Función para comenzar la animación de espera
|
|
95
|
+
wait() {
|
|
96
|
+
this.isWaiting = true;
|
|
97
|
+
this.currentFace = 0;
|
|
98
|
+
|
|
99
|
+
this.animationInterval = setInterval(() => {
|
|
100
|
+
this.currentFace = (this.currentFace + 1) % this.faces.length;
|
|
101
|
+
this.drawCube();
|
|
102
|
+
}, 500); // Cambia cada 500ms
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
// Función para detener la animación
|
|
106
|
+
continue() {
|
|
107
|
+
this.isWaiting = false;
|
|
108
|
+
if (this.animationInterval) {
|
|
109
|
+
clearInterval(this.animationInterval);
|
|
110
|
+
this.animationInterval = null;
|
|
111
|
+
}
|
|
112
|
+
this.drawCube();
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
module.exports = DBCubeLogger;
|
|
@@ -0,0 +1,262 @@
|
|
|
1
|
+
class LoggerConsole {
|
|
2
|
+
constructor(topLines = null) {
|
|
3
|
+
this.topLines = topLines;
|
|
4
|
+
this.isTopConsole = topLines !== null && topLines !== undefined;
|
|
5
|
+
this.isActive = false;
|
|
6
|
+
this.originalConsole = {};
|
|
7
|
+
this.buffer = [];
|
|
8
|
+
this.bottomBuffer = [];
|
|
9
|
+
this.topBuffer = [];
|
|
10
|
+
this.terminalHeight = process.stdout.rows || 24;
|
|
11
|
+
this.terminalWidth = process.stdout.columns || 80;
|
|
12
|
+
|
|
13
|
+
// Compartir instancias globalmente
|
|
14
|
+
if (!global.loggerConsoleInstances) {
|
|
15
|
+
global.loggerConsoleInstances = {
|
|
16
|
+
top: null,
|
|
17
|
+
bottom: null,
|
|
18
|
+
sharedState: {
|
|
19
|
+
topBuffer: [],
|
|
20
|
+
bottomBuffer: [],
|
|
21
|
+
activeInstance: null
|
|
22
|
+
}
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
// Registrar la instancia
|
|
27
|
+
if (this.isTopConsole) {
|
|
28
|
+
global.loggerConsoleInstances.top = this;
|
|
29
|
+
} else {
|
|
30
|
+
global.loggerConsoleInstances.bottom = this;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
start() {
|
|
35
|
+
if (this.isActive) return;
|
|
36
|
+
|
|
37
|
+
this.isActive = true;
|
|
38
|
+
global.loggerConsoleInstances.sharedState.activeInstance = this;
|
|
39
|
+
|
|
40
|
+
// Interceptar console methods solo para la instancia activa
|
|
41
|
+
if (this.isTopConsole) {
|
|
42
|
+
this.interceptConsole();
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
// Configurar el terminal
|
|
46
|
+
this.setupTerminal();
|
|
47
|
+
|
|
48
|
+
// Render inicial
|
|
49
|
+
this.render();
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
end() {
|
|
53
|
+
if (!this.isActive) return;
|
|
54
|
+
|
|
55
|
+
this.isActive = false;
|
|
56
|
+
|
|
57
|
+
// Restaurar console original
|
|
58
|
+
if (this.isTopConsole) {
|
|
59
|
+
this.restoreConsole();
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
// Limpiar terminal
|
|
63
|
+
this.cleanup();
|
|
64
|
+
|
|
65
|
+
|
|
66
|
+
global.loggerConsoleInstances.sharedState.activeInstance = null;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
setupTerminal() {
|
|
70
|
+
// Ocultar cursor
|
|
71
|
+
process.stdout.write('\x1B[?25l');
|
|
72
|
+
|
|
73
|
+
// Limpiar pantalla
|
|
74
|
+
process.stdout.write('\x1B[2J\x1B[H');
|
|
75
|
+
|
|
76
|
+
// Configurar el área de trabajo
|
|
77
|
+
this.reserveArea();
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
reserveArea() {
|
|
81
|
+
if (this.isTopConsole) {
|
|
82
|
+
// Reservar líneas superiores
|
|
83
|
+
for (let i = 0; i < this.topLines; i++) {
|
|
84
|
+
process.stdout.write('\n');
|
|
85
|
+
}
|
|
86
|
+
// Posicionar cursor en la primera línea reservada
|
|
87
|
+
process.stdout.write(`\x1B[${this.topLines}A`);
|
|
88
|
+
} else {
|
|
89
|
+
// Posicionar cursor en la parte inferior
|
|
90
|
+
const bottomStartLine = (global.loggerConsoleInstances.top?.topLines || 0) + 2;
|
|
91
|
+
process.stdout.write(`\x1B[${bottomStartLine};1H`);
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
interceptConsole() {
|
|
96
|
+
// Guardar métodos originales
|
|
97
|
+
this.originalConsole.log = console.log;
|
|
98
|
+
this.originalConsole.info = console.info;
|
|
99
|
+
this.originalConsole.error = console.error;
|
|
100
|
+
this.originalConsole.warn = console.warn;
|
|
101
|
+
this.originalConsole.clear = console.clear;
|
|
102
|
+
|
|
103
|
+
// Interceptar console.log para la consola superior
|
|
104
|
+
console.log = (...args) => {
|
|
105
|
+
if (this.isActive && this.isTopConsole) {
|
|
106
|
+
this.addToTopBuffer(args.join(' '));
|
|
107
|
+
this.render();
|
|
108
|
+
}
|
|
109
|
+
};
|
|
110
|
+
|
|
111
|
+
console.info = (...args) => {
|
|
112
|
+
if (this.isActive && this.isTopConsole) {
|
|
113
|
+
this.addToTopBuffer(args.join(' '));
|
|
114
|
+
this.render();
|
|
115
|
+
}
|
|
116
|
+
};
|
|
117
|
+
|
|
118
|
+
console.error = (...args) => {
|
|
119
|
+
if (this.isActive && this.isTopConsole) {
|
|
120
|
+
this.addToTopBuffer(args.join(' '));
|
|
121
|
+
this.render();
|
|
122
|
+
}
|
|
123
|
+
};
|
|
124
|
+
|
|
125
|
+
console.warn = (...args) => {
|
|
126
|
+
if (this.isActive && this.isTopConsole) {
|
|
127
|
+
this.addToTopBuffer(args.join(' '));
|
|
128
|
+
this.render();
|
|
129
|
+
}
|
|
130
|
+
};
|
|
131
|
+
|
|
132
|
+
console.clear = () => {
|
|
133
|
+
if (this.isActive && this.isTopConsole) {
|
|
134
|
+
this.clearTopBuffer();
|
|
135
|
+
this.render();
|
|
136
|
+
}
|
|
137
|
+
};
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
restoreConsole() {
|
|
141
|
+
console.log = this.originalConsole.log;
|
|
142
|
+
console.info = this.originalConsole.info;
|
|
143
|
+
console.error = this.originalConsole.error;
|
|
144
|
+
console.warn = this.originalConsole.warn;
|
|
145
|
+
console.clear = this.originalConsole.clear;
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
addToTopBuffer(message) {
|
|
149
|
+
global.loggerConsoleInstances.sharedState.topBuffer.push(message);
|
|
150
|
+
|
|
151
|
+
// Mantener solo las líneas necesarias
|
|
152
|
+
if (global.loggerConsoleInstances.sharedState.topBuffer.length > this.topLines) {
|
|
153
|
+
global.loggerConsoleInstances.sharedState.topBuffer.shift();
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
addToBottomBuffer(message) {
|
|
158
|
+
global.loggerConsoleInstances.sharedState.bottomBuffer.push(message);
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
clearTopBuffer() {
|
|
162
|
+
global.loggerConsoleInstances.sharedState.topBuffer = [];
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
render() {
|
|
166
|
+
if (!this.isActive) return;
|
|
167
|
+
|
|
168
|
+
if (this.isTopConsole) {
|
|
169
|
+
this.renderTopArea();
|
|
170
|
+
} else {
|
|
171
|
+
this.renderBottomArea();
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
renderTopArea() {
|
|
176
|
+
// Guardar posición del cursor
|
|
177
|
+
process.stdout.write('\x1B[s');
|
|
178
|
+
|
|
179
|
+
// Ir al inicio del área superior
|
|
180
|
+
process.stdout.write('\x1B[1;1H');
|
|
181
|
+
|
|
182
|
+
// Limpiar área superior
|
|
183
|
+
for (let i = 0; i < this.topLines; i++) {
|
|
184
|
+
process.stdout.write('\x1B[2K'); // Limpiar línea
|
|
185
|
+
if (i < this.topLines - 1) process.stdout.write('\n');
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
// Volver al inicio del área superior
|
|
189
|
+
process.stdout.write('\x1B[1;1H');
|
|
190
|
+
|
|
191
|
+
// Renderizar buffer superior
|
|
192
|
+
const topBuffer = global.loggerConsoleInstances.sharedState.topBuffer;
|
|
193
|
+
for (let i = 0; i < Math.min(topBuffer.length, this.topLines); i++) {
|
|
194
|
+
process.stdout.write(topBuffer[i]);
|
|
195
|
+
if (i < Math.min(topBuffer.length, this.topLines) - 1) {
|
|
196
|
+
process.stdout.write('\n');
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
// Restaurar posición del cursor
|
|
201
|
+
process.stdout.write('\x1B[u');
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
renderBottomArea() {
|
|
205
|
+
const topLines = global.loggerConsoleInstances.top?.topLines || 0;
|
|
206
|
+
const separatorLine = topLines + 1;
|
|
207
|
+
const bottomStartLine = topLines + 2;
|
|
208
|
+
|
|
209
|
+
// Dibujar separador
|
|
210
|
+
process.stdout.write(`\x1B[${separatorLine};1H`);
|
|
211
|
+
process.stdout.write('\x1B[2K');
|
|
212
|
+
process.stdout.write('─'.repeat(this.terminalWidth));
|
|
213
|
+
|
|
214
|
+
// Posicionar cursor en área inferior
|
|
215
|
+
process.stdout.write(`\x1B[${bottomStartLine};1H`);
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
cleanup() {
|
|
219
|
+
// Mostrar cursor
|
|
220
|
+
process.stdout.write('\x1B[?25h');
|
|
221
|
+
|
|
222
|
+
// Ir al final de la pantalla
|
|
223
|
+
process.stdout.write(`\x1B[${this.terminalHeight};1H`);
|
|
224
|
+
|
|
225
|
+
// Limpiar pantalla si es necesario
|
|
226
|
+
if (this.isTopConsole) {
|
|
227
|
+
process.stdout.write('\x1B[2J\x1B[H');
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
// Método para enviar logs desde la consola inferior a la superior
|
|
232
|
+
sendToTop(message, type = 'info') {
|
|
233
|
+
if (global.loggerConsoleInstances.top && global.loggerConsoleInstances.top.isActive) {
|
|
234
|
+
// Simular llamada al método del DBCubeLogger
|
|
235
|
+
if (global.dbcubeLogger) {
|
|
236
|
+
switch (type) {
|
|
237
|
+
case 'info':
|
|
238
|
+
global.dbcubeLogger.info(message);
|
|
239
|
+
break;
|
|
240
|
+
case 'error':
|
|
241
|
+
global.dbcubeLogger.error(message);
|
|
242
|
+
break;
|
|
243
|
+
case 'wait':
|
|
244
|
+
global.dbcubeLogger.wait();
|
|
245
|
+
break;
|
|
246
|
+
case 'continue':
|
|
247
|
+
global.dbcubeLogger.continue();
|
|
248
|
+
break;
|
|
249
|
+
}
|
|
250
|
+
}
|
|
251
|
+
}
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
// Método estático para facilitar el envío de logs
|
|
255
|
+
static sendToTop(message, type = 'info') {
|
|
256
|
+
if (global.loggerConsoleInstances.bottom) {
|
|
257
|
+
global.loggerConsoleInstances.bottom.sendToTop(message, type);
|
|
258
|
+
}
|
|
259
|
+
}
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
module.exports = LoggerConsole;
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Clase para manejar la configuración del ORM
|
|
3
|
+
*/
|
|
4
|
+
class Config {
|
|
5
|
+
constructor() {
|
|
6
|
+
this.data = {};
|
|
7
|
+
this.databases = {};
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Establece la configuración
|
|
12
|
+
* @param {Object} configData - Datos de configuración
|
|
13
|
+
*/
|
|
14
|
+
set(configData) {
|
|
15
|
+
this.data = configData;
|
|
16
|
+
|
|
17
|
+
if (configData.databases) {
|
|
18
|
+
this.databases = configData.databases;
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Obtiene un valor de configuración
|
|
24
|
+
* @param {string} key - Clave de configuración
|
|
25
|
+
* @returns {any} - Valor de configuración
|
|
26
|
+
*/
|
|
27
|
+
get(key) {
|
|
28
|
+
return this.data[key];
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* Obtiene la configuración de una base de datos específica
|
|
33
|
+
* @param {string} dbName - Nombre de la base de datos
|
|
34
|
+
* @returns {Object} - Configuración de la base de datos
|
|
35
|
+
*/
|
|
36
|
+
getDatabase(dbName) {
|
|
37
|
+
return this.databases[dbName] || null;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* Obtiene todas las bases de datos configuradas
|
|
42
|
+
* @returns {Object} - Todas las configuraciones de bases de datos
|
|
43
|
+
*/
|
|
44
|
+
getAllDatabases() {
|
|
45
|
+
return this.databases;
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
module.exports = Config;
|