dbcube 0.0.1 → 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 +22 -0
- package/package.json +14 -65
- 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
- package/.npmignore +0 -51
- package/CONTRIBUTING.md +0 -9
- package/LICENSE +0 -21
- package/README.md +0 -0
- package/dist/index.cjs +0 -146
- package/dist/index.cjs.map +0 -1
- package/dist/index.d.mts +0 -15
- package/dist/index.d.ts +0 -15
- package/dist/index.js +0 -116
- package/dist/index.js.map +0 -1
- package/tsup.config.ts +0 -14
|
@@ -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 fresh tables...")}`);
|
|
16
|
+
try {
|
|
17
|
+
// Verificar y leer archivos de la carpeta cubes
|
|
18
|
+
const spinner = ora('Preparando ejecución fresh 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 freshSpinner = ora(`Ejecutando fresh tables para: ${config.name} (${config.type})...`).start();
|
|
45
|
+
const schema = new Schema(config.name);
|
|
46
|
+
await schema.freshTables();
|
|
47
|
+
freshSpinner.succeed(`Fresh tables ejecutado para: ${config.name}`);
|
|
48
|
+
countTableCreated++;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
if(countTableCreated==0) {
|
|
52
|
+
console.log(`\n⚠️ ${chalk.yellow('No hay tablas para procesar.')}`);
|
|
53
|
+
} else {
|
|
54
|
+
console.log(`\n🎉 ${chalk.green(`Fresh 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 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;
|