frontend-hamroun 1.2.74 → 1.2.75

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.
Files changed (99) hide show
  1. package/dist/Counter.d.ts +0 -0
  2. package/dist/hooks-0728361a.cjs +1 -0
  3. package/dist/hooks-b58f947c.js +133 -0
  4. package/dist/hooks.js +1 -0
  5. package/dist/hooks.mjs +13 -0
  6. package/dist/index.js +1 -384
  7. package/dist/index.mjs +130 -374
  8. package/dist/jsx-runtime.js +1 -0
  9. package/dist/jsx-runtime.mjs +64 -0
  10. package/dist/renderer.js +1 -0
  11. package/dist/renderer.mjs +27 -0
  12. package/dist/server/src/batch.d.ts +3 -0
  13. package/dist/server/src/batch.js +23 -0
  14. package/dist/server/src/batch.js.map +1 -0
  15. package/dist/server/src/component.d.ts +14 -0
  16. package/dist/server/src/component.js +106 -0
  17. package/dist/server/src/component.js.map +1 -0
  18. package/dist/server/src/context.d.ts +13 -0
  19. package/dist/server/src/context.js +21 -0
  20. package/dist/server/src/context.js.map +1 -0
  21. package/dist/server/src/hooks.d.ts +12 -0
  22. package/dist/server/src/hooks.js +170 -0
  23. package/dist/server/src/hooks.js.map +1 -0
  24. package/dist/server/src/index.client.d.ts +12 -0
  25. package/dist/server/src/index.client.js +14 -0
  26. package/dist/server/src/index.client.js.map +1 -0
  27. package/dist/server/src/index.d.ts +88 -0
  28. package/dist/server/src/index.js +70 -0
  29. package/dist/server/src/index.js.map +1 -0
  30. package/dist/server/src/jsx-runtime/jsx-dev-runtime.d.ts +1 -0
  31. package/dist/server/src/jsx-runtime/jsx-dev-runtime.js +2 -0
  32. package/dist/server/src/jsx-runtime/jsx-dev-runtime.js.map +1 -0
  33. package/dist/server/src/jsx-runtime/jsx-runtime.d.ts +4 -0
  34. package/dist/server/src/jsx-runtime/jsx-runtime.js +41 -0
  35. package/dist/server/src/jsx-runtime/jsx-runtime.js.map +1 -0
  36. package/dist/server/src/jsx-runtime.d.ts +20 -0
  37. package/dist/server/src/jsx-runtime.js +105 -0
  38. package/dist/server/src/jsx-runtime.js.map +1 -0
  39. package/dist/server/src/renderComponent.d.ts +14 -0
  40. package/dist/server/src/renderComponent.js +25 -0
  41. package/dist/server/src/renderComponent.js.map +1 -0
  42. package/dist/server/src/renderer.d.ts +2 -0
  43. package/dist/server/src/renderer.js +31 -0
  44. package/dist/server/src/renderer.js.map +1 -0
  45. package/dist/server/src/server/api-router.d.ts +15 -0
  46. package/dist/server/src/server/api-router.js +111 -0
  47. package/dist/server/src/server/api-router.js.map +1 -0
  48. package/dist/server/src/server/auth.d.ts +32 -0
  49. package/dist/server/src/server/auth.js +80 -0
  50. package/dist/server/src/server/auth.js.map +1 -0
  51. package/dist/server/src/server/database.d.ts +24 -0
  52. package/dist/server/src/server/database.js +135 -0
  53. package/dist/server/src/server/database.js.map +1 -0
  54. package/dist/server/src/server/index.d.ts +54 -0
  55. package/dist/server/src/server/index.js +172 -0
  56. package/dist/server/src/server/index.js.map +1 -0
  57. package/dist/server/src/server/middleware.d.ts +11 -0
  58. package/dist/server/src/server/middleware.js +46 -0
  59. package/dist/server/src/server/middleware.js.map +1 -0
  60. package/dist/server/src/server/server.d.ts +9 -0
  61. package/dist/server/src/server/server.js +87 -0
  62. package/dist/server/src/server/server.js.map +1 -0
  63. package/dist/server/src/server/types.d.ts +38 -0
  64. package/dist/server/src/server/types.js +4 -0
  65. package/dist/server/src/server/types.js.map +1 -0
  66. package/dist/server/src/server/wasm.d.ts +9 -0
  67. package/dist/server/src/server/wasm.js +117 -0
  68. package/dist/server/src/server/wasm.js.map +1 -0
  69. package/dist/server/src/server-renderer.d.ts +5 -0
  70. package/dist/server/src/server-renderer.js +106 -0
  71. package/dist/server/src/server-renderer.js.map +1 -0
  72. package/dist/server/src/server-types.d.ts +42 -0
  73. package/dist/server/src/server-types.js +6 -0
  74. package/dist/server/src/server-types.js.map +1 -0
  75. package/dist/server/src/types.d.ts +19 -0
  76. package/dist/server/src/types.js +2 -0
  77. package/dist/server/src/types.js.map +1 -0
  78. package/dist/server/src/vdom.d.ts +8 -0
  79. package/dist/server/src/vdom.js +22 -0
  80. package/dist/server/src/vdom.js.map +1 -0
  81. package/dist/server/src/wasm.d.ts +36 -0
  82. package/dist/server/src/wasm.js +159 -0
  83. package/dist/server/src/wasm.js.map +1 -0
  84. package/dist/server/tsconfig.server.tsbuildinfo +1 -0
  85. package/dist/server/wasm.d.ts +7 -0
  86. package/dist/server-renderer.js +1 -0
  87. package/dist/server-renderer.mjs +64 -0
  88. package/dist/wasm.d.ts +37 -0
  89. package/dist/wasm.js +1 -0
  90. package/dist/wasm.mjs +103 -0
  91. package/package.json +1 -1
  92. package/templates/go/build.sh +43 -43
  93. package/templates/go-wasm-app/build-wasm.js +84 -84
  94. package/templates/go-wasm-app/package.json +6 -5
  95. package/templates/go-wasm-app/public/index.html +49 -53
  96. package/templates/go-wasm-app/server.js +0 -188
  97. package/dist/index.d.ts +0 -1
  98. package/dist/index.js.map +0 -1
  99. package/dist/index.mjs.map +0 -1
