neutronium 1.0.0 → 1.6.0

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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 PFMCODES
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/cli/index.js CHANGED
@@ -3,11 +3,22 @@ const { default: inquirer } = require('inquirer');
3
3
  const fs = require('fs');
4
4
  const path = require('path');
5
5
  const { execSync } = require('child_process');
6
- const babel = require('@babel/core');
6
+ const { transformSync } = require('@babel/core');
7
7
 
8
8
  const [, , command, ...args] = process.argv;
9
9
 
10
- // App.js with JSX
10
+ const babelRc = `{
11
+ "plugins": [
12
+ [
13
+ "@babel/plugin-transform-react-jsx",
14
+ {
15
+ "pragma": "h",
16
+ "pragmaFrag": "Fragment"
17
+ }
18
+ ]
19
+ ]
20
+ }`;
21
+
11
22
  const AppJs = `
12
23
  import { h, createApp } from 'neutronium';
13
24
 
@@ -23,22 +34,21 @@ function App() {
23
34
  createApp(App).mount('#app');
24
35
  `;
25
36
 
26
- // HTML template with __SCRIPT__ placeholder
27
- const htmlTemplate = `
37
+ const htmlTemplate = (title, jsCode) => `
28
38
  <!DOCTYPE html>
29
39
  <html>
30
40
  <head>
31
41
  <meta charset="UTF-8" />
32
- <title>${appName}</title>
42
+ <title>${title}</title>
33
43
  </head>
34
44
  <body>
35
45
  <div id="app"></div>
36
46
  <script type="module">
37
- __SCRIPT__
47
+ ${jsCode}
38
48
  </script>
39
49
  </body>
40
50
  </html>
41
- `;
51
+ `.trim();
42
52
 
43
53
  async function init() {
44
54
  let targetPath = process.cwd();
@@ -53,6 +63,8 @@ async function init() {
53
63
  }
54
64
  ]);
55
65
 
