utn-cli 2.0.76 → 2.0.77

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.
Files changed (2) hide show
  1. package/commands/db.js +25 -1
  2. package/package.json +1 -1
package/commands/db.js CHANGED
@@ -92,16 +92,40 @@ export async function updateDb(opciones = { cerrarAlFinalizar: true }) {
92
92
  process.exit(1);
93
93
  }
94
94
 
95
+ // Intentar recuperar el nombre del repositorio/base de datos antes de sobrescribir docker-compose.yml
96
+ const rutaCompose = path.join(directorioDestino, 'docker-compose.yml');
97
+ const rutaEstructuraDestino = path.join(directorioDestino, 'docker-scripts/1-crear estructura.sql');
98
+ let nombreRepositorio = '';
99
+
100
+ if (fs.existsSync(rutaCompose)) {
101
+ const contenidoCompose = fs.readFileSync(rutaCompose, 'utf-8');
102
+ const matchCompose = contenidoCompose.match(/^\s*(\S+):\s*\n\s*image:\s*mariadb:lts/m);
103
+ if (matchCompose && matchCompose[1]) {
104
+ nombreRepositorio = matchCompose[1];
105
+ }
106
+ }
107
+
108
+ if (!nombreRepositorio && fs.existsSync(rutaEstructuraDestino)) {
109
+ const contenidoEstructura = fs.readFileSync(rutaEstructuraDestino, 'utf-8');
110
+ const matchDb = contenidoEstructura.match(/CREATE DATABASE `(.+?)`/);
111
+ if (matchDb && matchDb[1]) {
112
+ nombreRepositorio = matchDb[1];
113
+ }
114
+ }
115
+
95
116
  // Copiar todos los archivos excepto la estructura base
96
117
  copiarDirectorios(directoriodePlantillas, directorioDestino, archivosAExcluir);
97
118
 
119
+ if (nombreRepositorio) {
120
+ reemplazarContenidoEnArchivo(rutaCompose, 'NOMBRE_DEL_REPOSITORIO_DE_BASE_DE_DATOS', nombreRepositorio);
121
+ }
122
+
98
123
  const gitignorePath = path.join(directorioDestino, 'cumulodb-scripts/gitignore');
99
124
  if (fs.existsSync(gitignorePath)) {
100
125
  fs.renameSync(gitignorePath, path.join(directorioDestino, 'cumulodb-scripts/.gitignore'));
101
126
  }
102
127
 
103
128
  // Lógica de merge para 1-crear estructura.sql
104
- const rutaEstructuraDestino = path.join(directorioDestino, 'docker-scripts/1-crear estructura.sql');
105
129
  const rutaEstructuraFuente = path.join(directoriodePlantillas, 'docker-scripts/1-crear estructura.sql');
106
130
 
107
131
  if (fs.existsSync(rutaEstructuraDestino) && fs.existsSync(rutaEstructuraFuente)) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "utn-cli",
3
- "version": "2.0.76",
3
+ "version": "2.0.77",
4
4
  "description": "Herramienta CLI unificada para la gestión de plantillas en SIGU.",
5
5
  "main": "index.js",
6
6
  "type": "module",