neutronium 2.9.7 → 2.9.8
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/compiler/compiler.js +125 -19
- package/package.json +2 -5
package/compiler/compiler.js
CHANGED
|
@@ -80,64 +80,167 @@ async function compileProject(projectDir = process.cwd()) {
|
|
|
80
80
|
writeFile(path.join(distDir, 'index.html'), htmlContent);
|
|
81
81
|
|
|
82
82
|
log('✅ Compilation complete!');
|
|
83
|
+
return true;
|
|
83
84
|
} catch (e) {
|
|
84
85
|
console.error('❌ Compilation failed:', e.message);
|
|
86
|
+
return false;
|
|
85
87
|
}
|
|
86
88
|
}
|
|
87
89
|
|
|
88
90
|
function compileProjectWatch(projectDir = process.cwd(), port = 3000) {
|
|
91
|
+
// Start server first
|
|
89
92
|
const server = serveProject(projectDir, port);
|
|
93
|
+
|
|
94
|
+
// Do initial compilation
|
|
90
95
|
compileProject(projectDir);
|
|
91
96
|
|
|
92
97
|
log('👀 Watching project for changes...');
|
|
98
|
+
log('✋ Press Ctrl+C to stop the development server');
|
|
99
|
+
|
|
93
100
|
let timeout;
|
|
94
101
|
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
path.join(projectDir, '**/*.ts'),
|
|
98
|
-
path.join(projectDir, '**/*.tsx')
|
|
99
|
-
], {
|
|
102
|
+
// Watch files more specifically
|
|
103
|
+
const watcher = chokidar.watch(projectDir, {
|
|
100
104
|
ignoreInitial: true,
|
|
101
|
-
|
|
105
|
+
ignored: [
|
|
106
|
+
'**/node_modules/**',
|
|
107
|
+
'**/dist/**',
|
|
108
|
+
'**/.git/**',
|
|
109
|
+
'**/*',
|
|
110
|
+
'compiler.js'
|
|
111
|
+
],
|
|
112
|
+
persistent: true,
|
|
113
|
+
followSymlinks: false,
|
|
114
|
+
depth: 2,
|
|
115
|
+
awaitWriteFinish: {
|
|
116
|
+
stabilityThreshold: 100,
|
|
117
|
+
pollInterval: 100
|
|
118
|
+
}
|
|
119
|
+
});
|
|
120
|
+
|
|
121
|
+
watcher.on('ready', () => {
|
|
122
|
+
log('📡 File watcher ready and monitoring changes...');
|
|
123
|
+
});
|
|
124
|
+
|
|
125
|
+
watcher.on('change', filePath => {
|
|
126
|
+
// Only watch js, ts, tsx files
|
|
127
|
+
if (!/\.(js|ts|tsx)$/.test(filePath)) {
|
|
128
|
+
return;
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
log(`🔍 Detected change in: ${path.relative(projectDir, filePath)}`);
|
|
132
|
+
|
|
102
133
|
clearTimeout(timeout);
|
|
103
134
|
timeout = setTimeout(() => {
|
|
104
|
-
console.clear();
|
|
105
|
-
log(`🔁 File changed: ${filePath}`);
|
|
106
135
|
log('🔨 Rebuilding project...');
|
|
107
136
|
|
|
108
137
|
try {
|
|
109
|
-
compileProject(projectDir);
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
138
|
+
const success = compileProject(projectDir);
|
|
139
|
+
if (success) {
|
|
140
|
+
log('✅ Rebuild successful!');
|
|
141
|
+
// Trigger browser reload
|
|
142
|
+
if (server && server.broadcastReload) {
|
|
143
|
+
server.broadcastReload();
|
|
144
|
+
log('🔄 Browser reload triggered');
|
|
145
|
+
}
|
|
114
146
|
}
|
|
115
147
|
} catch (err) {
|
|
116
148
|
console.error('❌ Rebuild failed:', err.stack || err.message);
|
|
117
149
|
}
|
|
118
|
-
},
|
|
150
|
+
}, 300); // Slightly longer debounce
|
|
151
|
+
});
|
|
152
|
+
|
|
153
|
+
watcher.on('add', filePath => {
|
|
154
|
+
if (!/\.(js|ts|tsx)$/.test(filePath)) {
|
|
155
|
+
return;
|
|
156
|
+
}
|
|
157
|
+
log(`📝 New file added: ${path.relative(projectDir, filePath)}`);
|
|
158
|
+
});
|
|
159
|
+
|
|
160
|
+
watcher.on('unlink', filePath => {
|
|
161
|
+
if (!/\.(js|ts|tsx)$/.test(filePath)) {
|
|
162
|
+
return;
|
|
163
|
+
}
|
|
164
|
+
log(`🗑️ File removed: ${path.relative(projectDir, filePath)}`);
|
|
119
165
|
});
|
|
166
|
+
|
|
167
|
+
watcher.on('error', error => {
|
|
168
|
+
console.error('❌ Watcher error:', error);
|
|
169
|
+
});
|
|
170
|
+
|
|
171
|
+
// Cleanup function
|
|
172
|
+
const cleanup = () => {
|
|
173
|
+
log('🧹 Cleaning up...');
|
|
174
|
+
watcher.close();
|
|
175
|
+
if (server) {
|
|
176
|
+
server.close();
|
|
177
|
+
}
|
|
178
|
+
process.exit(0);
|
|
179
|
+
};
|
|
180
|
+
|
|
181
|
+
process.on('SIGINT', cleanup);
|
|
182
|
+
process.on('SIGTERM', cleanup);
|
|
183
|
+
|
|
184
|
+
return { server, watcher, cleanup };
|
|
120
185
|
}
|
|
121
186
|
|
|
122
187
|
function serveProject(projectDir = process.cwd(), port = 3000) {
|
|
123
188
|
const server = http.createServer((req, res) => {
|
|
124
189
|
let reqPath = req.url;
|
|
190
|
+
|
|
191
|
+
// Handle root and index requests
|
|
125
192
|
if (reqPath === '/' || reqPath === '/index.html') {
|
|
126
193
|
reqPath = '/dist/index.html';
|
|
127
194
|
}
|
|
195
|
+
|
|
196
|
+
// Handle favicon requests
|
|
197
|
+
if (reqPath === '/favicon.ico') {
|
|
198
|
+
res.writeHead(204);
|
|
199
|
+
return res.end();
|
|
200
|
+
}
|
|
128
201
|
|
|
129
202
|
const filePath = path.join(projectDir, reqPath);
|
|
203
|
+
|
|
204
|
+
// Security check - ensure file is within project directory
|
|
205
|
+
if (!filePath.startsWith(projectDir)) {
|
|
206
|
+
res.writeHead(403);
|
|
207
|
+
return res.end('403 Forbidden');
|
|
208
|
+
}
|
|
209
|
+
|
|
130
210
|
if (!fs.existsSync(filePath)) {
|
|
131
211
|
res.writeHead(404);
|
|
132
212
|
return res.end('404 Not Found');
|
|
133
213
|
}
|
|
134
214
|
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
215
|
+
try {
|
|
216
|
+
const content = fs.readFileSync(filePath);
|
|
217
|
+
const mimeType = Mime.getType(filePath) || 'application/octet-stream';
|
|
218
|
+
|
|
219
|
+
res.writeHead(200, {
|
|
220
|
+
'Content-Type': mimeType,
|
|
221
|
+
'Cache-Control': 'no-cache, no-store, must-revalidate',
|
|
222
|
+
'Pragma': 'no-cache',
|
|
223
|
+
'Expires': '0'
|
|
224
|
+
});
|
|
225
|
+
res.end(content);
|
|
226
|
+
} catch (err) {
|
|
227
|
+
console.error('Error serving file:', err);
|
|
228
|
+
res.writeHead(500);
|
|
229
|
+
res.end('500 Internal Server Error');
|
|
230
|
+
}
|
|
138
231
|
});
|
|
139
232
|
|
|
140
233
|
const wss = new WebSocket.Server({ server });
|
|
234
|
+
|
|
235
|
+
// Add WebSocket connection handling
|
|
236
|
+
wss.on('connection', (ws) => {
|
|
237
|
+
log('🔌 WebSocket client connected');
|
|
238
|
+
|
|
239
|
+
ws.on('close', () => {
|
|
240
|
+
log('🔌 WebSocket client disconnected');
|
|
241
|
+
});
|
|
242
|
+
});
|
|
243
|
+
|
|
141
244
|
server.broadcastReload = () => {
|
|
142
245
|
wss.clients.forEach(client => {
|
|
143
246
|
if (client.readyState === WebSocket.OPEN) {
|
|
@@ -148,10 +251,13 @@ function serveProject(projectDir = process.cwd(), port = 3000) {
|
|
|
148
251
|
|
|
149
252
|
server.listen(port, () => {
|
|
150
253
|
log(`🚀 Server running at http://localhost:${port}`);
|
|
151
|
-
|
|
254
|
+
log(`🌐 Open your browser and navigate to: http://localhost:${port}`);
|
|
255
|
+
|
|
256
|
+
// Remove the open() call completely for now to avoid hanging
|
|
257
|
+
// User can manually open browser
|
|
152
258
|
});
|
|
153
259
|
|
|
154
260
|
return server;
|
|
155
261
|
}
|
|
156
262
|
|
|
157
|
-
module.exports = { compileProject, compileProjectWatch };
|
|
263
|
+
module.exports = { compileProject, compileProjectWatch, serveProject };
|
package/package.json
CHANGED
|
@@ -1,14 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "neutronium",
|
|
3
|
-
"version": "2.9.
|
|
3
|
+
"version": "2.9.8",
|
|
4
4
|
"description": "A dense, efficient JavaScript framework for building modern web applications",
|
|
5
5
|
"main": "src/index.js",
|
|
6
6
|
"type": "commonjs",
|
|
7
7
|
"types": "./ts-neutronium/index.d.ts",
|
|
8
|
-
"scripts": {
|
|
9
|
-
"build": "node build.js",
|
|
10
|
-
"start": "npx serve dist"
|
|
11
|
-
},
|
|
8
|
+
"scripts": {},
|
|
12
9
|
"exports": {
|
|
13
10
|
".": "./src/index.js"
|
|
14
11
|
},
|