vtex-css-sanitizer-cli 1.0.7 → 1.1.0
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/.github/workflows/release.yml +1 -0
- package/PUBLISHING.md +59 -43
- package/dist/commands/fix.js +12 -4
- package/dist/utils/report-generator.js +4 -2
- package/package.json +5 -4
package/PUBLISHING.md
CHANGED
|
@@ -1,65 +1,81 @@
|
|
|
1
1
|
# Guía de Publicación y Releases
|
|
2
2
|
|
|
3
|
-
Este repositorio actúa como un monorepo que contiene
|
|
3
|
+
Este repositorio actúa como un monorepo que contiene 2 proyectos independientes que conviven juntos:
|
|
4
4
|
|
|
5
5
|
1. **CLI (Línea de comandos)**: Publicado en el registro de `npm`.
|
|
6
6
|
2. **GUI (Aplicación de Escritorio)**: Compilado y publicado en GitHub Releases a través de GitHub Actions.
|
|
7
7
|
|
|
8
|
-
A continuación se
|
|
8
|
+
A continuación se detallan los 3 escenarios posibles de publicación.
|
|
9
9
|
|
|
10
|
+
> **Nota sobre la versión de la GUI:** No es necesario actualizar manualmente la versión en `gui/package.json`. El workflow de GitHub Actions la sincroniza automáticamente desde el tag de Git antes de compilar.
|
|
10
11
|
|
|
11
|
-
|
|
12
|
+
---
|
|
13
|
+
|
|
14
|
+
## Escenario 1: Cambios en CLI y GUI
|
|
15
|
+
|
|
16
|
+
Cuando hay cambios en ambos proyectos, una sola secuencia de comandos publica todo:
|
|
17
|
+
|
|
18
|
+
```bash
|
|
19
|
+
# 1. Compilar el CLI
|
|
20
|
+
npm run build
|
|
21
|
+
|
|
22
|
+
# 2. Bump de versión (genera commit + tag automáticamente)
|
|
23
|
+
npm version patch # o minor / major según corresponda
|
|
12
24
|
|
|
13
|
-
|
|
25
|
+
# 3. Publicar CLI en npm
|
|
26
|
+
npm publish
|
|
14
27
|
|
|
15
|
-
|
|
28
|
+
# 4. Push de todo (el tag v*.*.* dispara el build de la GUI)
|
|
29
|
+
git push origin main --follow-tags
|
|
30
|
+
```
|
|
16
31
|
|
|
17
|
-
|
|
18
|
-
2. Asegúrate de compilar el código TypeScript:
|
|
19
|
-
```bash
|
|
20
|
-
npm run build
|
|
21
|
-
```
|
|
22
|
-
3. Actualiza la versión en el `package.json` de la raíz del proyecto. Puedes usar el comando de npm para que te genere el commit y el tag automáticamente:
|
|
23
|
-
```bash
|
|
24
|
-
npm version patch # Para fixes menores (ej: 1.0.4 -> 1.0.5)
|
|
25
|
-
npm version minor # Para nuevas funciones (ej: 1.0.4 -> 1.1.0)
|
|
26
|
-
npm version major # Para cambios que rompen compatibilidad (ej: 1.0.4 -> 2.0.0)
|
|
27
|
-
```
|
|
28
|
-
4. Publica el paquete en npm (requiere estar logueado previamente con `npm login` si no lo estás):
|
|
29
|
-
```bash
|
|
30
|
-
npm publish
|
|
31
|
-
```
|
|
32
|
-
5. Empuja los commits y tags generados al repositorio remoto:
|
|
33
|
-
```bash
|
|
34
|
-
git push origin main --follow-tags
|
|
35
|
-
```
|
|
32
|
+
El `npm version` crea el tag `v*.*.*` que automáticamente dispara la GitHub Action para compilar y publicar la GUI.
|
|
36
33
|
|
|
37
34
|
---
|
|
38
35
|
|
|
39
|
-
## 2
|
|
36
|
+
## Escenario 2: Solo cambios en la GUI
|
|
40
37
|
|
|
41
|
-
|
|
38
|
+
Cuando los cambios fueron exclusivamente dentro de `/gui` y no hay nada nuevo en el CLI:
|
|
42
39
|
|
|
43
|
-
|
|
40
|
+
```bash
|
|
41
|
+
# 1. Commit de los cambios
|
|
42
|
+
git add gui/
|
|
43
|
+
git commit -m "feat(gui): descripción del cambio"
|
|
44
44
|
|
|
45
|
-
|
|
45
|
+
# 2. Crear tag manualmente (la versión del tag se inyecta en gui/package.json durante el build)
|
|
46
|
+
git tag v1.0.8 # usar la versión que corresponda
|
|
47
|
+
|
|
48
|
+
# 3. Push de todo (el tag dispara el build de la GUI)
|
|
49
|
+
git push origin main --follow-tags
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
> No se ejecuta `npm publish` porque no hay cambios en el CLI.
|
|
53
|
+
|
|
54
|
+
---
|
|
46
55
|
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
56
|
+
## Escenario 3: Solo cambios en el CLI
|
|
57
|
+
|
|
58
|
+
Cuando los cambios fueron exclusivamente en `/src` y no hay nada nuevo en la GUI:
|
|
59
|
+
|
|
60
|
+
```bash
|
|
61
|
+
# 1. Compilar el CLI
|
|
62
|
+
npm run build
|
|
63
|
+
|
|
64
|
+
# 2. Bump de versión
|
|
65
|
+
npm version patch # o minor / major según corresponda
|
|
66
|
+
|
|
67
|
+
# 3. Publicar en npm
|
|
68
|
+
npm publish
|
|
69
|
+
|
|
70
|
+
# 4. Push de commits (sin --follow-tags para NO disparar el build de la GUI)
|
|
71
|
+
git push origin main
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
> **Importante:** Se usa `git push origin main` (sin `--follow-tags`) para evitar que el tag dispare un release innecesario de la GUI. Si en el futuro querés generar un release de la GUI con esta misma versión, podés hacer `git push origin v*.*.*` manualmente.
|
|
75
|
+
|
|
76
|
+
---
|
|
61
77
|
|
|
62
|
-
|
|
78
|
+
## ¿Qué ocurre después de pushear un tag?
|
|
63
79
|
|
|
64
80
|
1. GitHub intercepta el tag `v*.*.*` y automáticamente arranca la [GitHub Action programada](.github/workflows/release.yml).
|
|
65
81
|
2. La Action levanta dos entornos virtuales en los servidores de GitHub (uno con Windows y otro con Ubuntu).
|
package/dist/commands/fix.js
CHANGED
|
@@ -35,8 +35,16 @@ async function fixCommand(projectPath) {
|
|
|
35
35
|
const totalFiles = cssFiles.length;
|
|
36
36
|
for (let fileIndex = 0; fileIndex < totalFiles; fileIndex++) {
|
|
37
37
|
const filePath = cssFiles[fileIndex];
|
|
38
|
-
|
|
39
|
-
|
|
38
|
+
let originalContent;
|
|
39
|
+
let root;
|
|
40
|
+
try {
|
|
41
|
+
originalContent = await promises_1.default.readFile(filePath, 'utf-8');
|
|
42
|
+
root = postcss_1.default.parse(originalContent);
|
|
43
|
+
}
|
|
44
|
+
catch (error) {
|
|
45
|
+
console.error(`❌ Error leyendo/parseando ${path_1.default.relative(projectPath, filePath)}: ${error}`);
|
|
46
|
+
continue;
|
|
47
|
+
}
|
|
40
48
|
const candidates = (0, css_processor_1.identifyRulesForDeletion)(root, unusedSuffixes);
|
|
41
49
|
if (candidates.length === 0) {
|
|
42
50
|
continue;
|
|
@@ -50,7 +58,7 @@ async function fixCommand(projectPath) {
|
|
|
50
58
|
const rule = candidates[i];
|
|
51
59
|
const relativePath = path_1.default.relative(projectPath, filePath);
|
|
52
60
|
const ruleAsString = rule.toString();
|
|
53
|
-
console.
|
|
61
|
+
console.log('\n==================================================================');
|
|
54
62
|
console.log(`[ Progreso: Archivo ${fileIndex + 1} de ${totalFiles} ]`);
|
|
55
63
|
console.log(`------------------------------------------------------------------`);
|
|
56
64
|
console.log(`Revisando Archivo: ${relativePath}`);
|
|
@@ -98,7 +106,7 @@ async function fixCommand(projectPath) {
|
|
|
98
106
|
deletedRules.push(...fileDeletedRules);
|
|
99
107
|
keptRules.push(...fileKeptRules);
|
|
100
108
|
}
|
|
101
|
-
console.
|
|
109
|
+
console.log('\n==================================================================');
|
|
102
110
|
if (totalRulesRemoved > 0) {
|
|
103
111
|
console.log(`\n✅ Proceso completado. Se eliminaron un total de ${totalRulesRemoved} reglas CSS.`);
|
|
104
112
|
}
|
|
@@ -13,13 +13,15 @@ async function ensureReportDirectory(projectPath) {
|
|
|
13
13
|
await promises_1.default.mkdir(reportDir, { recursive: true }); // recursive: true evita errores si el dir ya existe
|
|
14
14
|
return reportDir;
|
|
15
15
|
}
|
|
16
|
-
// --- Helper para obtener la fecha en formato YYYY-MM-
|
|
16
|
+
// --- Helper para obtener la fecha en formato YYYY-MM-DD_HHmm ---
|
|
17
17
|
function getFormattedDate() {
|
|
18
18
|
const date = new Date();
|
|
19
19
|
const year = date.getFullYear();
|
|
20
20
|
const month = (date.getMonth() + 1).toString().padStart(2, '0');
|
|
21
21
|
const day = date.getDate().toString().padStart(2, '0');
|
|
22
|
-
|
|
22
|
+
const hours = date.getHours().toString().padStart(2, '0');
|
|
23
|
+
const minutes = date.getMinutes().toString().padStart(2, '0');
|
|
24
|
+
return `${year}-${month}-${day}_${hours}${minutes}`;
|
|
23
25
|
}
|
|
24
26
|
// --- Generador para el informe de 'analyze' ---
|
|
25
27
|
async function generateAnalysisReport(projectPath, unusedCss, unusedBlockClasses, usedCssSuffixesMap, declaredBlockClassesMap) {
|
package/package.json
CHANGED
|
@@ -1,15 +1,16 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "vtex-css-sanitizer-cli",
|
|
3
|
-
"version": "1.0
|
|
3
|
+
"version": "1.1.0",
|
|
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": {
|
|
7
7
|
"vtex-css-sanitizer": "dist/index.js"
|
|
8
8
|
},
|
|
9
9
|
"scripts": {
|
|
10
|
-
"build": "
|
|
10
|
+
"build": "tsc",
|
|
11
11
|
"start": "ts-node src/index.ts",
|
|
12
|
-
"dev": "npm run build && node dist/index.js"
|
|
12
|
+
"dev": "npm run build && node dist/index.js",
|
|
13
|
+
"prepublishOnly": "npm run build"
|
|
13
14
|
},
|
|
14
15
|
"keywords": [
|
|
15
16
|
"vtex",
|
|
@@ -20,7 +21,6 @@
|
|
|
20
21
|
"author": "Elias Daniel Emanuele",
|
|
21
22
|
"license": "ISC",
|
|
22
23
|
"dependencies": {
|
|
23
|
-
"@types/glob": "^8.1.0",
|
|
24
24
|
"commander": "^11.0.0",
|
|
25
25
|
"glob": "^8.1.0",
|
|
26
26
|
"jsonc-parser": "^3.2.0",
|
|
@@ -28,6 +28,7 @@
|
|
|
28
28
|
"prompts": "^2.4.2"
|
|
29
29
|
},
|
|
30
30
|
"devDependencies": {
|
|
31
|
+
"@types/glob": "^8.1.0",
|
|
31
32
|
"@types/node": "^20.5.7",
|
|
32
33
|
"@types/prompts": "^2.4.9",
|
|
33
34
|
"ts-node": "^10.9.1",
|