slicejs-cli 3.1.0 → 3.3.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.
Files changed (43) hide show
  1. package/.github/ISSUE_TEMPLATE/bug_report.md +29 -0
  2. package/.github/ISSUE_TEMPLATE/feature_request.md +25 -0
  3. package/.github/pull_request_template.md +22 -0
  4. package/.github/workflows/docs-render-cicd.yml +65 -0
  5. package/CODE_OF_CONDUCT.md +126 -0
  6. package/ECOSYSTEM.md +9 -0
  7. package/LICENSE +21 -0
  8. package/README.md +104 -308
  9. package/client.js +644 -557
  10. package/commands/Print.js +167 -167
  11. package/commands/Validations.js +103 -103
  12. package/commands/build/build.js +40 -40
  13. package/commands/buildProduction/buildProduction.js +579 -579
  14. package/commands/bundle/bundle.js +235 -235
  15. package/commands/createComponent/VisualComponentTemplate.js +55 -55
  16. package/commands/createComponent/createComponent.js +126 -126
  17. package/commands/deleteComponent/deleteComponent.js +77 -77
  18. package/commands/doctor/doctor.js +369 -369
  19. package/commands/getComponent/getComponent.js +747 -747
  20. package/commands/init/init.js +261 -261
  21. package/commands/listComponents/listComponents.js +175 -175
  22. package/commands/startServer/startServer.js +264 -264
  23. package/commands/startServer/watchServer.js +79 -79
  24. package/commands/types/types.js +538 -0
  25. package/commands/utils/LocalCliDelegation.js +53 -53
  26. package/commands/utils/PathHelper.js +68 -68
  27. package/commands/utils/VersionChecker.js +167 -167
  28. package/commands/utils/bundling/BundleGenerator.js +2292 -2292
  29. package/commands/utils/bundling/DependencyAnalyzer.js +933 -933
  30. package/commands/utils/updateManager.js +453 -453
  31. package/docs/superpowers/specs/2026-05-10-pwa-generate-design.md +182 -0
  32. package/package.json +46 -46
  33. package/post.js +65 -25
  34. package/tests/bundle-generator.test.js +708 -708
  35. package/tests/bundle-v2-register-output.test.js +470 -470
  36. package/tests/client-launcher-contract.test.js +211 -211
  37. package/tests/client-update-flow-contract.test.js +272 -272
  38. package/tests/dependency-analyzer.test.js +24 -24
  39. package/tests/local-cli-delegation.test.js +79 -79
  40. package/tests/postinstall-command.test.js +72 -0
  41. package/tests/types-generator.test.js +356 -0
  42. package/tests/update-manager-notifications.test.js +88 -88
  43. package/refactor.md +0 -271
