slicejs-cli 2.2.3 → 2.2.5
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.
|
@@ -11,29 +11,50 @@ import Print from '../Print.js';
|
|
|
11
11
|
const __dirname = path.dirname(fileURLToPath(import.meta.url));
|
|
12
12
|
|
|
13
13
|
/**
|
|
14
|
-
* Opciones de minificación para diferentes tipos de archivos
|
|
14
|
+
* Opciones de minificación para diferentes tipos de archivos - CORREGIDAS
|
|
15
15
|
*/
|
|
16
16
|
const getMinificationOptions = () => ({
|
|
17
17
|
js: {
|
|
18
18
|
compress: {
|
|
19
19
|
dead_code: true,
|
|
20
|
-
drop_console:
|
|
20
|
+
drop_console: false, // NO remover console.log para evitar problemas
|
|
21
21
|
drop_debugger: true,
|
|
22
|
-
pure_funcs: [
|
|
23
|
-
passes:
|
|
22
|
+
pure_funcs: [], // NO remover funciones específicas
|
|
23
|
+
passes: 1, // Reducir pasadas para ser menos agresivo
|
|
24
|
+
keep_classnames: true, // IMPORTANTE: Preservar nombres de clases
|
|
25
|
+
keep_fnames: true // IMPORTANTE: Preservar nombres de funciones
|
|
24
26
|
},
|
|
25
27
|
mangle: {
|
|
26
|
-
toplevel:
|
|
27
|
-
|
|
28
|
+
toplevel: false, // NO hacer mangle a nivel superior
|
|
29
|
+
keep_classnames: true, // Preservar nombres de clases
|
|
30
|
+
keep_fnames: true, // Preservar nombres de funciones
|
|
31
|
+
reserved: [
|
|
32
|
+
// Framework core
|
|
33
|
+
'Slice', 'Controller', 'StylesManager', 'ThemeManager', 'Logger',
|
|
34
|
+
// Métodos importantes
|
|
35
|
+
'slice', 'build', 'init', 'attachTemplate', 'getComponent',
|
|
36
|
+
// Eventos y propiedades de componentes
|
|
37
|
+
'constructor', 'connectedCallback', 'disconnectedCallback',
|
|
38
|
+
'attributeChangedCallback', 'adoptedCallback',
|
|
39
|
+
// Variables comunes en componentes
|
|
40
|
+
'componentName', 'props', 'options', 'value', 'disabled',
|
|
41
|
+
// HTML Elements y DOM
|
|
42
|
+
'HTMLElement', 'customElements', 'define', 'querySelector',
|
|
43
|
+
'querySelectorAll', 'addEventListener', 'removeEventListener',
|
|
44
|
+
// Métodos de componentes Slice.js
|
|
45
|
+
'setComponentProps', 'componentCategories', 'templates',
|
|
46
|
+
'activeComponents', 'classes', 'requestedStyles'
|
|
47
|
+
]
|
|
28
48
|
},
|
|
29
49
|
output: {
|
|
30
50
|
comments: false,
|
|
31
|
-
beautify: false
|
|
51
|
+
beautify: false,
|
|
52
|
+
keep_quoted_props: true // Preservar propiedades entre comillas
|
|
32
53
|
},
|
|
33
|
-
toplevel:
|
|
54
|
+
toplevel: false // NO optimizar a nivel superior
|
|
34
55
|
},
|
|
35
56
|
css: {
|
|
36
|
-
level:
|
|
57
|
+
level: 1, // Optimización moderada en lugar de agresiva
|
|
37
58
|
returnPromise: false
|
|
38
59
|
},
|
|
39
60
|
html: {
|
|
@@ -41,20 +62,38 @@ const getMinificationOptions = () => ({
|
|
|
41
62
|
removeComments: true,
|
|
42
63
|
removeRedundantAttributes: true,
|
|
43
64
|
removeEmptyAttributes: true,
|
|
44
|
-
minifyCSS:
|
|
45
|
-
minifyJS:
|
|
65
|
+
minifyCSS: false, // NO minificar CSS inline para evitar problemas
|
|
66
|
+
minifyJS: false, // NO minificar JS inline para evitar problemas
|
|
46
67
|
useShortDoctype: true,
|
|
47
|
-
removeAttributeQuotes:
|
|
48
|
-
removeOptionalTags:
|
|
68
|
+
removeAttributeQuotes: false, // Mantener comillas en atributos
|
|
69
|
+
removeOptionalTags: false // Mantener tags opcionales
|
|
49
70
|
}
|
|
50
71
|
});
|
|
51
72
|
|
|
52
73
|
/**
|
|
53
|
-
* Minifica un archivo JavaScript
|
|
74
|
+
* Minifica un archivo JavaScript de forma segura
|
|
54
75
|
*/
|
|
55
76
|
async function minifyJavaScript(content, filename) {
|
|
56
77
|
try {
|
|
57
|
-
|
|
78
|
+
// Para archivos de componentes, ser menos agresivo
|
|
79
|
+
const isComponentFile = filename.includes('/Components/') || filename.includes('\\Components\\');
|
|
80
|
+
|
|
81
|
+
let options = getMinificationOptions().js;
|
|
82
|
+
|
|
83
|
+
if (isComponentFile) {
|
|
84
|
+
// Configuración especial para archivos de componentes
|
|
85
|
+
options = {
|
|
86
|
+
...options,
|
|
87
|
+
compress: {
|
|
88
|
+
...options.compress,
|
|
89
|
+
passes: 1,
|
|
90
|
+
keep_classnames: true,
|
|
91
|
+
keep_fnames: true
|
|
92
|
+
},
|
|
93
|
+
mangle: false // NO hacer mangle en archivos de componentes
|
|
94
|
+
};
|
|
95
|
+
}
|
|
96
|
+
|
|
58
97
|
const result = await terserMinify(content, options);
|
|
59
98
|
|
|
60
99
|
if (result.error) {
|
|
@@ -70,7 +109,9 @@ async function minifyJavaScript(content, filename) {
|
|
|
70
109
|
return result.code;
|
|
71
110
|
} catch (error) {
|
|
72
111
|
Print.error(`Error minifying ${filename}: ${error.message}`);
|
|
73
|
-
|
|
112
|
+
// En caso de error, devolver contenido original
|
|
113
|
+
Print.warning(`Using original content for ${filename}`);
|
|
114
|
+
return content;
|
|
74
115
|
}
|
|
75
116
|
}
|
|
76
117
|
|
|
@@ -377,7 +418,7 @@ export async function serveProductionBuild(port = 3001) {
|
|
|
377
418
|
}
|
|
378
419
|
|
|
379
420
|
/**
|
|
380
|
-
* Comando build con opciones
|
|
421
|
+
* Comando build con opciones - CORREGIDO
|
|
381
422
|
*/
|
|
382
423
|
export async function buildCommand(options = {}) {
|
|
383
424
|
// Verificar dependencias necesarias
|
|
@@ -400,17 +441,18 @@ export async function buildCommand(options = {}) {
|
|
|
400
441
|
// Build completo
|
|
401
442
|
const success = await buildProduction(options);
|
|
402
443
|
|
|
444
|
+
// Solo mostrar mensaje informativo, no ejecutar servidor automáticamente
|
|
403
445
|
if (success && options.preview) {
|
|
404
446
|
Print.newLine();
|
|
405
|
-
Print.info('
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
}, 1000);
|
|
447
|
+
Print.info('✨ Build completed successfully!');
|
|
448
|
+
Print.info('💡 Use "slice build --serve" to preview the production build');
|
|
449
|
+
Print.info('💡 Or "slice start" to start production server');
|
|
409
450
|
}
|
|
410
451
|
|
|
411
452
|
return success;
|
|
412
453
|
}
|
|
413
454
|
|
|
455
|
+
|
|
414
456
|
/**
|
|
415
457
|
* Verifica que las dependencias de build estén instaladas en el CLI
|
|
416
458
|
*/
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
// commands/startServer/startServer.js
|
|
1
|
+
// commands/startServer/startServer.js - VERSIÓN SIMPLIFICADA
|
|
2
2
|
|
|
3
3
|
import fs from 'fs-extra';
|
|
4
4
|
import path from 'path';
|
|
@@ -27,66 +27,7 @@ async function checkDevelopmentStructure() {
|
|
|
27
27
|
}
|
|
28
28
|
|
|
29
29
|
/**
|
|
30
|
-
*
|
|
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
|
-
/**
|
|
89
|
-
* Inicia el servidor Node.js
|
|
30
|
+
* Inicia el servidor Node.js - SIMPLIFICADO
|
|
90
31
|
*/
|
|
91
32
|
function startNodeServer(port, mode) {
|
|
92
33
|
return new Promise((resolve, reject) => {
|
|
@@ -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,39 +50,26 @@ function startNodeServer(port, mode) {
|
|
|
108
50
|
reject(error);
|
|
109
51
|
});
|
|
110
52
|
|
|
111
|
-
// Manejar Ctrl+C
|
|
112
|
-
process.on('SIGINT',
|
|
53
|
+
// Manejar Ctrl+C - SIMPLIFICADO
|
|
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
|
-
|
|
124
|
-
process.on('SIGTERM', async () => {
|
|
125
|
-
if (mode === 'production') {
|
|
126
|
-
await restoreDevelopmentIndexFile();
|
|
127
|
-
}
|
|
128
|
-
|
|
60
|
+
process.on('SIGTERM', () => {
|
|
129
61
|
serverProcess.kill('SIGTERM');
|
|
130
62
|
});
|
|
131
63
|
|
|
132
|
-
//
|
|
64
|
+
// NO mostrar mensajes duplicados - el api/index.js ya se encarga
|
|
133
65
|
setTimeout(() => {
|
|
134
|
-
Print.success(`${mode === 'production' ? 'Production' : 'Development'} server running at http://localhost:${port}`);
|
|
135
|
-
Print.info(`Serving files from /${mode === 'production' ? 'dist' : 'src'} directory`);
|
|
136
|
-
Print.info('Press Ctrl+C to stop the server');
|
|
137
66
|
resolve(serverProcess);
|
|
138
|
-
},
|
|
67
|
+
}, 500);
|
|
139
68
|
});
|
|
140
69
|
}
|
|
141
70
|
|
|
142
71
|
/**
|
|
143
|
-
* Función principal para iniciar servidor
|
|
72
|
+
* Función principal para iniciar servidor - ULTRA SIMPLIFICADA
|
|
144
73
|
*/
|
|
145
74
|
export default async function startServer(options = {}) {
|
|
146
75
|
const { mode = 'development', port = 3000 } = options;
|
|
@@ -155,35 +84,20 @@ export default async function startServer(options = {}) {
|
|
|
155
84
|
}
|
|
156
85
|
|
|
157
86
|
if (mode === 'production') {
|
|
158
|
-
//
|
|
87
|
+
// Verificar que existe build de producción
|
|
159
88
|
if (!await checkProductionBuild()) {
|
|
160
89
|
throw new Error('No production build found. Run "slice build" first.');
|
|
161
90
|
}
|
|
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
91
|
Print.info('Production mode: serving optimized files from /dist');
|
|
170
92
|
} else {
|
|
171
|
-
// Modo desarrollo: asegurar que está en modo desarrollo
|
|
172
|
-
await restoreDevelopmentIndexFile();
|
|
173
93
|
Print.info('Development mode: serving files from /src with hot reload');
|
|
174
94
|
}
|
|
175
95
|
|
|
176
|
-
// Iniciar el servidor
|
|
96
|
+
// Iniciar el servidor - api/index.js maneja todo automáticamente
|
|
177
97
|
await startNodeServer(port, mode);
|
|
178
98
|
|
|
179
99
|
} catch (error) {
|
|
180
100
|
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
101
|
throw error;
|
|
188
102
|
}
|
|
189
103
|
}
|