@@ -0,0 +1,64 @@
1
+ import { p as u, h as y } from "./hooks-b58f947c.js";
2
+ function m(r) {
3
+ u();
4
+ const p = c(r);
5
+ return y(), p;
6
+ }
7
+ function c(r) {
8
+ var p, l, f;
9
+ if (r == null || typeof r == "boolean")
10
+ return "";
11
+ if (typeof r == "number" || typeof r == "string")
12
+ return o(String(r));
13
+ if (typeof r.type == "function") {
14
+ const t = r.type, e = t(r.props || {});
15
+ return c(e);
16
+ }
17
+ if (typeof r.type == "string") {
18
+ const t = r.type;
19
+ let e = "", s = "";
20
+ if (r.props) {
21
+ for (const [n, i] of Object.entries(r.props))
22
+ if (n !== "children" && !n.startsWith("on")) {
23
+ if (n === "className") {
24
+ e += ` class="${o(i)}"`;
25
+ continue;
26
+ }
27
+ typeof i == "string" || typeof i == "number" ? e += ` ${n}="${o(String(i))}"` : i === !0 && (e += ` ${n}`);
28
+ }
29
+ }
30
+ const a = (p = r.props) != null && p.children ? Array.isArray(r.props.children) ? r.props.children : [r.props.children] : [];
31
+ for (const n of a)
32
+ s += c(n);
33
+ return [
34
+ "area",
35
+ "base",
36
+ "br",
37
+ "col",
38
+ "embed",
39
+ "hr",
40
+ "img",
41
+ "input",
42
+ "link",
43
+ "meta",
44
+ "param",
45
+ "source",
46
+ "track",
47
+ "wbr"
48
+ ].includes(t) ? `<${t}${e}/>` : `<${t}${e}>${s}</${t}>`;
49
+ }
50
+ if (r.type === Symbol.for("react.fragment")) {
51
+ let t = "";
52
+ const e = Array.isArray((l = r.props) == null ? void 0 : l.children) ? r.props.children : (f = r.props) != null && f.children ? [r.props.children] : [];
53
+ for (const s of e)
54
+ t += c(s);
55
+ return t;
56
+ }
57
+ return console.warn("Unknown vnode type:", r.type), "";
58
+ }
59
+ function o(r) {
60
+ return r.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;").replace(/"/g, "&quot;").replace(/'/g, "&#039;");
61
+ }
62
+ export {
63
+ m as renderToString
64
+ };
package/dist/wasm.d.ts ADDED
@@ -0,0 +1,37 @@
1
+ export interface GoWasmInstance {
2
+ instance: WebAssembly.Instance;
3
+ module: WebAssembly.Module;
4
+ exports: any;
5
+ functions: Record<string, Function>;
6
+ }
7
+
8
+ export interface GoWasmOptions {
9
+ goWasmPath?: string;
10
+ importObject?: WebAssembly.Imports;
11
+ loadGo?: boolean;
12
+ onLoad?: (instance: GoWasmInstance) => void;
13
+ debug?: boolean;
14
+ }
15
+
16
+ export declare function loadGoWasm(
17
+ wasmUrl: string,
18
+ options?: GoWasmOptions
19
+ ): Promise<GoWasmInstance>;
20
+
21
+ export declare function createTypedWasmFunction<T extends (...args: any[]) => any>(
22
+ instance: GoWasmInstance,
23
+ functionName: string
24
+ ): T;
25
+
26
+ export declare const goValues: {
27
+ stringToGo: (instance: GoWasmInstance, str: string) => number;
28
+ stringFromGo: (instance: GoWasmInstance, ptr: number) => string;
29
+ objectToGo: (instance: GoWasmInstance, obj: any) => number;
30
+ objectFromGo: (instance: GoWasmInstance, ptr: number) => any;
31
+ };
32
+
33
+ export declare const wasm: {
34
+ loadGoWasm: typeof loadGoWasm;
35
+ createTypedWasmFunction: typeof createTypedWasmFunction;
36
+ goValues: typeof goValues;
37
+ };
package/dist/wasm.js ADDED
@@ -0,0 +1 @@
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const W="/wasm_exec.js";async function A(o,t={}){const{importObject:s={},goWasmPath:c=W,loadGo:p=!0,onLoad:_,debug:l=!1}=t;typeof window<"u"&&p&&await S(c);try{const e=typeof Go<"u"?new Go:null;l&&console.log(`[WASM] Loading module from ${o}`);const a=await fetch(o);if(!a.ok)throw new Error(`Failed to fetch WASM module: ${a.statusText}`);const b=await a.arrayBuffer(),g=await WebAssembly.compile(b),y=e?{...e.importObject,...s}:s,w=await WebAssembly.instantiate(g,y);e&&e.run(w);const d=w.exports,r={};for(const n in d)if(typeof d[n]=="function"){const m=d[n];if(r[n]=(...i)=>m(...i),l){const i=r[n];r[n]=(...u)=>{console.log(`[WASM] Calling ${n}(${u.join(", ")})`);const f=i(...u);return console.log(`[WASM] ${n} returned:`,f),f}}}if(typeof window<"u"){for(const n in window)if(n.startsWith("go")&&typeof window[n]=="function"){const m=window[n];if(r[n]=(...i)=>m(...i),l){const i=r[n];r[n]=(...u)=>{console.log(`[WASM] Calling global ${n}(${u.join(", ")})`);const f=i(...u);return console.log(`[WASM] ${n} returned:`,f),f}}}}const G={instance:w,module:g,exports:d,functions:r};return _&&_(G),G}catch(e){throw console.error("[WASM] Failed to load Go WASM module:",e),e}}async function S(o=W){if(!(typeof window>"u")&&!(typeof window.Go<"u"))return new Promise((t,s)=>{const c=document.createElement("script");c.src=o,c.onload=()=>t(),c.onerror=()=>s(new Error(`Failed to load Go WASM runtime from ${o}`)),document.head.appendChild(c)})}function F(o,t){if(!o.functions[t])throw new Error(`WASM function "${t}" not found`);return o.functions[t]}const M={stringToGo:(o,t)=>{if(!o.functions.__stringToGo)throw new Error("__stringToGo function not found in WASM module");return o.functions.__stringToGo(t)},stringFromGo:(o,t)=>{if(!o.functions.__stringFromGo)throw new Error("__stringFromGo function not found in WASM module");return o.functions.__stringFromGo(t)},objectToGo:(o,t)=>{if(!o.functions.__objectToGo)throw new Error("__objectToGo function not found in WASM module");return o.functions.__objectToGo(JSON.stringify(t))},objectFromGo:(o,t)=>{if(!o.functions.__objectFromGo)throw new Error("__objectFromGo function not found in WASM module");const s=o.functions.__objectFromGo(t);return JSON.parse(s)}};exports.createTypedWasmFunction=F;exports.goValues=M;exports.loadGoWasm=A;
package/dist/wasm.mjs ADDED
@@ -0,0 +1,103 @@
1
+ const p = "/wasm_exec.js";
2
+ async function F(o, t = {}) {
3
+ const {
4
+ importObject: s = {},
5
+ goWasmPath: c = p,
6
+ loadGo: W = !0,
7
+ onLoad: _,
8
+ debug: l = !1
9
+ } = t;
10
+ typeof window < "u" && W && await y(c);
11
+ try {
12
+ const e = typeof Go < "u" ? new Go() : null;
13
+ l && console.log(`[WASM] Loading module from ${o}`);
14
+ const a = await fetch(o);
15
+ if (!a.ok)
16
+ throw new Error(`Failed to fetch WASM module: ${a.statusText}`);
17
+ const b = await a.arrayBuffer(), G = await WebAssembly.compile(b), A = e ? {
18
+ ...e.importObject,
19
+ ...s
20
+ } : s, w = await WebAssembly.instantiate(G, A);
21
+ e && e.run(w);
22
+ const d = w.exports, r = {};
23
+ for (const n in d)
24
+ if (typeof d[n] == "function") {
25
+ const m = d[n];
26
+ if (r[n] = (...i) => m(...i), l) {
27
+ const i = r[n];
28
+ r[n] = (...f) => {
29
+ console.log(`[WASM] Calling ${n}(${f.join(", ")})`);
30
+ const u = i(...f);
31
+ return console.log(`[WASM] ${n} returned:`, u), u;
32
+ };
33
+ }
34
+ }
35
+ if (typeof window < "u") {
36
+ for (const n in window)
37
+ if (n.startsWith("go") && typeof window[n] == "function") {
38
+ const m = window[n];
39
+ if (r[n] = (...i) => m(...i), l) {
40
+ const i = r[n];
41
+ r[n] = (...f) => {
42
+ console.log(`[WASM] Calling global ${n}(${f.join(", ")})`);
43
+ const u = i(...f);
44
+ return console.log(`[WASM] ${n} returned:`, u), u;
45
+ };
46
+ }
47
+ }
48
+ }
49
+ const g = {
50
+ instance: w,
51
+ module: G,
52
+ exports: d,
53
+ functions: r
54
+ };
55
+ return _ && _(g), g;
56
+ } catch (e) {
57
+ throw console.error("[WASM] Failed to load Go WASM module:", e), e;
58
+ }
59
+ }
60
+ async function y(o = p) {
61
+ if (!(typeof window > "u") && !(typeof window.Go < "u"))
62
+ return new Promise((t, s) => {
63
+ const c = document.createElement("script");
64
+ c.src = o, c.onload = () => t(), c.onerror = () => s(new Error(`Failed to load Go WASM runtime from ${o}`)), document.head.appendChild(c);
65
+ });
66
+ }
67
+ function S(o, t) {
68
+ if (!o.functions[t])
69
+ throw new Error(`WASM function "${t}" not found`);
70
+ return o.functions[t];
71
+ }
72
+ const M = {
73
+ // Convert JS string to Go string (returns memory pointer)
74
+ stringToGo: (o, t) => {
75
+ if (!o.functions.__stringToGo)
76
+ throw new Error("__stringToGo function not found in WASM module");
77
+ return o.functions.__stringToGo(t);
78
+ },
79
+ // Convert Go string (memory pointer) to JS string
80
+ stringFromGo: (o, t) => {
81
+ if (!o.functions.__stringFromGo)
82
+ throw new Error("__stringFromGo function not found in WASM module");
83
+ return o.functions.__stringFromGo(t);
84
+ },
85
+ // Convert JS object to Go (returns memory pointer)
86
+ objectToGo: (o, t) => {
87
+ if (!o.functions.__objectToGo)
88
+ throw new Error("__objectToGo function not found in WASM module");
89
+ return o.functions.__objectToGo(JSON.stringify(t));
90
+ },
91
+ // Convert Go object (memory pointer) to JS object
92
+ objectFromGo: (o, t) => {
93
+ if (!o.functions.__objectFromGo)
94
+ throw new Error("__objectFromGo function not found in WASM module");
95
+ const s = o.functions.__objectFromGo(t);
96
+ return JSON.parse(s);
97
+ }
98
+ };
99
+ export {
100
+ S as createTypedWasmFunction,
101
+ M as goValues,
102
+ F as loadGoWasm
103
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "frontend-hamroun",
3
- "version": "1.2.74",
3
+ "version": "1.2.75",
4
4
  "description": "A lightweight full-stack JavaScript framework",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
@@ -1,43 +1,43 @@
1
- #!/bin/bash
2
-
3
- # Build script for Go WASM modules
4
-
5
- # Ensure Go is installed
6
- if ! command -v go &> /dev/null; then
7
- echo "Error: Go is not installed"
8
- exit 1
9
- fi
10
-
11
- # Check Go version
12
- GO_VERSION=$(go version | cut -d ' ' -f 3 | sed 's/go//')
13
- GO_VERSION_MAJOR=$(echo $GO_VERSION | cut -d '.' -f 1)
14
- GO_VERSION_MINOR=$(echo $GO_VERSION | cut -d '.' -f 2)
15
-
16
- if [ $GO_VERSION_MAJOR -lt 1 ] || ([ $GO_VERSION_MAJOR -eq 1 ] && [ $GO_VERSION_MINOR -lt 16 ]); then
17
- echo "Warning: Go version 1.16+ recommended for WebAssembly, detected $GO_VERSION"
18
- fi
19
-
20
- # Build example WASM module
21
- echo "Building example Go WASM module..."
22
- GOOS=js GOARCH=wasm go build -o example.wasm example.go
23
- if [ $? -ne 0 ]; then
24
- echo "Error: Failed to build Go WASM module"
25
- exit 1
26
- fi
27
-
28
- # Copy wasm_exec.js files for browser and Node.js from Go installation
29
- GO_ROOT=$(go env GOROOT)
30
- echo "Copying wasm_exec.js files from $GO_ROOT/misc/wasm/"
31
- cp "$GO_ROOT/misc/wasm/wasm_exec.js" ./
32
- cp "$GO_ROOT/misc/wasm/wasm_exec_node.js" ./
33
-
34
- echo "Build complete!"
35
- echo "Files created:"
36
- echo "- example.wasm - WebAssembly module"
37
- echo "- wasm_exec.js - Browser runtime"
38
- echo "- wasm_exec_node.js - Node.js runtime"
39
-
40
- echo ""
41
- echo "Usage:"
42
- echo "1. Copy these files to your project's public directory"
43
- echo "2. Load the WASM module using the provided utilities"
1
+ #!/bin/bash
2
+
3
+ # Build script for Go WASM modules
4
+
5
+ # Ensure Go is installed
6
+ if ! command -v go &> /dev/null; then
7
+ echo "Error: Go is not installed"
8
+ exit 1
9
+ fi
10
+
11
+ # Check Go version
12
+ GO_VERSION=$(go version | cut -d ' ' -f 3 | sed 's/go//')
13
+ GO_VERSION_MAJOR=$(echo $GO_VERSION | cut -d '.' -f 1)
14
+ GO_VERSION_MINOR=$(echo $GO_VERSION | cut -d '.' -f 2)
15
+
16
+ if [ $GO_VERSION_MAJOR -lt 1 ] || ([ $GO_VERSION_MAJOR -eq 1 ] && [ $GO_VERSION_MINOR -lt 16 ]); then
17
+ echo "Warning: Go version 1.16+ recommended for WebAssembly, detected $GO_VERSION"
18
+ fi
19
+
20
+ # Build example WASM module
21
+ echo "Building example Go WASM module..."
22
+ GOOS=js GOARCH=wasm go build -o example.wasm example.go
23
+ if [ $? -ne 0 ]; then
24
+ echo "Error: Failed to build Go WASM module"
25
+ exit 1
26
+ fi
27
+
28
+ # Copy wasm_exec.js files for browser and Node.js from Go installation
29
+ GO_ROOT=$(go env GOROOT)
30
+ echo "Copying wasm_exec.js files from $GO_ROOT/misc/wasm/"
31
+ cp "$GO_ROOT/misc/wasm/wasm_exec.js" ./
32
+ cp "$GO_ROOT/misc/wasm/wasm_exec_node.js" ./
33
+
34
+ echo "Build complete!"
35
+ echo "Files created:"
36
+ echo "- example.wasm - WebAssembly module"
37
+ echo "- wasm_exec.js - Browser runtime"
38
+ echo "- wasm_exec_node.js - Node.js runtime"
39
+
40
+ echo ""
41
+ echo "Usage:"
42
+ echo "1. Copy these files to your project's public directory"
43
+ echo "2. Load the WASM module using the provided utilities"
@@ -32,86 +32,7 @@ function ensureDir(dir) {
32
32
  }
33
33
  }
