vtex-css-sanitizer-cli 1.0.1 → 1.0.3

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/README.md CHANGED
@@ -33,7 +33,7 @@ Estos restos de código aumentan el tamaño de los bundles y hacen que la base d
33
33
  Para usar esta herramienta en cualquier proyecto de tu máquina, instálala globalmente:
34
34
 
35
35
  ```bash
36
- npm install -g vtex-css-sanitizer
36
+ npm install -g vtex-css-sanitizer-cli
37
37
  ```
38
38
 
39
39
  ### 🚀 Uso
@@ -41,13 +41,16 @@ async function fixCommand(projectPath) {
41
41
  if (candidates.length === 0) {
42
42
  continue;
43
43
  }
44
+ // Arreglos temporales para los cambios del archivo actual
45
+ const fileDeletedRules = [];
46
+ const fileKeptRules = [];
44
47
  let rulesRemovedInFile = 0;
48
+ let userCancelled = false;
45
49
  for (let i = 0; i < candidates.length; i++) {
46
50
  const rule = candidates[i];
47
51
  const relativePath = path_1.default.relative(projectPath, filePath);
48
52
  const ruleAsString = rule.toString();
49
53
  console.clear();
50
- // Se muestra el progreso general y el del archivo actual
51
54
  console.log(`[ Progreso: Archivo ${fileIndex + 1} de ${totalFiles} ]`);
52
55
  console.log(`------------------------------------------------------------------`);
53
56
  console.log(`Revisando Archivo: ${relativePath}`);
@@ -63,25 +66,31 @@ async function fixCommand(projectPath) {
63
66
  });
64
67
  if (response.shouldDelete === undefined) {
65
68
  console.log('\n🛑 Proceso de limpieza cancelado por el usuario.');
66
- // Antes de salir, generamos el informe con lo que se haya hecho hasta ahora
67
- if (deletedRules.length > 0 || keptRules.length > 0) {
68
- await (0, report_generator_1.generateFixReport)(projectPath, deletedRules, keptRules);
69
- console.log(`\n📄 Informe parcial de limpieza guardado.`);
70
- }
71
- return;
69
+ userCancelled = true;
70
+ break; // Sale del bucle de reglas para este archivo
72
71
  }
73
72
  if (response.shouldDelete) {
73
+ // Se opera sobre la regla, pero el reporte se guarda temporalmente
74
+ fileDeletedRules.push({ rule: ruleAsString, filePath });
74
75
  rule.remove();
75
76
  rulesRemovedInFile++;
76
- deletedRules.push({ rule: ruleAsString, filePath });
77
77
  console.log('\x1b[31m%s\x1b[0m', '🗑️ Regla eliminada.');
78
78
  }
79
79
  else {
80
- keptRules.push({ rule: ruleAsString, filePath });
80
+ fileKeptRules.push({ rule: ruleAsString, filePath });
81
81
  console.log('\x1b[32m%s\x1b[0m', '👍 Regla conservada.');
82
82
  }
83
83
  console.log('------------------------------------------------------------------');
84
84
  }
85
+ // Si el usuario canceló, se detiene todo el proceso.
86
+ if (userCancelled) {
87
+ if (deletedRules.length > 0 || keptRules.length > 0) {
88
+ await (0, report_generator_1.generateFixReport)(projectPath, deletedRules, keptRules);
89
+ console.log(`\n📄 Informe parcial de limpieza guardado con los cambios de los archivos **anteriores**.`);
90
+ }
91
+ return;
92
+ }
93
+ // Si se completó el archivo y hubo cambios, se escriben en el disco.
85
94
  if (rulesRemovedInFile > 0) {
86
95
  const newContent = root.toString();
87
96
  await promises_1.default.writeFile(filePath, newContent, 'utf-8');
@@ -89,6 +98,9 @@ async function fixCommand(projectPath) {
89
98
  totalRulesRemoved += rulesRemovedInFile;
90
99
  await (0, prompts_1.default)({ type: 'invisible', name: 'continue', message: 'Presiona Enter para continuar con el siguiente archivo...' });
91
100
  }
101
+ // Solo si el archivo se procesó por completo, se añaden las acciones al reporte final.
102
+ deletedRules.push(...fileDeletedRules);
103
+ keptRules.push(...fileKeptRules);
92
104
  }
93
105
  console.clear();
94
106
  if (totalRulesRemoved > 0) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vtex-css-sanitizer-cli",
3
- "version": "1.0.1",
3
+ "version": "1.0.3",
4
4
  "description": "Herramienta CLI para eliminar CSS y blockClass no utilizados en proyectos VTEX IO.",
5
5
  "main": "dist/index.js",
6
6
  "bin": {