utn-cli 2.0.74 → 2.0.75

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.
@@ -190,25 +190,26 @@ function mergeRutasBackend(rutaDestino, rutaFuente) {
190
190
  let contenidoDestino = fs.readFileSync(rutaDestino, 'utf-8');
191
191
  const contenidoFuente = fs.readFileSync(rutaFuente, 'utf-8');
192
192
 
193
- // Extraer requires de la fuente
194
- const requiresFuente = contenidoFuente.match(/const .* = require\(.*\);/g) || [];
193
+ // Extraer requires de la fuente (solo líneas no comentadas)
194
+ const requiresFuente = contenidoFuente.match(/^\s*const .* = require\(.*\);/gm) || [];
195
195
  requiresFuente.forEach(req => {
196
- if (!contenidoDestino.includes(req)) {
196
+ if (!contenidoDestino.includes(req.trim())) {
197
197
  // Insertar el nuevo require antes de la función asignarRutasAExpress
198
- contenidoDestino = contenidoDestino.replace(/function asignarRutasAExpress/, `${req}\nfunction asignarRutasAExpress`);
198
+ contenidoDestino = contenidoDestino.replace(/function asignarRutasAExpress/, `${req.trim()}\nfunction asignarRutasAExpress`);
199
199
  }
200
200
  });
201
201
 
202
- // Extraer app.use de la fuente
203
- const usesFuente = contenidoFuente.match(/app\.use\(.*\);/g) || [];
202
+ // Extraer app.use de la fuente (solo líneas no comentadas)
203
+ const usesFuente = contenidoFuente.match(/^\s*app\.use\(.*\);/gm) || [];
204
204
  usesFuente.forEach(use => {
205
+ const useTrimmed = use.trim();
205
206
  // Limpiar espacios para comparar
206
- const useNormalizado = use.replace(/\s/g, '');
207
+ const useNormalizado = useTrimmed.replace(/\s/g, '');
207
208
  const contenidoDestinoNormalizado = contenidoDestino.replace(/\s/g, '');
208
209
 
209
210
  if (!contenidoDestinoNormalizado.includes(useNormalizado)) {
210
211
  // Insertar el nuevo app.use al final de la función asignarRutasAExpress
211
- contenidoDestino = contenidoDestino.replace(/(function asignarRutasAExpress\(app\) \{[\s\S]*?)(\n\})/, `$1 ${use}$2`);
212
+ contenidoDestino = contenidoDestino.replace(/(function asignarRutasAExpress\(app\) \{[\s\S]*?)(\n\})/, `$1 ${useTrimmed}$2`);
212
213
  }
213
214
  });
214
215
 
@@ -84,12 +84,13 @@ function mergeRoutesFrontend(rutaDestino, rutaFuente) {
84
84
  let contenidoDestino = fs.readFileSync(rutaDestino, 'utf-8');
85
85
  const contenidoFuente = fs.readFileSync(rutaFuente, 'utf-8');
86
86
 
87
- // Extraer imports de la fuente
88
- const importsFuente = contenidoFuente.match(/import \{ .* \} from '.*';/g) || [];
87
+ // Extraer imports de la fuente (solo líneas no comentadas)
88
+ const importsFuente = contenidoFuente.match(/^\s*import \{ .* \} from '.*';/gm) || [];
89
89
  importsFuente.forEach(imp => {
90
- if (!contenidoDestino.includes(imp)) {
90
+ const impTrimmed = imp.trim();
91
+ if (!contenidoDestino.includes(impTrimmed)) {
91
92
  // Insertar el nuevo import al inicio del archivo
92
- contenidoDestino = imp + '\n' + contenidoDestino;
93
+ contenidoDestino = impTrimmed + '\n' + contenidoDestino;
93
94
  }
94
95
  });
95
96
 
@@ -97,13 +98,21 @@ function mergeRoutesFrontend(rutaDestino, rutaFuente) {
97
98
  const matchFuente = contenidoFuente.match(/export const routes: Routes = \[\s*([\s\S]*?)\s*\];/);
98
99
  if (matchFuente) {
99
100
  const rutasFuenteStr = matchFuente[1];
100
- // Intentar separar por llaves de objetos { path: ... }
101
- const rutasFuenteArray = rutasFuenteStr.split(/},\s*{/).map((r, i, a) => {
102
- let res = r.trim();
103
- if (!res.startsWith('{')) res = '{ ' + res;
104
- if (!res.endsWith('}')) res = res + ' }';
105
- return res;
106
- });
101
+
102
+ // Mejorar la separación de objetos de ruta, ignorando líneas comentadas
103
+ const rutasFuenteArray = rutasFuenteStr.split('\n')
104
+ .map(linea => linea.trim())
105
+ .filter(linea => linea.length > 0 && !linea.startsWith('//'))
106
+ .join('\n')
107
+ .split(/},\s*{/)
108
+ .map((r, i, a) => {
109
+ let res = r.trim();
110
+ if (!res.startsWith('{')) res = '{ ' + res;
111
+ if (!res.endsWith('}')) res = res + ' }';
112
+ // Quitar comas sobrantes al final de cada objeto individual si existen
113
+ if (res.endsWith('},')) res = res.slice(0, -1);
114
+ return res;
115
+ });
107
116
 
108
117
  rutasFuenteArray.forEach(ruta => {
109
118
  // Limpiar espacios para comparar
@@ -117,9 +126,9 @@ function mergeRoutesFrontend(rutaDestino, rutaFuente) {
117
126
  const textoAntesDeCierre = contenidoDestino.slice(0, cierreArray).trimEnd();
118
127
  const necesitaComa = !textoAntesDeCierre.endsWith(',') && !textoAntesDeCierre.endsWith('[');
119
128
 
120
- contenidoDestino = contenidoDestino.slice(0, cierreArray) +
121
- (necesitaComa ? ',' : '') + '\n ' +
122
- ruta + '\n' +
129
+ contenidoDestino = contenidoDestino.slice(0, cierreArray).trimEnd() +
130
+ (necesitaComa ? ',\n' : '\n') +
131
+ ' ' + ruta + '\n' +
123
132
  contenidoDestino.slice(cierreArray);
124
133
  }
125
134
  }
@@ -364,13 +373,13 @@ function actualizarArchivosConfiguracion(nombreClase, nombreRuta, titulo, descri
364
373
  if (!contenidoRoutes.includes(`path: '${nombreRuta}'`)) {
365
374
  const cierreArray = contenidoRoutes.lastIndexOf('];');
366
375
  if (cierreArray !== -1) {
367
- const nuevaRuta = ` { path: '${nombreRuta}', component: ${nombreClase} },`;
376
+ const nuevaRuta = `{ path: '${nombreRuta}', component: ${nombreClase} }`;
368
377
  const textoAntesDeCierre = contenidoRoutes.slice(0, cierreArray).trimEnd();
369
378
  const necesitaComa = !textoAntesDeCierre.endsWith(',') && !textoAntesDeCierre.endsWith('[');
370
379
 
371
- contenidoRoutes = contenidoRoutes.slice(0, cierreArray) +
372
- (necesitaComa ? ',' : '') + '\n' +
373
- nuevaRuta + '\n' +
380
+ contenidoRoutes = contenidoRoutes.slice(0, cierreArray).trimEnd() +
381
+ (necesitaComa ? ',\n' : '\n') +
382
+ ' ' + nuevaRuta + '\n' +
374
383
  contenidoRoutes.slice(cierreArray);
375
384
 
376
385
  fs.writeFileSync(rutaRoutes, contenidoRoutes);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "utn-cli",
3
- "version": "2.0.74",
3
+ "version": "2.0.75",
4
4
  "description": "Herramienta CLI unificada para la gestión de plantillas en SIGU.",
5
5
  "main": "index.js",
6
6
  "type": "module",