66
+ let appName = 'neutronium-app';
67
+
56
68
  if (!confirmInit) {
57
69
  const { projectName } = await inquirer.prompt([
58
70
  {
@@ -62,45 +74,39 @@ async function init() {
62
74
  default: 'neutronium-app'
63
75
  }
64
76
  ]);
77
+ appName = projectName;
65
78
  targetPath = path.resolve(process.cwd(), projectName);
66
79
  createdFolder = true;
67
80
  if (!fs.existsSync(targetPath)) fs.mkdirSync(targetPath);
68
81
  else console.log('⚠️ Folder already exists. Using it anyway.');
69
82
  }
70
83
 
71
- // Write App.js
72
84
  const appPath = path.join(targetPath, 'App.js');
73
85
  fs.writeFileSync(appPath, AppJs.trim());
74
86
 
75
- // Init package.json
76
- execSync('npm init -y', { cwd: targetPath, stdio: 'inherit' });
87
+ fs.writeFileSync(path.join(targetPath, '.babelrc'), babelRc);
77
88
 
78
- // Install neutronium
89
+ execSync('npm init -y', { cwd: targetPath, stdio: 'inherit' });
79
90
  execSync('npm install neutronium', { cwd: targetPath, stdio: 'inherit' });
80
-
81
- // Install Babel for JSX support
82
91
  execSync('npm install --save-dev @babel/core @babel/cli @babel/plugin-transform-react-jsx', {
83
92
  cwd: targetPath,
84
93
  stdio: 'inherit'
85
94
  });
86
95
 
87
- // Compile App.js to script string
88
- const appJsCode = fs.readFileSync(appPath, 'utf-8');
89
- const result = babel.transformSync(appJsCode, {
96
+ const result = transformSync(AppJs, {
90
97
  filename: 'App.js',
98
+ presets: [],
91
99
  plugins: [['@babel/plugin-transform-react-jsx', { pragma: 'h' }]]
92
100
  });
93
101
 
94
- // Inject into HTML
95
- const finalHtml = htmlTemplate.replace('__SCRIPT__', result.code);
96
-
102
+ const finalHtml = htmlTemplate(appName, result.code);
97
103
  const distPath = path.join(targetPath, 'dist');
98
104
  if (!fs.existsSync(distPath)) fs.mkdirSync(distPath);
99
105
  fs.writeFileSync(path.join(distPath, 'index.html'), finalHtml);
100
106
 
101
- const folder = createdFolder ? `cd ${path.basename(targetPath)}` : '';
107
+ const folderCmd = createdFolder ? `cd ${path.basename(targetPath)}` : '';
102
108
  console.log('\n✅ Neutronium app is ready!');
103
- console.log(`➡️ Run the following to get started:\n\n ${folder}\n npx serve dist\n`);
109
+ console.log(`➡️ Run the following to get started:\n\n ${folderCmd}\n npx serve dist\n`);
104
110
  }
105
111
 
106
112
  const { compileProject, compileProjectWatch } = require('../compiler/compiler');
@@ -112,11 +118,12 @@ switch (command) {
112
118
  init();
113
119
  break;
114
120
  case 'start':
115
- if (args[0] == "--watch") {
116
- compileProjectWatch(); // Will read App.js and output dist/index.html
117
- } else {
118
- compileProject()
119
- }
121
+ if (args[0] === '--watch') {
122
+ compileProjectWatch();
123
+ } else {
124
+ compileProject();
125
+ }
126
+ break;
120
127
  default:
121
128
  console.log('❌ Unknown command.');
122
129
  console.log('Usage: neu-cli init');
@@ -14,7 +14,9 @@ function compileProject(projectDir = process.cwd()) {
14
14
  const distDir = path.join(projectDir, 'dist');
15
15
  const outHtmlPath = path.join(distDir, 'index.html');
16
16
  const outJsPath = path.join(distDir, 'App.compiled.js');
17
- const srcIndexPath = path.relative(distDir, path.join(projectDir, 'src/index.js')).replace(/\\/g, '/');
17
+
18
+ // Use relative path to Neutronium source
19
+ const neutroniumPath = path.relative(distDir, path.join(projectDir, 'node_modules/neutronium/src/index.js')).replace(/\\/g, '/');
18
20
 
19
21
  try {
20
22
  log('📖 Reading App.js...');
@@ -27,9 +29,9 @@ function compileProject(projectDir = process.cwd()) {
27
29
  plugins: [['@babel/plugin-transform-react-jsx', { pragma: 'h' }]],
28
30
  });
29
31
 
30
- // Inject framework import + mount call
32
+ log('📦 Writing App.compiled.js...');
31
33
  const finalJsCode = `
32
- import { h, createApp } from '${srcIndexPath}';
34
+ import { h, createApp } from '${neutroniumPath}';
33
35
 
34
36
  ${transpiled}
35
37
 
@@ -68,7 +70,8 @@ function compileProjectWatch(projectDir = process.cwd(), port = 3000) {
68
70
  }
69
71
 
70
72
  function serveProject(projectDir = process.cwd(), port = 3000) {
71
- const distDir = path.join(projectDir, 'dist');
73
+ const distDir = projectDir
74
+
72
75
  const server = http.createServer((req, res) => {
73
76
  let reqPath = req.url === '/' ? '/index.html' : req.url;
74
77
  const filePath = path.join(distDir, reqPath);
@@ -101,4 +104,4 @@ function serveProject(projectDir = process.cwd(), port = 3000) {
101
104
  return server;
102
105
  }
103
106
 
104
- module.exports = { compileProject, compileProjectWatch };
107
+ module.exports = { compileProject, compileProjectWatch };
@@ -1,14 +1,14 @@
1
- function baseHtml(bodyHtml, scriptFile = 'App.compiled.js') {
1
+ function baseHtml(appHtml, scriptName) {
2
2
  return `
3
3
  <!DOCTYPE html>
4
4
  <html>
5
5
  <head>
6
- <meta charset="UTF-8" />
6
+ <meta charset="UTF-8">
7
7
  <title>Neutronium App</title>
8
8
  </head>
9
9
  <body>
10
- ${bodyHtml}
11
- <script type="module" src="./${scriptFile}"></script>
10
+ ${appHtml}
11
+ <script type="module" src="./${scriptName}"></script>
12
12
  <script>
13
13
  const ws = new WebSocket('ws://' + location.host);
14
14
  ws.onmessage = (msg) => {
@@ -23,4 +23,4 @@ function baseHtml(bodyHtml, scriptFile = 'App.compiled.js') {
23
23
  `.trim();
24
24
  }
25
25
 
26
- module.exports = { baseHtml };
26
+ module.exports = { baseHtml };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "neutronium",
3
- "version": "1.0.0",
3
+ "version": "1.6.0",
4
4
  "description": "A dense, efficient JavaScript framework for building modern web applications",
5
5
  "main": "src/index.js",
6
6
  "type": "commonjs",
package/src/index.js CHANGED
@@ -38,4 +38,5 @@ function createApp(component) {
38
38
  };
39
39
  }
40
40
 
41
- module.exports = { h, createApp };
41
+
42
+ export { h, createApp };
package/.babelrc DELETED
@@ -1,11 +0,0 @@
1
- {
2
- "plugins": [
3
- [
4
- "@babel/plugin-transform-react-jsx",
5
- {
6
- "pragma": "h",
7
- "pragmaFrag": "Fragment"
8
- }
9
- ]
10
- ]
11
- }
package/test-open.js DELETED
@@ -1,6 +0,0 @@
1
-
2
- const { default:open } = require('open');
3
-
4
- open('http://localhost:3000').catch(err => {
5
- console.error('❌ Failed to open browser:', err);
6
- });