@@ -0,0 +1,182 @@
1
+ # Diseno de `slice generate-pwa` (V1)
2
+
3
+ ## Objetivo
4
+
5
+ Agregar un comando dedicado de CLI, `slice generate-pwa`, que convierta un build de Slice en una PWA usable offline, con estrategia de cache configurable y exclusion explicita de dominios de backend para evitar cache accidental de APIs REST.
6
+
7
+ El comando debe ser postbundle, operar sobre `dist/` y mantener una experiencia simple de V1.
8
+
9
+ ## Alcance V1
10
+
11
+ - Nuevo comando `slice generate-pwa`.
12
+ - Ejecutar `build` automaticamente antes del proceso PWA.
13
+ - Generar `manifest.json` en `dist/`.
14
+ - Generar `sw.js` en `dist/`.
15
+ - Registrar Service Worker en el HTML de entrada de `dist`.
16
+ - Soportar estrategias: `hybrid` (default), `offline-first`, `network-first`.
17
+ - Persistir y leer configuracion desde `src/sliceConfig.json` en:
18
+ - `pwa.cache.excludeDomains`.
19
+ - Aplicar exclusion efectiva de `localhost` y `127.0.0.1` en desarrollo.
20
+
21
+ ## Fuera de alcance V1
22
+
23
+ - Exclusion por paths o headers (`excludePaths`, `excludeHeaders`).
24
+ - UI interactiva avanzada para crear iconos PWA.
25
+ - Soporte de push notifications, background sync o runtime caching avanzado por tipo de API.
26
+ - Plugin system formal; se deja preparado para evolucion futura.
27
+
28
+ ## UX del comando
29
+
30
+ ### Sintaxis
31
+
32
+ ```bash
33
+ slice generate-pwa
34
+ slice generate-pwa --strategy hybrid
35
+ slice generate-pwa --strategy offline-first
36
+ slice generate-pwa --strategy network-first
37
+ slice generate-pwa --name "Mi App" --short-name "MiApp"
38
+ ```
39
+
40
+ ### Flags V1
41
+
42
+ - `--strategy <hybrid|offline-first|network-first>` (default: `hybrid`)
43
+ - `--name <string>`
44
+ - `--short-name <string>`
45
+
46
+ ### Flujo de ejecucion
47
+
48
+ 1. Ejecuta build de produccion.
49
+ 2. Lee y normaliza configuracion PWA en `src/sliceConfig.json`.
50
+ 3. Genera manifiesto de assets para precache desde `dist/`.
51
+ 4. Genera `dist/manifest.json`.
52
+ 5. Genera `dist/sw.js` con la estrategia seleccionada.
53
+ 6. Inyecta (o asegura) registro SW en HTML de entrada de `dist`.
54
+ 7. Imprime resumen final:
55
+ - estrategia usada,
56
+ - cantidad de assets precacheados,
57
+ - dominios excluidos efectivos.
58
+
59
+ ## Configuracion en `sliceConfig.json`
60
+
61
+ Seccion minima V1:
62
+
63
+ ```json
64
+ {
65
+ "pwa": {
66
+ "cache": {
67
+ "excludeDomains": []
68
+ }
69
+ }
70
+ }
71
+ ```
72
+
73
+ Reglas:
74
+
75
+ - Si `pwa` no existe, el comando crea la seccion sin romper configuracion previa.
76
+ - `excludeDomains` acepta hosts exactos (ej: `api.midominio.com`).
77
+ - En ejecucion de desarrollo, se agregan de forma efectiva (no necesariamente persistida) `localhost` y `127.0.0.1`.
78
+
79
+ ## Arquitectura propuesta
80
+
81
+ ### Integracion CLI
82
+
83
+ - Agregar comando en `client.js`:
84
+ - `generate-pwa`
85
+ - opcion `--strategy`
86
+ - opciones de nombre para manifest
87
+
88
+ ### Modulos nuevos
89
+
90
+ - `commands/pwa/generatePwa.js`
91
+ - Orquestador del flujo completo.
92
+ - `commands/pwa/ConfigResolver.js`
93
+ - Lee/crea/normaliza `pwa.cache.excludeDomains`.
94
+ - `commands/pwa/AssetManifestBuilder.js`
95
+ - Recorre `dist/` y arma lista precache.
96
+ - `commands/pwa/ManifestGenerator.js`
97
+ - Genera `manifest.json` con defaults y overrides por flags.
98
+ - `commands/pwa/ServiceWorkerGenerator.js`
99
+ - Genera `sw.js` con estrategia seleccionada y exclusiones.
100
+
101
+ ## Diseno de cache
102
+
103
+ ### Reglas globales
104
+
105
+ - Interceptar solo requests `GET`.
106
+ - Si el host esta en `excludeDomains`, hacer `fetch` directo (sin cache).
107
+ - Versionado de cache por build id (timestamp o hash de build).
108
+ - Al activar nuevo SW, limpiar caches viejas automaticamente.
109
+
110
+ ### Estrategias
111
+
112
+ - `hybrid` (default):
113
+ - assets estaticos -> `cache-first`.
114
+ - navegacion HTML -> `network-first` con fallback offline.
115
+ - `offline-first`:
116
+ - navegacion + estaticos -> `cache-first`.
117
+ - update en background cuando haya red.
118
+ - `network-first`:
119
+ - navegacion -> `network-first`.
120
+ - estaticos precacheados como respaldo.
121
+
122
+ ## Manejo de API REST y seguridad
123
+
124
+ Para evitar cache de backend no deseado:
125
+
126
+ - Exclusion por dominio con `excludeDomains` (regla principal de V1).
127
+ - Limitar runtime cache a activos del frontend y navegacion segun estrategia.
128
+ - No cachear metodos distintos de `GET`.
129
+
130
+ Resultado: los assets del cliente se aceleran offline, pero el backend queda fuera de cache por configuracion explicita.
131
+
132
+ ## Error handling
133
+
134
+ - Si build falla, abortar `generate-pwa` con mensaje claro.
135
+ - Si `dist/` no existe tras build, abortar con diagnostico.
136
+ - Si `sliceConfig.json` es invalido, mostrar error con sugerencia de reparacion.
137
+ - Si no se puede inyectar registro SW en HTML, reportar warning y ruta objetivo.
138
+
139
+ ## Testing
140
+
141
+ ### Unit tests
142
+
143
+ - `ConfigResolver`:
144
+ - crea seccion `pwa.cache.excludeDomains` cuando no existe,
145
+ - respeta config existente.
146
+ - `AssetManifestBuilder`:
147
+ - incluye assets esperados,
148
+ - excluye archivos no aptos.
149
+ - `ServiceWorkerGenerator`:
150
+ - genera logica correcta por estrategia,
151
+ - respeta `excludeDomains`.
152
+
153
+ ### Integracion
154
+
155
+ - `slice generate-pwa` ejecuta build y crea `dist/manifest.json` + `dist/sw.js`.
156
+ - registro SW presente en HTML de salida.
157
+ - exclusiones de dominio aplicadas en codigo generado.
158
+
159
+ ### E2E manual minima
160
+
161
+ - Build + generate-pwa.
162
+ - Abrir app, validar installability (manifest).
163
+ - Apagar red, validar navegacion offline en `hybrid`.
164
+ - Verificar que requests a dominio excluido no se sirven desde cache SW.
165
+
166
+ ## Plan de evolucion (post V1)
167
+
168
+ - `excludePaths` y `excludeHeaders`.
169
+ - soporte de iconos y shortcuts PWA asistidos.
170
+ - estrategia por ruta (ej: `/api/*` network-only).
171
+ - extraer pipeline postbundle reusable para otras features.
172
+
173
+ ## Criterios de aceptacion
174
+
175
+ - Existe comando `slice generate-pwa` funcional.
176
+ - Ejecuta build antes de generar artefactos PWA.
177
+ - Genera `manifest.json` y `sw.js` en `dist/`.
178
+ - Registra SW en HTML principal de salida.
179
+ - `hybrid` es default con HTML `network-first` y fallback offline.
180
+ - Lee/escribe `pwa.cache.excludeDomains` en `src/sliceConfig.json`.
181
+ - Excluye dominios configurados del cache runtime.
182
+ - Muestra resumen final legible al usuario.
package/package.json CHANGED
@@ -1,46 +1,46 @@
1
- {
2
- "name": "slicejs-cli",
3
- "version": "3.1.0",
4
- "description": "Command client for developing web applications with Slice.js framework",
5
- "main": "client.js",
6
- "bin": {
7
- "slice": "./client.js"
8
- },
9
- "repository": {
10
- "type": "git",
11
- "url": "https://github.com/vkneider/slicejs-cli.git"
12
- },
13
- "scripts": {
14
- "test": "node --test",
15
- "postinstall": "node post.js"
16
- },
17
- "keywords": [
18
- "framework",
19
- "web",
20
- "client",
21
- "cli",
22
- "slice",
23
- "slicejs",
24
- "component",
25
- "development server"
26
- ],
27
- "author": "vkneider",
28
- "type": "module",
29
- "preferGlobal": false,
30
- "license": "ISC",
31
- "dependencies": {
32
- "@babel/parser": "^7.28.5",
33
- "@babel/traverse": "^7.28.5",
34
- "chalk": "^5.6.2",
35
- "chokidar": "^3.6.0",
36
- "clean-css": "^5.3.3",
37
- "cli-table3": "^0.6.5",
38
- "commander": "^12.0.0",
39
- "fs-extra": "^11.2.0",
40
- "html-minifier-terser": "^7.2.0",
41
- "inquirer": "^12.4.2",
42
- "ora": "^8.2.0",
43
- "slicejs-web-framework": "latest",
44
- "terser": "^5.43.1"
45
- }
46
- }
1
+ {
2
+ "name": "slicejs-cli",
3
+ "version": "3.3.0",
4
+ "description": "Command client for developing web applications with Slice.js framework",
5
+ "main": "client.js",
6
+ "bin": {
7
+ "slice": "./client.js"
8
+ },
9
+ "repository": {
10
+ "type": "git",
11
+ "url": "https://github.com/vkneider/slicejs-cli.git"
12
+ },
13
+ "scripts": {
14
+ "test": "node --test",
15
+ "postinstall": "node post.js"
16
+ },
17
+ "keywords": [
18
+ "framework",
19
+ "web",
20
+ "client",
21
+ "cli",
22
+ "slice",
23
+ "slicejs",
24
+ "component",
25
+ "development server"
26
+ ],
27
+ "author": "vkneider",
28
+ "type": "module",
29
+ "preferGlobal": false,
30
+ "license": "ISC",
31
+ "dependencies": {
32
+ "@babel/parser": "^7.28.5",
33
+ "@babel/traverse": "^7.28.5",
34
+ "chalk": "^5.6.2",
35
+ "chokidar": "^3.6.0",
36
+ "clean-css": "^5.3.3",
37
+ "cli-table3": "^0.6.5",
38
+ "commander": "^12.0.0",
39
+ "fs-extra": "^11.2.0",
40
+ "html-minifier-terser": "^7.2.0",
41
+ "inquirer": "^12.4.2",
42
+ "ora": "^8.2.0",
43
+ "slicejs-web-framework": "latest",
44
+ "terser": "^5.43.1"
45
+ }
46
+ }
package/post.js CHANGED
@@ -1,25 +1,65 @@
1
- import fs from 'fs';
2
- import { fileURLToPath } from 'url';
3
- import path from 'path';
4
- import Print from './commands/Print.js';
5
-
6
- const __filename = fileURLToPath(import.meta.url);
7
- const __dirname = path.dirname(__filename);
8
-
9
- const isGlobal = process.env.npm_config_global === 'true';
10
- const initCwd = process.env.INIT_CWD ? path.resolve(process.env.INIT_CWD) : null;
11
- const targetRoot = initCwd || path.resolve(__dirname, '../../');
12
- const projectPackageJsonPath = path.join(targetRoot, 'package.json');
13
-
14
- if (isGlobal) {
15
- console.log('⚠️ Global installation of slicejs-cli detected.');
16
- console.log(' We strongly recommend using a local installation to avoid version mismatches.');
17
- console.log(' Uninstall global: npm uninstall -g slicejs-cli');
18
- process.exit(0);
19
- }
20
-
21
- console.log('✅ slicejs-cli installed successfully.');
22
- console.log(' Add the CLI to your package.json scripts:');
23
- console.log(' "dev": "slice dev"');
24
- console.log(' Then run: npm run dev');
25
- process.exit(0);
1
+ import fs from 'fs';
2
+ import path from 'path';
3
+ import { fileURLToPath } from 'url';
4
+ import { getProjectRoot } from './commands/utils/PathHelper.js';
5
+
6
+ const __filename = fileURLToPath(import.meta.url);
7
+
8
+ const isGlobal = process.env.npm_config_global === 'true';
9
+
10
+ if (isGlobal) {
11
+ console.log('⚠️ Global installation of slicejs-cli detected.');
12
+ console.log(' We strongly recommend using a local installation to avoid version mismatches.');
13
+ console.log(' Uninstall global: npm uninstall -g slicejs-cli');
14
+ process.exit(0);
15
+ }
16
+
17
+ const projectRoot = getProjectRoot(import.meta.url);
18
+ const pkgPath = path.join(projectRoot, 'package.json');
19
+
20
+ const sliceScripts = {
21
+ 'slice:dev': 'slice dev',
22
+ 'slice:start': 'slice start',
23
+ 'slice:create': 'slice component create',
24
+ 'slice:list': 'slice component list',
25
+ 'slice:delete': 'slice component delete',
26
+ 'slice:init': 'slice init',
27
+ 'slice:get': 'slice get',
28
+ 'slice:browse': 'slice browse',
29
+ 'slice:sync': 'slice sync',
30
+ 'slice:version': 'slice version',
31
+ 'slice:update': 'slice update',
32
+ };
33
+
34
+ try {
35
+ let pkg = {};
36
+ if (fs.existsSync(pkgPath)) {
37
+ pkg = JSON.parse(fs.readFileSync(pkgPath, 'utf-8'));
38
+ } else {
39
+ pkg = {
40
+ name: path.basename(projectRoot),
41
+ version: '1.0.0',
42
+ description: 'Slice.js project',
43
+ scripts: {}
44
+ };
45
+ }
46
+
47
+ pkg.scripts = pkg.scripts || {};
48
+ let addedCount = 0;
49
+ for (const [script, command] of Object.entries(sliceScripts)) {
50
+ if (!pkg.scripts[script]) {
51
+ pkg.scripts[script] = command;
52
+ addedCount++;
53
+ }
54
+ }
55
+
56
+ fs.writeFileSync(pkgPath, JSON.stringify(pkg, null, 2), 'utf-8');
57
+ console.log(`✅ slicejs-cli installed successfully. Added ${addedCount} npm scripts to package.json.`);
58
+ console.log(' Run: npm run slice:dev');
59
+ } catch (err) {
60
+ console.log('✅ slicejs-cli installed successfully.');
61
+ console.log(' Could not auto-configure scripts:', err.message);
62
+ console.log(' Run: npx slice dev');
63
+ }
64
+
65
+ process.exit(0);