frontend-hamroun 1.2.77 → 1.2.79
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/dist/batch/package.json +1 -1
- package/dist/client-router/package.json +1 -1
- package/dist/component/package.json +1 -1
- package/dist/context/package.json +1 -1
- package/dist/event-bus/package.json +1 -1
- package/dist/forms/package.json +1 -1
- package/dist/hooks/package.json +1 -1
- package/dist/index.mjs +1 -0
- package/dist/jsx-runtime/package.json +1 -1
- package/dist/lifecycle-events/package.json +1 -1
- package/dist/package.json +1 -1
- package/dist/render-component/package.json +1 -1
- package/dist/renderer/package.json +1 -1
- package/dist/router/package.json +1 -1
- package/dist/server/package.json +1 -1
- package/dist/server/src/index.js +24 -23
- package/dist/server/src/index.js.map +1 -1
- package/dist/server/src/renderComponent.d.ts +8 -9
- package/dist/server/src/renderComponent.js +10 -5
- package/dist/server/src/renderComponent.js.map +1 -1
- package/dist/server/src/server/index.d.ts +23 -34
- package/dist/server/src/server/index.js +170 -50
- package/dist/server/src/server/index.js.map +1 -1
- package/dist/server/src/server/templates.d.ts +2 -0
- package/dist/server/src/server/templates.js +9 -5
- package/dist/server/src/server/templates.js.map +1 -1
- package/dist/server/src/server/utils.d.ts +1 -1
- package/dist/server/src/server/utils.js +1 -1
- package/dist/server/src/server/utils.js.map +1 -1
- package/dist/server/tsconfig.server.tsbuildinfo +1 -1
- package/dist/server-renderer/package.json +1 -1
- package/dist/store/package.json +1 -1
- package/dist/types/package.json +1 -1
- package/dist/utils/package.json +1 -1
- package/dist/vdom/package.json +1 -1
- package/dist/wasm/package.json +1 -1
- package/package.json +1 -1
- package/templates/complete-app/client.js +58 -0
- package/templates/complete-app/package-lock.json +2536 -0
- package/templates/complete-app/package.json +8 -31
- package/templates/complete-app/pages/about.js +119 -0
- package/templates/complete-app/pages/index.js +157 -0
- package/templates/complete-app/pages/wasm-demo.js +290 -0
- package/templates/complete-app/public/client.js +80 -0
- package/templates/complete-app/public/index.html +47 -0
- package/templates/complete-app/public/styles.css +446 -212
- package/templates/complete-app/readme.md +188 -0
- package/templates/complete-app/server.js +417 -0
- package/templates/complete-app/server.ts +275 -0
- package/templates/complete-app/src/App.tsx +59 -0
- package/templates/complete-app/src/client.ts +61 -0
- package/templates/complete-app/src/client.tsx +18 -0
- package/templates/complete-app/src/pages/index.tsx +51 -0
- package/templates/complete-app/src/server.ts +218 -0
- package/templates/complete-app/tsconfig.json +22 -0
- package/templates/complete-app/tsconfig.server.json +19 -0
- package/templates/complete-app/vite.config.js +57 -0
- package/templates/complete-app/vite.config.ts +30 -0
- package/templates/go/example.go +154 -99
- package/templates/complete-app/build.js +0 -284
- package/templates/complete-app/src/api/index.js +0 -31
- package/templates/complete-app/src/client.js +0 -93
- package/templates/complete-app/src/components/App.js +0 -66
- package/templates/complete-app/src/components/Footer.js +0 -19
- package/templates/complete-app/src/components/Header.js +0 -38
- package/templates/complete-app/src/pages/About.js +0 -59
- package/templates/complete-app/src/pages/Home.js +0 -54
- package/templates/complete-app/src/pages/WasmDemo.js +0 -136
- package/templates/complete-app/src/server.js +0 -186
- package/templates/complete-app/src/wasm/build.bat +0 -16
- package/templates/complete-app/src/wasm/build.sh +0 -16
- package/templates/complete-app/src/wasm/example.go +0 -101
@@ -1,136 +0,0 @@
|
|
1
|
-
import { jsx, useState, useEffect, useContext } from '../client.js';
|
2
|
-
import { AppContext } from '../components/App.js';
|
3
|
-
|
4
|
-
export default function WasmDemo() {
|
5
|
-
const { wasm } = useContext(AppContext);
|
6
|
-
|
7
|
-
// State for error display
|
8
|
-
const [error, setError] = useState(null);
|
9
|
-
|
10
|
-
// State for calculation form
|
11
|
-
const [num1, setNum1] = useState(5);
|
12
|
-
const [num2, setNum2] = useState(7);
|
13
|
-
const [result, setResult] = useState(null);
|
14
|
-
|
15
|
-
// State for JSON form
|
16
|
-
const [jsonInput, setJsonInput] = useState('{"name": "Baraqex", "version": "1.0"}');
|
17
|
-
const [jsonResult, setJsonResult] = useState(null);
|
18
|
-
|
19
|
-
useEffect(() => {
|
20
|
-
document.title = 'WebAssembly Demo - Baraqex Complete App';
|
21
|
-
|
22
|
-
// Demonstrate a calculation on mount if WASM is available
|
23
|
-
if (wasm && wasm.functions.goAdd) {
|
24
|
-
try {
|
25
|
-
const sum = wasm.functions.goAdd(5, 7);
|
26
|
-
setResult(sum);
|
27
|
-
} catch (err) {
|
28
|
-
console.error('Error in initial WASM calculation:', err);
|
29
|
-
}
|
30
|
-
}
|
31
|
-
}, [wasm]);
|
32
|
-
|
33
|
-
// Function to calculate using WASM
|
34
|
-
const calculateResult = () => {
|
35
|
-
if (!wasm || !wasm.functions.goAdd) {
|
36
|
-
setError('WASM module not loaded or function not available');
|
37
|
-
return;
|
38
|
-
}
|
39
|
-
|
40
|
-
try {
|
41
|
-
// Call the WASM function
|
42
|
-
const sum = wasm.functions.goAdd(parseInt(num1), parseInt(num2));
|
43
|
-
setResult(sum);
|
44
|
-
setError(null);
|
45
|
-
} catch (err) {
|
46
|
-
console.error('Error calling WASM function:', err);
|
47
|
-
setError('Error calling WASM function: ' + err);
|
48
|
-
}
|
49
|
-
};
|
50
|
-
|
51
|
-
// Function to parse JSON using WASM
|
52
|
-
const parseJsonWithWasm = () => {
|
53
|
-
if (!wasm || !wasm.functions.goParseJSON) {
|
54
|
-
setError('WASM module not loaded or JSON parsing function not available');
|
55
|
-
return;
|
56
|
-
}
|
57
|
-
|
58
|
-
try {
|
59
|
-
// Call the WASM function
|
60
|
-
const parsed = wasm.functions.goParseJSON(jsonInput);
|
61
|
-
setJsonResult(JSON.stringify(parsed, null, 2));
|
62
|
-
setError(null);
|
63
|
-
} catch (err) {
|
64
|
-
console.error('Error parsing JSON with WASM:', err);
|
65
|
-
setError('Error parsing JSON with WASM: ' + err);
|
66
|
-
}
|
67
|
-
};
|
68
|
-
|
69
|
-
return (
|
70
|
-
<div className="wasm-demo-page">
|
71
|
-
<h1>WebAssembly Integration Demo</h1>
|
72
|
-
|
73
|
-
{!wasm && (
|
74
|
-
<div className="wasm-status error">
|
75
|
-
<h3>WASM Not Available</h3>
|
76
|
-
<p>WebAssembly module could not be loaded. Please check the console for details.</p>
|
77
|
-
</div>
|
78
|
-
)}
|
79
|
-
|
80
|
-
{error && (
|
81
|
-
<div className="wasm-status error">
|
82
|
-
<h3>Error:</h3>
|
83
|
-
<pre>{error}</pre>
|
84
|
-
</div>
|
85
|
-
)}
|
86
|
-
|
87
|
-
{wasm && (
|
88
|
-
<div className="wasm-status success">
|
89
|
-
<h3>WASM Module Loaded Successfully</h3>
|
90
|
-
<p>The Go WebAssembly module has been loaded and is ready to use.</p>
|
91
|
-
</div>
|
92
|
-
)}
|
93
|
-
|
94
|
-
<div className="demo-section">
|
95
|
-
<h2>WASM Addition</h2>
|
96
|
-
<div className="calculator">
|
97
|
-
<input
|
98
|
-
type="number"
|
99
|
-
value={num1}
|
100
|
-
onChange={(e) => setNum1(e.target.value)}
|
101
|
-
/>
|
102
|
-
<span> + </span>
|
103
|
-
<input
|
104
|
-
type="number"
|
105
|
-
value={num2}
|
106
|
-
onChange={(e) => setNum2(e.target.value)}
|
107
|
-
/>
|
108
|
-
<button onClick={calculateResult}>Calculate</button>
|
109
|
-
<div className="result">
|
110
|
-
Result: <strong>{result}</strong>
|
111
|
-
</div>
|
112
|
-
</div>
|
113
|
-
|
114
|
-
<h2>WASM JSON Parsing</h2>
|
115
|
-
<div className="json-parser">
|
116
|
-
<textarea
|
117
|
-
rows="5"
|
118
|
-
value={jsonInput}
|
119
|
-
onChange={(e) => setJsonInput(e.target.value)}
|
120
|
-
/>
|
121
|
-
<button onClick={parseJsonWithWasm}>Parse JSON</button>
|
122
|
-
{jsonResult && (
|
123
|
-
<pre className="json-result">{jsonResult}</pre>
|
124
|
-
)}
|
125
|
-
</div>
|
126
|
-
|
127
|
-
<h2>Available WASM Functions</h2>
|
128
|
-
<ul className="function-list">
|
129
|
-
{wasm && Object.keys(wasm.functions).map(funcName => (
|
130
|
-
<li key={funcName}>{funcName}</li>
|
131
|
-
))}
|
132
|
-
</ul>
|
133
|
-
</div>
|
134
|
-
</div>
|
135
|
-
);
|
136
|
-
}
|
@@ -1,186 +0,0 @@
|
|
1
|
-
import express from 'express';
|
2
|
-
import path from 'path';
|
3
|
-
import fs from 'fs';
|
4
|
-
import { fileURLToPath } from 'url';
|
5
|
-
import compression from 'compression';
|
6
|
-
import cors from 'cors';
|
7
|
-
import { Server as SocketServer } from 'socket.io';
|
8
|
-
import http from 'http';
|
9
|
-
import dotenv from 'dotenv';
|
10
|
-
|
11
|
-
// Import from frontend-hamroun
|
12
|
-
import {
|
13
|
-
renderToString,
|
14
|
-
loadGoWasmFromFile,
|
15
|
-
initNodeWasm
|
16
|
-
} from 'frontend-hamroun/server';
|
17
|
-
|
18
|
-
// Import components
|
19
|
-
import App from './components/App.js';
|
20
|
-
import { ApiRouter } from './api/index.js';
|
21
|
-
|
22
|
-
// Load environment variables
|
23
|
-
dotenv.config();
|
24
|
-
|
25
|
-
// Get __dirname equivalent in ESM
|
26
|
-
const __filename = fileURLToPath(import.meta.url);
|
27
|
-
const __dirname = path.dirname(__filename);
|
28
|
-
|
29
|
-
// Server configuration
|
30
|
-
const PORT = process.env.PORT || 3000;
|
31
|
-
const PUBLIC_DIR = path.join(__dirname, 'public');
|
32
|
-
const isProd = process.env.NODE_ENV === 'production';
|
33
|
-
|
34
|
-
// Initialize the express app
|
35
|
-
const app = express();
|
36
|
-
const server = http.createServer(app);
|
37
|
-
const io = new SocketServer(server);
|
38
|
-
|
39
|
-
// WASM state
|
40
|
-
let wasmInstance = null;
|
41
|
-
|
42
|
-
// Middleware
|
43
|
-
app.use(compression()); // Compress responses
|
44
|
-
app.use(express.json()); // Parse JSON request bodies
|
45
|
-
app.use(express.urlencoded({ extended: true })); // Parse URL-encoded request bodies
|
46
|
-
app.use(cors()); // Enable CORS
|
47
|
-
|
48
|
-
// Serve static files
|
49
|
-
app.use(express.static(PUBLIC_DIR));
|
50
|
-
|
51
|
-
// Setup API routes
|
52
|
-
app.use('/api', ApiRouter);
|
53
|
-
|
54
|
-
// Setup Socket.IO
|
55
|
-
io.on('connection', (socket) => {
|
56
|
-
console.log('New client connected');
|
57
|
-
|
58
|
-
socket.on('message', (data) => {
|
59
|
-
console.log('Message received:', data);
|
60
|
-
io.emit('message', data); // Broadcast to all clients
|
61
|
-
});
|
62
|
-
|
63
|
-
socket.on('disconnect', () => {
|
64
|
-
console.log('Client disconnected');
|
65
|
-
});
|
66
|
-
});
|
67
|
-
|
68
|
-
// Initialize WASM
|
69
|
-
async function initWasm() {
|
70
|
-
try {
|
71
|
-
// Initialize Node WASM environment
|
72
|
-
await initNodeWasm();
|
73
|
-
|
74
|
-
// Check if WASM file exists
|
75
|
-
const wasmPath = path.join(__dirname, 'public/wasm/example.wasm');
|
76
|
-
if (fs.existsSync(wasmPath)) {
|
77
|
-
// Load WASM module
|
78
|
-
wasmInstance = await loadGoWasmFromFile(wasmPath, {
|
79
|
-
debug: false,
|
80
|
-
goWasmPath: path.join(__dirname, 'public/wasm/wasm_exec.js')
|
81
|
-
});
|
82
|
-
|
83
|
-
console.log('Server WASM module loaded successfully');
|
84
|
-
} else {
|
85
|
-
console.log('WASM file not found, skipping WASM initialization');
|
86
|
-
}
|
87
|
-
} catch (error) {
|
88
|
-
console.error('Failed to initialize WASM:', error);
|
89
|
-
}
|
90
|
-
}
|
91
|
-
|
92
|
-
// Handle all other requests with SSR
|
93
|
-
app.get('*', async (req, res) => {
|
94
|
-
try {
|
95
|
-
// Prepare context for rendering
|
96
|
-
const context = {
|
97
|
-
url: req.url,
|
98
|
-
wasm: wasmInstance,
|
99
|
-
initialData: {
|
100
|
-
// Add any data needed for initial render
|
101
|
-
path: req.path,
|
102
|
-
query: req.query,
|
103
|
-
timestamp: new Date().toISOString()
|
104
|
-
}
|
105
|
-
};
|
106
|
-
|
107
|
-
// Render app to string
|
108
|
-
const appHtml = renderToString(<App context={context} />);
|
109
|
-
|
110
|
-
// Format the initial data as JSON for client hydration
|
111
|
-
const initialDataScript = `
|
112
|
-
<script id="__INITIAL_DATA__" type="application/json">
|
113
|
-
${JSON.stringify(context.initialData).replace(/</g, '\\u003c')}
|
114
|
-
</script>
|
115
|
-
`;
|
116
|
-
|
117
|
-
// Generate full HTML
|
118
|
-
const html = `
|
119
|
-
<!DOCTYPE html>
|
120
|
-
<html lang="en">
|
121
|
-
<head>
|
122
|
-
<meta charset="UTF-8">
|
123
|
-
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
124
|
-
<title>Complete Baraqex App</title>
|
125
|
-
<link rel="stylesheet" href="/styles.css">
|
126
|
-
</head>
|
127
|
-
<body>
|
128
|
-
<div id="app" data-ssr>${appHtml}</div>
|
129
|
-
${initialDataScript}
|
130
|
-
<script type="module" src="/client.js"></script>
|
131
|
-
</body>
|
132
|
-
</html>
|
133
|
-
`;
|
134
|
-
|
135
|
-
res.send(html);
|
136
|
-
} catch (error) {
|
137
|
-
console.error('Error rendering page:', error);
|
138
|
-
|
139
|
-
// Send error page
|
140
|
-
res.status(500).send(`
|
141
|
-
<!DOCTYPE html>
|
142
|
-
<html>
|
143
|
-
<head>
|
144
|
-
<title>Server Error</title>
|
145
|
-
<style>
|
146
|
-
body { font-family: system-ui, sans-serif; padding: 2rem; line-height: 1.5; }
|
147
|
-
.error { background: #fff0f0; border: 1px solid #ffcaca; border-radius: 4px; padding: 1rem; }
|
148
|
-
pre { background: #f5f5f5; padding: 1rem; overflow: auto; border-radius: 4px; }
|
149
|
-
</style>
|
150
|
-
</head>
|
151
|
-
<body>
|
152
|
-
<h1>Server Error</h1>
|
153
|
-
<div class="error">
|
154
|
-
<p>${error.message}</p>
|
155
|
-
${isProd ? '' : `<pre>${error.stack}</pre>`}
|
156
|
-
</div>
|
157
|
-
</body>
|
158
|
-
</html>
|
159
|
-
`);
|
160
|
-
}
|
161
|
-
});
|
162
|
-
|
163
|
-
// Start the server
|
164
|
-
async function startServer() {
|
165
|
-
// Initialize WASM
|
166
|
-
await initWasm();
|
167
|
-
|
168
|
-
// Start listening
|
169
|
-
server.listen(PORT, () => {
|
170
|
-
console.log(`
|
171
|
-
┌─────────────────────────────────────────────────────┐
|
172
|
-
│ │
|
173
|
-
│ Complete Baraqex App Server running! │
|
174
|
-
│ │
|
175
|
-
│ - Local: http://localhost:${PORT} │
|
176
|
-
│ - API: http://localhost:${PORT}/api │
|
177
|
-
│ │
|
178
|
-
│ Mode: ${isProd ? 'production' : 'development'} │
|
179
|
-
│ │
|
180
|
-
└─────────────────────────────────────────────────────┘
|
181
|
-
`);
|
182
|
-
});
|
183
|
-
}
|
184
|
-
|
185
|
-
// Run the server
|
186
|
-
startServer().catch(console.error);
|
@@ -1,16 +0,0 @@
|
|
1
|
-
@echo off
|
2
|
-
echo Building Go WASM module...
|
3
|
-
|
4
|
-
set GOOS=js
|
5
|
-
set GOARCH=wasm
|
6
|
-
go build -o example.wasm example.go
|
7
|
-
|
8
|
-
if %ERRORLEVEL% NEQ 0 (
|
9
|
-
echo Error: Failed to build Go WASM module
|
10
|
-
exit /b 1
|
11
|
-
)
|
12
|
-
|
13
|
-
for /f "tokens=*" %%g in ('go env GOROOT') do (set GOROOT=%%g)
|
14
|
-
copy "%GOROOT%\misc\wasm\wasm_exec.js" .
|
15
|
-
|
16
|
-
echo Build complete!
|
@@ -1,16 +0,0 @@
|
|
1
|
-
#!/bin/bash
|
2
|
-
echo "Building Go WASM module..."
|
3
|
-
|
4
|
-
# Set environment variables for Go to compile to WASM
|
5
|
-
GOOS=js GOARCH=wasm go build -o example.wasm example.go
|
6
|
-
|
7
|
-
if [ $? -ne 0 ]; then
|
8
|
-
echo "Error: Failed to build Go WASM module"
|
9
|
-
exit 1
|
10
|
-
fi
|
11
|
-
|
12
|
-
# Get Go WASM exec runtime
|
13
|
-
GOROOT=$(go env GOROOT)
|
14
|
-
cp "$GOROOT/misc/wasm/wasm_exec.js" .
|
15
|
-
|
16
|
-
echo "Build completed!"
|
@@ -1,101 +0,0 @@
|
|
1
|
-
package main
|
2
|
-
|
3
|
-
import (
|
4
|
-
"encoding/json"
|
5
|
-
"fmt"
|
6
|
-
"syscall/js"
|
7
|
-
)
|
8
|
-
|
9
|
-
// These functions will be exposed to JavaScript
|
10
|
-
func main() {
|
11
|
-
// Set up functions we want to expose to JavaScript
|
12
|
-
js.Global().Set("goAdd", js.FuncOf(add))
|
13
|
-
js.Global().Set("goSubtract", js.FuncOf(subtract))
|
14
|
-
js.Global().Set("goMultiply", js.FuncOf(multiply))
|
15
|
-
js.Global().Set("goDivide", js.FuncOf(divide))
|
16
|
-
js.Global().Set("goParseJSON", js.FuncOf(parseJSON))
|
17
|
-
|
18
|
-
// Print to browser console
|
19
|
-
fmt.Println("Go WASM module initialized")
|
20
|
-
|
21
|
-
// Keep the program running
|
22
|
-
<-make(chan bool)
|
23
|
-
}
|
24
|
-
|
25
|
-
// add adds two numbers and returns the result
|
26
|
-
func add(this js.Value, args []js.Value) interface{} {
|
27
|
-
if len(args) != 2 {
|
28
|
-
return js.Error{Message: "Invalid number of arguments passed to add"}
|
29
|
-
}
|
30
|
-
|
31
|
-
// Convert the JavaScript values to Go values
|
32
|
-
a := args[0].Int()
|
33
|
-
b := args[1].Int()
|
34
|
-
|
35
|
-
return a + b
|
36
|
-
}
|
37
|
-
|
38
|
-
// subtract subtracts the second number from the first and returns the result
|
39
|
-
func subtract(this js.Value, args []js.Value) interface{} {
|
40
|
-
if len(args) != 2 {
|
41
|
-
return js.Error{Message: "Invalid number of arguments passed to subtract"}
|
42
|
-
}
|
43
|
-
|
44
|
-
a := args[0].Int()
|
45
|
-
b := args[1].Int()
|
46
|
-
|
47
|
-
return a - b
|
48
|
-
}
|
49
|
-
|
50
|
-
// multiply multiplies two numbers and returns the result
|
51
|
-
func multiply(this js.Value, args []js.Value) interface{} {
|
52
|
-
if len(args) != 2 {
|
53
|
-
return js.Error{Message: "Invalid number of arguments passed to multiply"}
|
54
|
-
}
|
55
|
-
|
56
|
-
a := args[0].Int()
|
57
|
-
b := args[1].Int()
|
58
|
-
|
59
|
-
return a * b
|
60
|
-
}
|
61
|
-
|
62
|
-
// divide divides the first number by the second and returns the result
|
63
|
-
func divide(this js.Value, args []js.Value) interface{} {
|
64
|
-
if len(args) != 2 {
|
65
|
-
return js.Error{Message: "Invalid number of arguments passed to divide"}
|
66
|
-
}
|
67
|
-
|
68
|
-
a := args[0].Int()
|
69
|
-
b := args[1].Int()
|
70
|
-
|
71
|
-
if b == 0 {
|
72
|
-
return js.Error{Message: "Division by zero"}
|
73
|
-
}
|
74
|
-
|
75
|
-
return a / b
|
76
|
-
}
|
77
|
-
|
78
|
-
// parseJSON parses a JSON string and returns a JavaScript object
|
79
|
-
func parseJSON(this js.Value, args []js.Value) interface{} {
|
80
|
-
if len(args) != 1 {
|
81
|
-
return js.Error{Message: "Invalid number of arguments passed to parseJSON"}
|
82
|
-
}
|
83
|
-
|
84
|
-
// Get the JSON string from JavaScript
|
85
|
-
jsonStr := args[0].String()
|
86
|
-
|
87
|
-
// Parse the JSON string into a map
|
88
|
-
var data map[string]interface{}
|
89
|
-
if err := json.Unmarshal([]byte(jsonStr), &data); err != nil {
|
90
|
-
return js.Error{Message: "Error parsing JSON: " + err.Error()}
|
91
|
-
}
|
92
|
-
|
93
|
-
// Convert the map to a JavaScript object
|
94
|
-
result := make(map[string]interface{})
|
95
|
-
for k, v := range data {
|
96
|
-
result[k] = v
|
97
|
-
}
|
98
|
-
|
99
|
-
// Return the JavaScript object
|
100
|
-
return result
|
101
|
-
}
|