neutronium 3.2.6 → 3.2.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 +11 -7
- package/compiler/template.js +0 -17
- package/package.json +1 -1
- package/compiler/watcher.js +0 -17
package/compiler/compiler.js
CHANGED
|
@@ -12,7 +12,7 @@ const { execSync } = require('child_process');
|
|
|
12
12
|
|
|
13
13
|
async function compileProject(projectDir = process.cwd()) {
|
|
14
14
|
const distDir = path.join(projectDir, 'dist');
|
|
15
|
-
const neutroniumPath =
|
|
15
|
+
const neutroniumPath = 'neutronium.js';
|
|
16
16
|
const packageJson = JSON.parse(fs.readFileSync(path.join(projectDir, 'package.json')));
|
|
17
17
|
const entry = packageJson.main || 'App.js';
|
|
18
18
|
|
|
@@ -68,11 +68,11 @@ async function compileProject(projectDir = process.cwd()) {
|
|
|
68
68
|
|
|
69
69
|
// Ensure _neutronium is imported
|
|
70
70
|
if (!source.includes('_neutronium')) {
|
|
71
|
-
code = `import * as _neutronium from '
|
|
71
|
+
code = `import * as _neutronium from './${neutroniumPath.replace(/\\/g, '/')}';\n\n${code}`;
|
|
72
72
|
}
|
|
73
73
|
|
|
74
74
|
// Replace imports to "neutronium" with local path
|
|
75
|
-
code = code.replace(/from\s+['"]neutronium['"]/g, `from '
|
|
75
|
+
code = code.replace(/from\s+['"]neutronium['"]/g, `from './${neutroniumPath.replace(/\\/g, '/')}'`);
|
|
76
76
|
|
|
77
77
|
writeFile(outputPath, code);
|
|
78
78
|
}
|
|
@@ -81,7 +81,7 @@ async function compileProject(projectDir = process.cwd()) {
|
|
|
81
81
|
const htmlContent = baseHtml(`
|
|
82
82
|
<script defer type="module" src="./${entry}"></script>
|
|
83
83
|
`);
|
|
84
|
-
|
|
84
|
+
writeFile(path.join(distDir, neutroniumPath), fs.readFileSync(path.join(projectDir, 'node_modules', 'neutronium', 'src', 'index.js'), 'utf-8'))
|
|
85
85
|
writeFile(path.join(distDir, 'index.html'), htmlContent);
|
|
86
86
|
|
|
87
87
|
log('✅ Compilation complete!');
|
|
@@ -178,10 +178,12 @@ function compileProjectWatch(projectDir = process.cwd(), port = 3000) {
|
|
|
178
178
|
function serveProject(projectDir = process.cwd(), port = 3000) {
|
|
179
179
|
const server = http.createServer((req, res) => {
|
|
180
180
|
let reqPath = req.url;
|
|
181
|
-
|
|
182
181
|
if (reqPath === '/' || reqPath === '/index.html') {
|
|
183
182
|
reqPath = '/dist/index.html';
|
|
184
183
|
}
|
|
184
|
+
else if (!reqPath.startsWith('/dist/')) {
|
|
185
|
+
reqPath = '/dist' + reqPath;
|
|
186
|
+
}
|
|
185
187
|
|
|
186
188
|
if (reqPath === '/favicon.ico') {
|
|
187
189
|
res.writeHead(204);
|
|
@@ -194,7 +196,10 @@ function serveProject(projectDir = process.cwd(), port = 3000) {
|
|
|
194
196
|
res.writeHead(403);
|
|
195
197
|
return res.end('403 Forbidden');
|
|
196
198
|
}
|
|
197
|
-
|
|
199
|
+
if (!filePath.startsWith(path.join(projectDir, 'dist'))) {
|
|
200
|
+
res.writeHead(403);
|
|
201
|
+
return res.end('403 Forbidden');
|
|
202
|
+
}
|
|
198
203
|
if (!fs.existsSync(filePath)) {
|
|
199
204
|
res.writeHead(404);
|
|
200
205
|
return res.end('404 Not Found');
|
|
@@ -234,7 +239,6 @@ function serveProject(projectDir = process.cwd(), port = 3000) {
|
|
|
234
239
|
};
|
|
235
240
|
|
|
236
241
|
server.listen(port, () => {
|
|
237
|
-
log(`🚀 Server running at http://localhost:${port}`);
|
|
238
242
|
log(`🌐 Open your browser and navigate to: http://localhost:${port}`);
|
|
239
243
|
});
|
|
240
244
|
|
package/compiler/template.js
CHANGED
|
@@ -22,21 +22,4 @@ function baseHtml(script) {
|
|
|
22
22
|
`.trim();
|
|
23
23
|
}
|
|
24
24
|
|
|
25
|
-
export function basehtml(script) {
|
|
26
|
-
return `
|
|
27
|
-
<!DOCTYPE html>
|
|
28
|
-
<html>
|
|
29
|
-
<head>
|
|
30
|
-
<meta charset="UTF-8">
|
|
31
|
-
<title>Neutronium App</title>
|
|
32
|
-
</head>
|
|
33
|
-
<body>
|
|
34
|
-
<script>
|
|
35
|
-
${script}
|
|
36
|
-
</script>
|
|
37
|
-
</body>
|
|
38
|
-
</html>
|
|
39
|
-
`.trim();
|
|
40
|
-
}
|
|
41
|
-
|
|
42
25
|
module.exports = { baseHtml };
|
package/package.json
CHANGED
package/compiler/watcher.js
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import chokidar from 'chokidar';
|
|
2
|
-
import path from 'path';
|
|
3
|
-
|
|
4
|
-
const projectDir = process.cwd(); // or absolute path
|
|
5
|
-
|
|
6
|
-
const watcher = chokidar.watch(path.join(projectDir, '**/*.js'), {
|
|
7
|
-
ignoreInitial: true,
|
|
8
|
-
ignored: ['**/node_modules/**'],
|
|
9
|
-
awaitWriteFinish: {
|
|
10
|
-
stabilityThreshold: 300,
|
|
11
|
-
pollInterval: 100
|
|
12
|
-
}
|
|
13
|
-
});
|
|
14
|
-
|
|
15
|
-
watcher.on('all', (event, filePath) => {
|
|
16
|
-
console.log(`[${event}] ${filePath}`);
|
|
17
|
-
});
|