34
34
 
35
- // Build a single Go file to WASM
36
- export async function buildGoFile(goFilePath, wasmFilePath) {
37
- try {
38
- if (!fs.existsSync(goFilePath)) {
39
- throw new Error(`Go file not found: ${goFilePath}`);
40
- }
41
-
42
- console.log(`Building ${goFilePath} to ${wasmFilePath}`);
43
-
44
- // Create a unique temporary directory with timestamp
45
- const timestamp = Date.now();
46
- const tempDir = join(os.tmpdir(), `go-wasm-build-${timestamp}`);
47
-
48
- // Ensure the directory is clean
49
- if (fs.existsSync(tempDir)) {
50
- if (isWindows) {
51
- execSync(`rmdir /s /q "${tempDir}"`, { shell: true });
52
- } else {
53
- fs.rmSync(tempDir, { recursive: true, force: true });
54
- }
55
- }
56
-
57
- // Create the temporary directory
58
- ensureDir(tempDir);
59
-
60
- // Copy the Go file to the temp directory
61
- const goFileName = goFilePath.split(/[/\\]/).pop();
62
- const tempGoFile = join(tempDir, goFileName);
63
- fs.copyFileSync(goFilePath, tempGoFile);
64
-
65
- // Initialize Go module
66
- console.log(`Initializing Go module in ${tempDir}`);
67
- execSync(`go mod init wasmapp`, { cwd: tempDir });
68
-
69
- // Build the WASM module with OS-specific command
70
- if (isWindows) {
71
- // Windows-specific environment variable setting
72
- execSync(`go build -o "${wasmFilePath}" "${tempGoFile}"`, {
73
- cwd: tempDir,
74
- env: {
75
- ...process.env,
76
- GOOS: 'js',
77
- GOARCH: 'wasm'
78
- }
79
- });
80
- } else {
81
- // Unix/Linux/Mac command
82
- execSync(`GOOS=js GOARCH=wasm go build -o "${wasmFilePath}" "${tempGoFile}"`, {
83
- cwd: tempDir
84
- });
85
- }
86
-
87
- // Clean up temporary directory
88
- try {
89
- if (isWindows) {
90
- execSync(`rmdir /s /q "${tempDir}"`, { shell: true });
91
- } else {
92
- fs.rmSync(tempDir, { recursive: true, force: true });
93
- }
94
- } catch (cleanupError) {
95
- console.warn(`Warning: Failed to clean up temp directory ${tempDir}:`, cleanupError);
96
- }
97
-
98
- console.log(`✓ Successfully built ${goFileName} to WASM`);
99
- return {
100
- success: true,
101
- wasmPath: wasmFilePath,
102
- goFile: goFilePath
103
- };
104
- } catch (error) {
105
- console.error(`✗ Error building ${goFilePath}:`, error);
106
- return {
107
- success: false,
108
- error: error.message,
109
- goFile: goFilePath
110
- };
111
- }
112
- }
113
-
114
- // Build all Go WASM modules
35
+ // Build Go WASM modules
115
36
  async function buildWasmModules() {
116
37
  // Check if Go is installed
117
38
  if (!checkGoInstallation()) {
@@ -144,13 +65,92 @@ async function buildWasmModules() {
144
65
  console.log(`Copying ${wasmExecNodeJsPath} to ${wasmExecNodeJsDest}`);
145
66
  fs.copyFileSync(wasmExecNodeJsPath, wasmExecNodeJsDest);
146
67
 
147
- // Generate a default example.go file if no Go files exist
148
- const goFiles = fs.existsSync(goSourceDir) ?
149
- fs.readdirSync(goSourceDir).filter(file => file.endsWith('.go')) : [];
68
+ // Build all Go files in the WASM directory
69
+ const goFiles = fs.readdirSync(goSourceDir).filter(file => file.endsWith('.go'));
150
70
 
151
71
  if (goFiles.length === 0) {
152
- console.log('No Go files found. Creating example.go...');
72
+ console.log('No Go files found in src/wasm');
73
+
74
+ // Create an example Go file
75
+ const exampleGoFile = join(goSourceDir, 'example.go');
76
+ const exampleGoContent = `//go:build js && wasm
77
+ // +build js,wasm
78
+
79
+ package main
80
+
81
+ import (
82
+ "encoding/json"
83
+ "fmt"
84
+ "syscall/js"
85
+ )
86
+
87
+ // Example Go function to be called from JavaScript
88
+ func add(this js.Value, args []js.Value) interface{} {
89
+ if len(args) != 2 {
90
+ return js.ValueOf("Error: Expected two arguments")
91
+ }
92
+
93
+ a := args[0].Int()
94
+ b := args[1].Int()
95
+ return js.ValueOf(a + b)
96
+ }
97
+
98
+ // Process complex data in Go
99
+ func processData(this js.Value, args []js.Value) interface{} {
100
+ if len(args) == 0 {
101
+ return js.ValueOf("Error: Expected at least one argument")
102
+ }
103
+
104
+ // Get input data
105
+ data := args[0]
106
+ if data.Type() != js.TypeObject {
107
+ return js.ValueOf("Error: Expected JSON object")
108
+ }
109
+
110
+ // Convert JS object to Go map
111
+ jsonStr := js.Global().Get("JSON").Call("stringify", data).String()
112
+ var inputMap map[string]interface{}
113
+ if err := json.Unmarshal([]byte(jsonStr), &inputMap); err != nil {
114
+ return js.ValueOf(fmt.Sprintf("Error parsing JSON: %s", err.Error()))
115
+ }
116
+
117
+ // Add new fields
118
+ inputMap["processed"] = true
119
+ inputMap["processor"] = "Go WASM"
120
+
121
+ // Add some computed fields
122
+ if values, ok := inputMap["values"].([]interface{}); ok {
123
+ sum := 0.0
124
+ for _, v := range values {
125
+ if num, ok := v.(float64); ok {
126
+ sum += num
127
+ }
128
+ }
129
+ inputMap["sum"] = sum
130
+ }
131
+
132
+ // Convert back to JS
133
+ resultJSON, err := json.Marshal(inputMap)
134
+ if err != nil {
135
+ return js.ValueOf(fmt.Sprintf("Error generating JSON: %s", err.Error()))
136
+ }
137
+
138
+ return js.ValueOf(string(resultJSON))
139
+ }
140
+
141
+ func main() {
142
+ fmt.Println("Go WASM Module initialized")
143
+
144
+ // Register functions to be callable from JavaScript
145
+ js.Global().Set("goAdd", js.FuncOf(add))
146
+ js.Global().Set("goProcessData", js.FuncOf(processData))
147
+
148
+ // Keep the program running
149
+ <-make(chan bool)
150
+ }
151
+ `;
153
152
 
153
+ fs.writeFileSync(exampleGoFile, exampleGoContent);
154
154
  console.log(`Created example Go file at ${exampleGoFile}`);
155
155
 
156
156
  // Add the new file to the list
@@ -5,18 +5,19 @@
5
5
  "type": "module",
6
6
  "main": "server.js",
7
7
  "scripts": {
8
- "build:dirs": "node -e \"const fs=require('fs');const dirs=['public/wasm','src/wasm','dist'];dirs.forEach(d=>!fs.existsSync(d)&&fs.mkdirSync(d,{recursive:true}))\"",
9
8
  "build:wasm": "node build-wasm.js",
10
- "dev": "npm run build:dirs && npm run build:wasm && node --watch server.js",
11
- "build": "npm run build:dirs && npm run build:wasm && node -e \"require('fs-extra').copySync('public', 'dist')\"",
9
+ "prepare": "node -e \"if (!require('fs').existsSync('public/wasm')) { require('fs').mkdirSync('public/wasm', {recursive: true}); }\"",
10
+ "dev": "npm run build:wasm && node --watch server.js",
11
+ "build": "npm run build:wasm && node -e \"require('fs').mkdirSync('dist', {recursive: true}); require('fs-extra').copySync('public', 'dist')\"",
12
12
  "start": "cross-env NODE_ENV=production node server.js"
13
13
  },
14
14
  "dependencies": {
15
15
  "express": "^4.18.2",
16
- "frontend-hamroun": "^1.2.72",
17
- "fs-extra": "^11.1.1"
16
+ "frontend-hamroun": "^1.2.71",
17
+ "fs-extra": "^10.0.0"
18
18
  },
19
19
  "devDependencies": {
20
+ "@babel/core": "^7.22.9",
20
21
  "cross-env": "^7.0.3"
21
22
  }
22
23
  }
@@ -21,12 +21,12 @@
21
21
  }
22
22
 
23
23
  body {
24
- font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
25
- background-color: var(--background);
26
- color: var(--text-color);
27
- margin: 0;
28
- padding: 0;
24
+ font-family: system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
25
+ max-width: 800px;
26
+ margin: 0 auto;
27
+ padding: 2rem;
29
28
  line-height: 1.6;
29
+ color: #333;
30
30
  }
31
31
 
32
32
  .app {
@@ -45,25 +45,8 @@
45
45
  color: var(--primary-color);
46
46
  }
47
47
 
48
- .rendering-info {
49
- display: flex;
50
- gap: 10px;
51
- justify-content: center;
52
- margin-top: 10px;
53
- }
54
-
55
- .badge {
56
- display: inline-block;
57
- padding: 4px 8px;
58
- border-radius: 4px;
59
- background-color: #eaeaea;
48
+ header p {
60
49
  color: #666;
61
- font-size: 0.8rem;
62
- }
63
-
64
- .badge.active {
65
- background-color: var(--success-color);
66
- color: white;
67
50
  }
68
51
 
69
52
  .card {
@@ -75,23 +58,11 @@
75
58
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.05);
76
59
  }
77
60
 
78
- .result {
79
- background-color: #f0f7ff;
61
+ pre {
62
+ background-color: #f5f5f5;
80
63
  padding: 1rem;
81
64
  border-radius: 4px;
82
- margin-top: 1rem;
83
- white-space: pre-wrap;
84
65
  overflow-x: auto;
85
- font-family: monospace;
86
- font-size: 0.9rem;
87
- }
88
-
89
- .error {
90
- background-color: #ffebee;
91
- color: #c62828;
92
- padding: 0.75rem;
93
- border-radius: 4px;
94
- margin-top: 0.5rem;
95
66
  }
96
67
 
97
68
  footer {
@@ -102,31 +73,56 @@
102
73
  border-top: 1px solid var(--border-color);
103
74
  }
104
75
 
105
- footer a {
106
- color: var(--primary-color);
107
- text-decoration: none;
76
+ .warning {
77
+ display: none;
78
+ background-color: #fff3cd;
79
+ border: 1px solid #ffecb5;
80
+ color: #856404;
81
+ padding: 1rem;
82
+ border-radius: 4px;
83
+ margin-bottom: 1rem;
108
84
  }
109
85
 
110
- @media (max-width: 768px) {
111
- .app {
112
- padding: 10px;
113
- }
114
-
115
- .card {
116
- padding: 1rem;
117
- }
86
+ code {
87
+ background-color: #f5f5f5;
88
+ padding: 0.2rem 0.4rem;
89
+ border-radius: 3px;
90
+ }
91
+
92
+ .loading {
93
+ text-align: center;
94
+ padding: 3rem 1rem;
95
+ color: #666;
118
96
  }
119
97
  </style>
120
- <!-- WASM runtime will be loaded by server -->
121
- <script src="/wasm/wasm_exec.js"></script>
98
+ <script src="/wasm/wasm_exec.js" defer></script>
122
99
  </head>
123
100
  <body>
124
101
  <div id="root">
125
- <!-- Server-rendered content will replace this -->
126
- <div class="loading" style="text-align:center;padding:3rem;">
102
+ <!-- Server-rendered content will be inserted here -->
103
+ <div class="loading">
127
104
  <h2>Loading...</h2>
128
- <p>Please wait while the application initializes.</p>
105
+ <p>Please wait while the server starts.</p>
106
+ <p>If this message persists, there might be an issue with the server.</p>
129
107
  </div>
130
108
  </div>
109
+ <script type="module" src="/src/client.js"></script>
110
+ <script>
111
+ // The server should replace this entire page with server-rendered content
112
+ // If you're seeing this, something is wrong with the server-side rendering
113
+ setTimeout(() => {
114
+ if (document.querySelector('.loading')) {
115
+ document.querySelector('#root').innerHTML = `
116
+ <div class="warning" style="display:block; background-color: #fff3cd; border: 1px solid #ffecb5; color: #856404; padding: 1rem; border-radius: 4px; margin-bottom: 1rem;">
117
+ <h2>Server Not Responding</h2>
118
+ <p>The server is not responding with the expected server-rendered content.</p>
119
+ <p>Please make sure the server is running properly with:</p>
120
+ <code>npm run dev</code>
121
+ <p>This static HTML file should be replaced by server-rendered content.</p>
122
+ </div>
123
+ `;
124
+ }
125
+ }, 2000);
126
+ </script>
131
127
  </body>
132
128
  </html>