slicejs-cli 2.2.2 → 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('
|
|
406
|
-
|
|
407
|
-
|
|
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,69 +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
|
-
const prodIndexPath = path.join(apiDir, 'index.prod.js');
|
|
38
|
-
|
|
39
|
-
// Crear backup del index original si no existe
|
|
40
|
-
if (!await fs.pathExists(backupIndexPath)) {
|
|
41
|
-
await fs.copy(originalIndexPath, backupIndexPath);
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
// Leer el contenido original
|
|
45
|
-
const originalContent = await fs.readFile(originalIndexPath, 'utf8');
|
|
46
|
-
|
|
47
|
-
// Modificar para servir desde /dist en lugar de /src
|
|
48
|
-
const productionContent = originalContent.replace(
|
|
49
|
-
/express\.static\(['"`]src['"`]\)/g,
|
|
50
|
-
"express.static('dist')"
|
|
51
|
-
).replace(
|
|
52
|
-
/express\.static\(path\.join\(__dirname,\s*['"`]\.\.\/src['"`]\)\)/g,
|
|
53
|
-
"express.static(path.join(__dirname, '../dist'))"
|
|
54
|
-
);
|
|
55
|
-
|
|
56
|
-
// Escribir archivo temporal de producción
|
|
57
|
-
await fs.writeFile(prodIndexPath, productionContent, 'utf8');
|
|
58
|
-
|
|
59
|
-
// Reemplazar index.js con versión de producción
|
|
60
|
-
await fs.copy(prodIndexPath, originalIndexPath);
|
|
61
|
-
|
|
62
|
-
Print.success('Express server configured for production mode');
|
|
63
|
-
|
|
64
|
-
return true;
|
|
65
|
-
} catch (error) {
|
|
66
|
-
Print.error(`Error configuring production server: ${error.message}`);
|
|
67
|
-
return false;
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
/**
|
|
72
|
-
* Restaura el servidor Express al modo desarrollo
|
|
73
|
-
*/
|
|
74
|
-
async function restoreDevelopmentIndexFile() {
|
|
75
|
-
try {
|
|
76
|
-
const apiDir = path.join(__dirname, '../../../../api');
|
|
77
|
-
const originalIndexPath = path.join(apiDir, 'index.js');
|
|
78
|
-
const backupIndexPath = path.join(apiDir, 'index.dev.js');
|
|
79
|
-
|
|
80
|
-
if (await fs.pathExists(backupIndexPath)) {
|
|
81
|
-
await fs.copy(backupIndexPath, originalIndexPath);
|
|
82
|
-
Print.success('Express server restored to development mode');
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
return true;
|
|
86
|
-
} catch (error) {
|
|
87
|
-
Print.error(`Error restoring development server: ${error.message}`);
|
|
88
|
-
return false;
|
|
89
|
-
}
|
|
90
|
-
}
|
|
91
|
-
|
|
92
29
|
/**
|
|
93
30
|
* Inicia el servidor Node.js
|
|
94
31
|
*/
|
|
@@ -103,7 +40,8 @@ function startNodeServer(port, mode) {
|
|
|
103
40
|
env: {
|
|
104
41
|
...process.env,
|
|
105
42
|
PORT: port,
|
|
106
|
-
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
|
|
107
45
|
}
|
|
108
46
|
});
|
|
109
47
|
|
|
@@ -112,24 +50,15 @@ function startNodeServer(port, mode) {
|
|
|
112
50
|
reject(error);
|
|
113
51
|
});
|
|
114
52
|
|
|
115
|
-
// Manejar Ctrl+C
|
|
116
|
-
process.on('SIGINT',
|
|
53
|
+
// Manejar Ctrl+C
|
|
54
|
+
process.on('SIGINT', () => {
|
|
117
55
|
Print.info('Shutting down server...');
|
|
118
|
-
|
|
119
|
-
if (mode === 'production') {
|
|
120
|
-
await restoreDevelopmentIndexFile();
|
|
121
|
-
}
|
|
122
|
-
|
|
123
56
|
serverProcess.kill('SIGINT');
|
|
124
57
|
process.exit(0);
|
|
125
58
|
});
|
|
126
59
|
|
|
127
60
|
// Manejar cierre del proceso
|
|
128
|
-
process.on('SIGTERM',
|
|
129
|
-
if (mode === 'production') {
|
|
130
|
-
await restoreDevelopmentIndexFile();
|
|
131
|
-
}
|
|
132
|
-
|
|
61
|
+
process.on('SIGTERM', () => {
|
|
133
62
|
serverProcess.kill('SIGTERM');
|
|
134
63
|
});
|
|
135
64
|
|
|
@@ -144,7 +73,7 @@ function startNodeServer(port, mode) {
|
|
|
144
73
|
}
|
|
145
74
|
|
|
146
75
|
/**
|
|
147
|
-
* Función principal para iniciar servidor
|
|
76
|
+
* Función principal para iniciar servidor - SIMPLIFICADA
|
|
148
77
|
*/
|
|
149
78
|
export default async function startServer(options = {}) {
|
|
150
79
|
const { mode = 'development', port = 3000 } = options;
|
|
@@ -159,35 +88,20 @@ export default async function startServer(options = {}) {
|
|
|
159
88
|
}
|
|
160
89
|
|
|
161
90
|
if (mode === 'production') {
|
|
162
|
-
//
|
|
91
|
+
// Verificar que existe build de producción
|
|
163
92
|
if (!await checkProductionBuild()) {
|
|
164
93
|
throw new Error('No production build found. Run "slice build" first.');
|
|
165
94
|
}
|
|
166
|
-
|
|
167
|
-
// Configurar Express para modo producción
|
|
168
|
-
const configSuccess = await createProductionIndexFile();
|
|
169
|
-
if (!configSuccess) {
|
|
170
|
-
throw new Error('Failed to configure production server');
|
|
171
|
-
}
|
|
172
|
-
|
|
173
95
|
Print.info('Production mode: serving optimized files from /dist');
|
|
174
96
|
} else {
|
|
175
|
-
// Modo desarrollo: asegurar que está en modo desarrollo
|
|
176
|
-
await restoreDevelopmentIndexFile();
|
|
177
97
|
Print.info('Development mode: serving files from /src with hot reload');
|
|
178
98
|
}
|
|
179
99
|
|
|
180
|
-
// Iniciar el servidor
|
|
100
|
+
// Iniciar el servidor - api/index.js detectará automáticamente el modo
|
|
181
101
|
await startNodeServer(port, mode);
|
|
182
102
|
|
|
183
103
|
} catch (error) {
|
|
184
104
|
Print.error(`Failed to start server: ${error.message}`);
|
|
185
|
-
|
|
186
|
-
// Limpiar en caso de error
|
|
187
|
-
if (mode === 'production') {
|
|
188
|
-
await restoreDevelopmentIndexFile();
|
|
189
|
-
}
|
|
190
|
-
|
|
191
105
|
throw error;
|
|
192
106
|
}
|
|
193
107
|
}
|