frontend-hamroun 1.1.41 → 1.1.43
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/bin/cli.js +64 -43
- package/package.json +2 -1
package/bin/cli.js
CHANGED
@@ -8,7 +8,6 @@ import { fileURLToPath } from 'url';
|
|
8
8
|
import chalk from 'chalk';
|
9
9
|
import { createSpinner } from 'nanospinner';
|
10
10
|
import { createServer } from 'http';
|
11
|
-
import * as esbuild from 'esbuild';
|
12
11
|
|
13
12
|
const __filename = fileURLToPath(import.meta.url);
|
14
13
|
const __dirname = path.dirname(__filename);
|
@@ -16,56 +15,70 @@ const __dirname = path.dirname(__filename);
|
|
16
15
|
async function createDevServer(options = {}) {
|
17
16
|
const { port = 3000, isSSR = false } = options;
|
18
17
|
|
19
|
-
|
20
|
-
|
21
|
-
bundle: true,
|
22
|
-
outdir: 'dist',
|
23
|
-
format: 'esm',
|
24
|
-
platform: isSSR ? 'node' : 'browser',
|
25
|
-
sourcemap: true,
|
26
|
-
loader: { '.tsx': 'tsx', '.ts': 'tsx' },
|
27
|
-
jsxFactory: '_jsx',
|
28
|
-
jsxFragment: '_Fragment',
|
29
|
-
banner: {
|
30
|
-
js: `import { jsx as _jsx, Fragment as _Fragment } from 'frontend-hamroun';`,
|
31
|
-
}
|
32
|
-
});
|
33
|
-
|
34
|
-
await ctx.watch();
|
35
|
-
|
36
|
-
const server = createServer((req, res) => {
|
37
|
-
const url = new URL(req.url || '', `http://${req.headers.host}`);
|
18
|
+
try {
|
19
|
+
const esbuild = await import('esbuild');
|
38
20
|
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
21
|
+
const ctx = await esbuild.context({
|
22
|
+
entryPoints: ['src/main.tsx'],
|
23
|
+
bundle: true,
|
24
|
+
outdir: 'dist',
|
25
|
+
format: 'esm',
|
26
|
+
platform: isSSR ? 'node' : 'browser',
|
27
|
+
sourcemap: true,
|
28
|
+
loader: { '.tsx': 'tsx', '.ts': 'tsx' },
|
29
|
+
jsxFactory: '_jsx',
|
30
|
+
jsxFragment: '_Fragment',
|
31
|
+
banner: {
|
32
|
+
js: `import { jsx as _jsx, Fragment as _Fragment } from 'frontend-hamroun';`,
|
33
|
+
}
|
34
|
+
});
|
35
|
+
|
36
|
+
await ctx.watch();
|
37
|
+
|
38
|
+
const server = createServer((req, res) => {
|
39
|
+
const url = new URL(req.url || '', `http://${req.headers.host}`);
|
40
|
+
|
41
|
+
if (url.pathname === '/') {
|
42
|
+
res.writeHead(200, { 'Content-Type': 'text/html' });
|
43
|
+
res.end(fs.readFileSync('index.html', 'utf8'));
|
44
|
+
} else if (url.pathname.endsWith('.js')) {
|
45
|
+
res.writeHead(200, { 'Content-Type': 'application/javascript' });
|
46
|
+
res.end(fs.readFileSync(path.join('dist', url.pathname), 'utf8'));
|
47
|
+
} else {
|
48
|
+
res.writeHead(404);
|
49
|
+
res.end();
|
50
|
+
}
|
51
|
+
});
|
52
|
+
|
53
|
+
server.listen(port);
|
54
|
+
console.log(chalk.green(`Development server running at http://localhost:${port}`));
|
55
|
+
|
56
|
+
return { server, ctx };
|
57
|
+
} catch (error) {
|
58
|
+
console.error('Failed to load esbuild:', error);
|
59
|
+
throw error;
|
60
|
+
}
|
55
61
|
}
|
56
62
|
|
57
63
|
async function init() {
|
58
64
|
const program = new Command();
|
59
65
|
|
60
66
|
program
|
61
|
-
.name('
|
62
|
-
.description('
|
67
|
+
.name('frontend-hamroun')
|
68
|
+
.description('Frontend Hamroun CLI')
|
69
|
+
.version('1.0.0');
|
70
|
+
|
71
|
+
// Create command
|
72
|
+
program
|
73
|
+
.command('create')
|
74
|
+
.description('Create a new project')
|
63
75
|
.argument('[name]', 'Project name')
|
64
76
|
.action(async (name) => {
|
65
77
|
const projectName = name || await askProjectName();
|
66
78
|
await createProject(projectName);
|
67
79
|
});
|
68
80
|
|
81
|
+
// Dev command
|
69
82
|
program
|
70
83
|
.command('dev')
|
71
84
|
.description('Start development server')
|
@@ -74,19 +87,27 @@ async function init() {
|
|
74
87
|
.action(async (options) => {
|
75
88
|
const spinner = createSpinner('Starting development server...').start();
|
76
89
|
try {
|
77
|
-
await createDevServer({
|
90
|
+
const { server, ctx } = await createDevServer({
|
78
91
|
port: parseInt(options.port),
|
79
92
|
isSSR: options.ssr
|
80
93
|
});
|
81
|
-
|
94
|
+
|
95
|
+
spinner.success({ text: `Development server running at http://localhost:${options.port}` });
|
96
|
+
|
97
|
+
// Handle cleanup
|
98
|
+
process.on('SIGINT', async () => {
|
99
|
+
await ctx.dispose();
|
100
|
+
server.close();
|
101
|
+
process.exit(0);
|
102
|
+
});
|
82
103
|
} catch (error) {
|
83
|
-
spinner.error({ text:
|
84
|
-
console.error(error);
|
104
|
+
spinner.error({ text: 'Failed to start development server' });
|
105
|
+
console.error(chalk.red(error));
|
85
106
|
process.exit(1);
|
86
107
|
}
|
87
108
|
});
|
88
109
|
|
89
|
-
program.parse();
|
110
|
+
program.parse(process.argv);
|
90
111
|
}
|
91
112
|
|
92
113
|
async function askProjectName() {
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "frontend-hamroun",
|
3
|
-
"version": "1.1.
|
3
|
+
"version": "1.1.43",
|
4
4
|
"description": "A lightweight frontend framework with hooks and virtual DOM",
|
5
5
|
"type": "module",
|
6
6
|
"main": "./dist/index.js",
|
@@ -61,6 +61,7 @@
|
|
61
61
|
"dependencies": {
|
62
62
|
"chalk": "^5.3.0",
|
63
63
|
"commander": "^11.0.0",
|
64
|
+
"esbuild": "^0.19.2",
|
64
65
|
"fs-extra": "^11.1.1",
|
65
66
|
"inquirer": "^9.2.10",
|
66
67
|
"nanospinner": "^1.1.0"
|