slicejs-web-framework 2.0.0 → 2.0.3

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/Slice/Slice.js CHANGED
@@ -11,7 +11,6 @@ export default class Slice {
11
11
  this.loggerConfig = sliceConfig.logger;
12
12
  this.debuggerConfig = sliceConfig.debugger;
13
13
  this.loadingConfig = sliceConfig.loading;
14
- this.productionConfig = sliceConfig.production;
15
14
  }
16
15
 
17
16
  async getClass(module) {
@@ -24,7 +23,7 @@ export default class Slice {
24
23
  }
25
24
 
26
25
  isProduction(){
27
- return this.productionConfig.enabled;
26
+ return true;
28
27
  }
29
28
 
30
29
  getComponent(componentSliceId) {
package/api/index.js CHANGED
@@ -12,131 +12,154 @@ let server;
12
12
 
13
13
  const app = express();
14
14
 
15
- // Detectar configuración automáticamente
16
- const PORT = process.env.PORT || 3001;
17
- const NODE_ENV = process.env.NODE_ENV || 'development';
18
- const IS_CLI_MODE = process.env.SLICE_CLI_MODE === 'true';
19
-
20
- // Determinar directorio a servir
21
- // Prioridad: 1) NODE_ENV del CLI, 2) sliceConfig.production, 3) default 'src'
22
- let folderDeployed;
23
- if (NODE_ENV === 'production') {
24
- folderDeployed = 'dist';
25
- } else if (NODE_ENV === 'development') {
26
- folderDeployed = 'src';
27
- } else {
28
- // Fallback al comportamiento original
29
- const isProduction = sliceConfig.production === true;
30
- folderDeployed = isProduction ? 'dist' : 'src';
31
- }
15
+ // Parsear argumentos de línea de comandos
16
+ const args = process.argv.slice(2);
17
+
18
+ // Siempre usar development mode (ignorar argumentos de production)
19
+ const runMode = 'development';
20
+ const folderDeployed = 'src';
21
+
22
+ // Obtener puerto desde sliceConfig.json, con fallback a process.env.PORT
23
+ const PORT = sliceConfig.server?.port || process.env.PORT || 3001;
24
+
25
+ console.log(`🚀 Starting Slice.js server in ${runMode} mode`);
26
+ console.log(`📁 Serving files from: /${folderDeployed}`);
32
27
 
33
- // Servir archivos estáticos desde la carpeta 'Slice'
34
28
  app.use('/Slice/', express.static(path.join(__dirname, '..', 'node_modules', 'slicejs-web-framework', 'Slice')));
35
29
 
36
- // Testing routes (mantener las existentes)
37
- app.get('/testing1', (req, res) => {
38
- res.send(` Actual route in server: __dirname: ${__dirname} __filename: ${__filename} - checking if file exists: ${path.join(__dirname, '..', 'src','App', 'index.html')}`);
39
- });
40
30
 
41
- // Servir archivos estáticos desde la carpeta determinada (src o dist)
42
- app.use(express.static(path.join(__dirname,'..', folderDeployed)));
31
+ // Middleware para servir archivos estáticos
32
+ app.use(express.static(path.join(__dirname, `../${folderDeployed}`)));
43
33
 
44
- app.get('/testing2', (req, res) => {
45
- res.send(` Actual route in server: __dirname: ${__dirname} __filename: ${__filename} - checking if file exists: ${path.join(__dirname, '..', 'src','App', 'index.html')}`);
34
+ // Middleware para parsear JSON y formularios
35
+ app.use(express.json());
36
+ app.use(express.urlencoded({ extended: true }));
37
+
38
+ // Configurar headers de CORS
39
+ app.use((req, res, next) => {
40
+ res.header('Access-Control-Allow-Origin', '*');
41
+ res.header('Access-Control-Allow-Methods', 'GET, POST, PUT, DELETE, OPTIONS');
42
+ res.header('Access-Control-Allow-Headers', 'Origin, X-Requested-With, Content-Type, Accept, Authorization');
43
+
44
+ if (req.method === 'OPTIONS') {
45
+ res.sendStatus(200);
46
+ } else {
47
+ next();
48
+ }
46
49
  });
47
50
 
48
- // API de estado (útil para debugging)
51
+ // Ruta de ejemplo para API
49
52
  app.get('/api/status', (req, res) => {
50
- res.json({
51
- mode: NODE_ENV,
52
- serving: folderDeployed,
53
- port: PORT,
54
- cliMode: IS_CLI_MODE,
55
- timestamp: new Date().toISOString()
53
+ res.json({
54
+ status: 'ok',
55
+ mode: runMode,
56
+ folder: folderDeployed,
57
+ timestamp: new Date().toISOString(),
58
+ framework: 'Slice.js',
59
+ version: '2.0.0'
56
60
  });
57
61
  });
58
62
 
59
- // Ruta para servir el index.html desde la carpeta apropiada
63
+ // SPA fallback - servir index.html para rutas no encontradas
60
64
  app.get('*', (req, res) => {
61
- const filePath = path.join(__dirname, '..', folderDeployed, 'App', 'index.html');
62
- res.sendFile(filePath, (err) => {
63
- if (err) {
64
- // Fallback si no existe App/index.html
65
- const fallbackPath = path.join(__dirname, '..', folderDeployed, 'index.html');
66
- res.sendFile(fallbackPath, (fallbackErr) => {
67
- if (fallbackErr) {
68
- res.status(404).send(`File not found: ${folderDeployed}/index.html`);
69
- }
70
- });
71
- }
72
- });
65
+ const indexPath = path.join(__dirname, `../${folderDeployed}`,"App", 'index.html');
66
+ res.sendFile(indexPath, (err) => {
67
+ if (err) {
68
+ res.status(404).send(`
69
+ <h1>404 - Page Not Found</h1>
70
+ <p>The requested file could not be found in /${folderDeployed}</p>
71
+ <p>Make sure you've run the appropriate build command:</p>
72
+ <ul>
73
+ <li>For development: Files should be in /src</li>
74
+ <li>For production: Run "npm run slice:build" first</li>
75
+ </ul>
76
+ `);
77
+ }
78
+ });
73
79
  });
74
80
 
75
81
  function startServer() {
76
- server = app.listen(PORT, () => {
77
- if (IS_CLI_MODE) {
78
- // Modo CLI - salida simple y limpia (sin menú)
79
- console.log(`🚀 Slice.js ${NODE_ENV} server running at http://localhost:${PORT}`);
80
- console.log(`📁 Serving files from /${folderDeployed} directory`);
81
- console.log('Press Ctrl+C to stop the server');
82
- } else {
83
- // Modo standalone - mostrar menú interactivo
84
- showMenu();
85
- }
86
- });
82
+ server = app.listen(PORT, () => {
83
+ // Limpiar consola y mostrar banner de inicio
84
+ console.clear();
85
+ showWelcomeBanner();
86
+
87
+ // Información del servidor
88
+ console.log(`✅ Server running at ${'\x1b[36m'}http://localhost:${PORT}${'\x1b[0m'}`);
89
+ console.log(`📂 Mode: ${'\x1b[32m'}${runMode}${'\x1b[0m'} (serving from ${'\x1b[33m'}/${folderDeployed}${'\x1b[0m'})`);
90
+ console.log(`🔄 ${'\x1b[32m'}Development mode${'\x1b[0m'}: Changes in /src are served instantly`);
91
+ console.log(`🛑 Press ${'\x1b[31m'}Ctrl+C${'\x1b[0m'} to stop\n`);
92
+ });
93
+
94
+ // Mostrar menú interactivo después de un momento
95
+ setTimeout(showInteractiveMenu, 1500);
96
+ }
97
+
98
+ function showWelcomeBanner() {
99
+ const banner = `
100
+ ${'\x1b[36m'}╔══════════════════════════════════════════════════╗${'\x1b[0m'}
101
+ ${'\x1b[36m'}║${'\x1b[0m'} ${'\x1b[1m'}🍰 SLICE.JS SERVER${'\x1b[0m'} ${'\x1b[36m'}║${'\x1b[0m'}
102
+ ${'\x1b[36m'}║${'\x1b[0m'} ${'\x1b[90m'}Development Environment${'\x1b[0m'} ${'\x1b[36m'}║${'\x1b[0m'}
103
+ ${'\x1b[36m'}╚══════════════════════════════════════════════════╝${'\x1b[0m'}
104
+ `;
105
+ console.log(banner);
87
106
  }
88
107
 
89
- async function showMenu() {
90
- console.clear();
91
- console.log("\n=================================");
92
- console.log(" SLICE SERVER MENU ");
93
- console.log("=================================\n");
94
-
95
- const url = `http://localhost:${PORT}`;
96
- console.log(`Server is running on port ${PORT}, ${url}`);
97
- console.log(`Mode: ${NODE_ENV} | Serving: /${folderDeployed}\n`);
98
-
99
- while (true) {
100
- try {
101
- const { action } = await inquirer.prompt([
102
- {
103
- type: 'list',
104
- name: 'action',
105
- message: 'Select an option:',
106
- choices: ['Restart Server', 'Stop Server (Exit)']
107
- }
108
- ]);
109
-
110
- if (action === 'Stop Server (Exit)') {
111
- console.log('\nShutting down server...');
112
- server.close(() => {
113
- console.log('Server stopped.');
114
- process.exit(0);
115
- });
116
- break;
117
- } else if (action === 'Restart Server') {
118
- console.log('\nRestarting server...');
119
- server.close(() => {
120
- console.log('Server stopped. Restarting...');
121
- startServer();
122
- });
123
- break;
108
+ async function showInteractiveMenu() {
109
+ while (true) {
110
+ try {
111
+ console.log('\n' + '='.repeat(50));
112
+
113
+ const { action } = await inquirer.prompt([
114
+ {
115
+ type: 'list',
116
+ name: 'action',
117
+ message: '🎛️ Server Control Menu',
118
+ choices: [
119
+ '📊 Server Status',
120
+ '🌐 Open in Browser',
121
+ '🔄 Restart Server',
122
+ '🛑 Stop Server'
123
+ ]
124
124
  }
125
- } catch (error) {
126
- // Si hay error con inquirer, continuar sin menú
127
- console.log('\n💡 Interactive menu not available - Press Ctrl+C to stop');
125
+ ]);
126
+
127
+ if (action === '📊 Server Status') {
128
+ console.log(`\n📈 Server Status:`);
129
+ console.log(` 🔗 URL: http://localhost:${PORT}`);
130
+ console.log(` 📁 Mode: ${runMode}`);
131
+ console.log(` 📂 Serving: /${folderDeployed}`);
132
+ console.log(` ⏰ Uptime: ${Math.floor(process.uptime())}s`);
133
+ } else if (action === '🌐 Open in Browser') {
134
+ const { default: open } = await import('open');
135
+ await open(`http://localhost:${PORT}`);
136
+ console.log('🌐 Opening browser...');
137
+ } else if (action === '🛑 Stop Server') {
138
+ console.log('\n🛑 Stopping server...');
139
+ server.close(() => {
140
+ console.log('✅ Server stopped successfully');
141
+ process.exit(0);
142
+ });
143
+ break;
144
+ } else if (action === '🔄 Restart Server') {
145
+ console.log('\nRestarting server...');
146
+ server.close(() => {
147
+ console.log('Server stopped. Restarting...');
148
+ startServer();
149
+ });
128
150
  break;
129
151
  }
130
- }
152
+ } catch (error) {
153
+ // Si hay error con inquirer, continuar sin menú
154
+ console.log('\n💡 Interactive menu not available - Press Ctrl+C to stop');
155
+ break;
156
+ }
157
+ }
131
158
  }
132
159
 
133
160
  // Manejar cierre del proceso
134
161
  process.on('SIGINT', () => {
135
- if (IS_CLI_MODE) {
136
- console.log('\n🛑 Server stopped');
137
- } else {
138
- console.log('\n🛑 Slice server stopped');
139
- }
162
+ console.log('\n🛑 Slice server stopped');
140
163
  process.exit(0);
141
164
  });
142
165
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "slicejs-web-framework",
3
- "version": "2.0.0",
3
+ "version": "2.0.3",
4
4
  "description": "",
5
5
  "engines": {
6
6
  "node": ">=20"