siesa-agents 2.1.5 → 2.1.6

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/bin/install.js +67 -0
  2. package/package.json +1 -1
package/bin/install.js CHANGED
@@ -22,6 +22,9 @@ class SiesaBmadInstaller {
22
22
  this.targetDir = process.cwd();
23
23
  // Intentar múltiples ubicaciones posibles para el paquete
24
24
  this.packageDir = this.findPackageDir();
25
+
26
+ // Almacenamiento temporal para contenido de archivos ignorados
27
+ this.preservedContent = new Map();
25
28
  }
26
29
 
27
30
  showBanner() {
@@ -174,6 +177,10 @@ class SiesaBmadInstaller {
174
177
  }
175
178
 
176
179
  async promptUser(modifiedFiles) {
180
+
181
+ const hasNonIgnoredFiles = modifiedFiles.some(file => file.is_ignored == false)
182
+ if (!hasNonIgnoredFiles) return '2'
183
+
177
184
  console.log('\n⚠️ Se detectaron archivos modificados:');
178
185
 
179
186
  // Agrupar por carpeta
@@ -396,6 +403,9 @@ class SiesaBmadInstaller {
396
403
  await this.performUpdateWithBackups();
397
404
  } else {
398
405
  // Si no hay backups, hacer actualización normal (remover y copiar)
406
+ // Pero primero preservar archivos ignorados
407
+ await this.preserveIgnoredFiles();
408
+
399
409
  for (const mapping of this.folderMappings) {
400
410
  const targetPath = path.join(this.targetDir, mapping.target);
401
411
 
@@ -406,7 +416,64 @@ class SiesaBmadInstaller {
406
416
 
407
417
  // Realizar instalación nueva
408
418
  await this.performInstallation();
419
+
420
+ // Restaurar archivos ignorados
421
+ await this.restoreIgnoredFiles();
422
+ }
423
+ }
424
+
425
+ async preserveIgnoredFiles() {
426
+ console.log('🔒 Preservando archivos de configuración...');
427
+
428
+ for (const mapping of this.folderMappings) {
429
+ const targetFolderPath = path.join(this.targetDir, mapping.target);
430
+
431
+ if (!fs.existsSync(targetFolderPath)) {
432
+ continue;
433
+ }
434
+
435
+ for (const ignoredFile of this.ignoredFiles) {
436
+ const filePath = path.join(targetFolderPath, ignoredFile);
437
+
438
+ if (fs.existsSync(filePath)) {
439
+ try {
440
+ const content = await fs.readFile(filePath, 'utf8');
441
+ const key = `${mapping.target}/${ignoredFile}`;
442
+ this.preservedContent.set(key, content);
443
+ console.log(`✓ Preservando: ${ignoredFile}`);
444
+ } catch (error) {
445
+ console.warn(`⚠️ Error leyendo ${ignoredFile}: ${error.message}`);
446
+ }
447
+ }
448
+ }
449
+ }
450
+ }
451
+
452
+ async restoreIgnoredFiles() {
453
+ if (this.preservedContent.size === 0) {
454
+ return;
455
+ }
456
+
457
+ console.log('🔄 Restaurando archivos de configuración...');
458
+
459
+ for (const [key, content] of this.preservedContent) {
460
+ const [targetFolder, ...filePathParts] = key.split('/');
461
+ const filePath = path.join(this.targetDir, targetFolder, ...filePathParts);
462
+
463
+ try {
464
+ // Asegurar que el directorio existe
465
+ await fs.ensureDir(path.dirname(filePath));
466
+
467
+ // Restaurar el contenido
468
+ await fs.writeFile(filePath, content, 'utf8');
469
+ console.log(`✓ Restaurado: ${filePathParts.join('/')}`);
470
+ } catch (error) {
471
+ console.warn(`⚠️ Error restaurando ${filePathParts.join('/')}: ${error.message}`);
472
+ }
409
473
  }
474
+
475
+ // Limpiar el mapa después de restaurar
476
+ this.preservedContent.clear();
410
477
  }
411
478
 
412
479
  showPostInstallMessage() {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "siesa-agents",
3
- "version": "2.1.5",
3
+ "version": "2.1.6",
4
4
  "description": "Paquete para instalar y configurar agentes SIESA en tu proyecto",
5
5
  "main": "index.js",
6
6
  "bin": {