slicejs-cli 2.2.3 → 2.2.4

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.
@@ -377,7 +377,7 @@ export async function serveProductionBuild(port = 3001) {
377
377
  }
378
378
 
379
379
  /**
380
- * Comando build con opciones
380
+ * Comando build con opciones - CORREGIDO
381
381
  */
382
382
  export async function buildCommand(options = {}) {
383
383
  // Verificar dependencias necesarias
@@ -400,17 +400,18 @@ export async function buildCommand(options = {}) {
400
400
  // Build completo
401
401
  const success = await buildProduction(options);
402
402
 
403
+ // Solo mostrar mensaje informativo, no ejecutar servidor automáticamente
403
404
  if (success && options.preview) {
404
405
  Print.newLine();
405
- Print.info('Starting preview server...');
406
- setTimeout(() => {
407
- serveProductionBuild(options.port);
408
- }, 1000);
406
+ Print.info(' Build completed successfully!');
407
+ Print.info('💡 Use "slice build --serve" to preview the production build');
408
+ Print.info('💡 Or "slice start" to start production server');
409
409
  }
410
410
 
411
411
  return success;
412
412
  }
413
413
 
414
+
414
415
  /**
415
416
  * Verifica que las dependencias de build estén instaladas en el CLI
416
417
  */
@@ -26,65 +26,6 @@ async function checkDevelopmentStructure() {
26
26
  return (await fs.pathExists(srcDir)) && (await fs.pathExists(apiDir));
27
27
  }
28
28
 
29
- /**
30
- * Modifica temporalmente el servidor Express para modo producción
31
- */
32
- async function createProductionIndexFile() {
33
- try {
34
- const apiDir = path.join(__dirname, '../../../../api');
35
- const originalIndexPath = path.join(apiDir, 'index.js');
36
- const backupIndexPath = path.join(apiDir, 'index.dev.js');
37
-
38
- // Crear backup del index original si no existe
39
- if (!await fs.pathExists(backupIndexPath)) {
40
- await fs.copy(originalIndexPath, backupIndexPath);
41
- }
42
-
43
- // Leer el contenido original
44
- const originalContent = await fs.readFile(originalIndexPath, 'utf8');
45
-
46
- // Modificar para servir desde /dist en lugar de /src
47
- const productionContent = originalContent.replace(
48
- /express\.static\(['"`]src['"`]\)/g,
49
- "express.static('dist')"
50
- ).replace(
51
- /express\.static\(path\.join\(__dirname,\s*['"`]\.\.\/src['"`]\)\)/g,
52
- "express.static(path.join(__dirname, '../dist'))"
53
- );
54
-
55
- // Escribir la versión modificada directamente
56
- await fs.writeFile(originalIndexPath, productionContent, 'utf8');
57
-
58
- Print.success('Express server configured for production mode');
59
-
60
- return true;
61
- } catch (error) {
62
- Print.error(`Error configuring production server: ${error.message}`);
63
- return false;
64
- }
65
- }
66
-
67
- /**
68
- * Restaura el servidor Express al modo desarrollo
69
- */
70
- async function restoreDevelopmentIndexFile() {
71
- try {
72
- const apiDir = path.join(__dirname, '../../../../api');
73
- const originalIndexPath = path.join(apiDir, 'index.js');
74
- const backupIndexPath = path.join(apiDir, 'index.dev.js');
75
-
76
- if (await fs.pathExists(backupIndexPath)) {
77
- await fs.copy(backupIndexPath, originalIndexPath);
78
- Print.success('Express server restored to development mode');
79
- }
80
-
81
- return true;
82
- } catch (error) {
83
- Print.error(`Error restoring development server: ${error.message}`);
84
- return false;
85
- }
86
- }
87
-
88
29
  /**
89
30
  * Inicia el servidor Node.js
90
31
  */
@@ -99,7 +40,8 @@ function startNodeServer(port, mode) {
99
40
  env: {
100
41
  ...process.env,
101
42
  PORT: port,
102
- NODE_ENV: mode === 'production' ? 'production' : 'development'
43
+ NODE_ENV: mode === 'production' ? 'production' : 'development',
44
+ SLICE_CLI_MODE: 'true' // Flag para que api/index.js sepa que viene del CLI
103
45
  }
104
46
  });
105
47
 
@@ -108,24 +50,15 @@ function startNodeServer(port, mode) {
108
50
  reject(error);
109
51
  });
110
52
 
111
- // Manejar Ctrl+C para limpiar archivos temporales
112
- process.on('SIGINT', async () => {
53
+ // Manejar Ctrl+C
54
+ process.on('SIGINT', () => {
113
55
  Print.info('Shutting down server...');
114
-
115
- if (mode === 'production') {
116
- await restoreDevelopmentIndexFile();
117
- }
118
-
119
56
  serverProcess.kill('SIGINT');
120
57
  process.exit(0);
121
58
  });
122
59
 
123
60
  // Manejar cierre del proceso
124
- process.on('SIGTERM', async () => {
125
- if (mode === 'production') {
126
- await restoreDevelopmentIndexFile();
127
- }
128
-
61
+ process.on('SIGTERM', () => {
129
62
  serverProcess.kill('SIGTERM');
130
63
  });
131
64
 
@@ -140,7 +73,7 @@ function startNodeServer(port, mode) {
140
73
  }
141
74
 
142
75
  /**
143
- * Función principal para iniciar servidor
76
+ * Función principal para iniciar servidor - SIMPLIFICADA
144
77
  */
145
78
  export default async function startServer(options = {}) {
146
79
  const { mode = 'development', port = 3000 } = options;
@@ -155,35 +88,20 @@ export default async function startServer(options = {}) {
155
88
  }
156
89
 
157
90
  if (mode === 'production') {
158
- // Modo producción: verificar build y configurar servidor
91
+ // Verificar que existe build de producción
159
92
  if (!await checkProductionBuild()) {
160
93
  throw new Error('No production build found. Run "slice build" first.');
161
94
  }
162
-
163
- // Configurar Express para modo producción (modifica api/index.js temporalmente)
164
- const configSuccess = await createProductionIndexFile();
165
- if (!configSuccess) {
166
- throw new Error('Failed to configure production server');
167
- }
168
-
169
95
  Print.info('Production mode: serving optimized files from /dist');
170
96
  } else {
171
- // Modo desarrollo: asegurar que está en modo desarrollo
172
- await restoreDevelopmentIndexFile();
173
97
  Print.info('Development mode: serving files from /src with hot reload');
174
98
  }
175
99
 
176
- // Iniciar el servidor (solo uno)
100
+ // Iniciar el servidor - api/index.js detectará automáticamente el modo
177
101
  await startNodeServer(port, mode);
178
102
 
179
103
  } catch (error) {
180
104
  Print.error(`Failed to start server: ${error.message}`);
181
-
182
- // Limpiar en caso de error
183
- if (mode === 'production') {
184
- await restoreDevelopmentIndexFile();
185
- }
186
-
187
105
  throw error;
188
106
  }
189
107
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "slicejs-cli",
3
- "version": "2.2.3",
3
+ "version": "2.2.4",
4
4
  "description": "Command client for developing web applications with Slice.js framework",
5
5
  "main": "client.js",
6
6
  "scripts": {