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 +1 -2
- package/api/index.js +124 -101
- package/package.json +1 -1
- package/src/Components/AppComponents/HomePage/HomePage.js +195 -195
- package/src/Components/components.js +27 -27
- package/src/sliceConfig.json +5 -6
- package/src/testing.js +888 -0
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
|
|
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
|
-
//
|
|
16
|
-
const
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
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
|
-
//
|
|
42
|
-
app.use(express.static(path.join(__dirname,
|
|
31
|
+
// Middleware para servir archivos estáticos
|
|
32
|
+
app.use(express.static(path.join(__dirname, `../${folderDeployed}`)));
|
|
43
33
|
|
|
44
|
-
|
|
45
|
-
|
|
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
|
-
//
|
|
51
|
+
// Ruta de ejemplo para API
|
|
49
52
|
app.get('/api/status', (req, res) => {
|
|
50
|
-
res.json({
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
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
|
-
//
|
|
63
|
+
// SPA fallback - servir index.html para rutas no encontradas
|
|
60
64
|
app.get('*', (req, res) => {
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
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
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
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
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
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
|
-
|
|
126
|
-
|
|
127
|
-
|
|
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
|
-
|
|
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
|
|