frontend-hamroun 1.2.79 → 1.2.82

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 (259) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +129 -1513
  3. package/bin/cli.js +506 -145
  4. package/dist/index.cjs +2 -0
  5. package/dist/index.cjs.map +1 -0
  6. package/dist/index.client.cjs +2 -0
  7. package/dist/index.client.cjs.map +1 -0
  8. package/dist/index.client.js +26 -0
  9. package/dist/index.client.js.map +1 -0
  10. package/dist/index.js +299 -1
  11. package/dist/index.js.map +1 -0
  12. package/dist/jsx-runtime.cjs +2 -0
  13. package/dist/jsx-runtime.cjs.map +1 -0
  14. package/dist/jsx-runtime.js +93 -1
  15. package/dist/jsx-runtime.js.map +1 -0
  16. package/dist/renderer-Bo9zkUZ_.js +52 -0
  17. package/dist/renderer-Bo9zkUZ_.js.map +1 -0
  18. package/dist/renderer-Din1y3YM.cjs +2 -0
  19. package/dist/renderer-Din1y3YM.cjs.map +1 -0
  20. package/dist/server-renderer-CqIpQ-od.cjs +2 -0
  21. package/dist/server-renderer-CqIpQ-od.cjs.map +1 -0
  22. package/dist/server-renderer-QHt45Ip2.js +255 -0
  23. package/dist/server-renderer-QHt45Ip2.js.map +1 -0
  24. package/dist/server-renderer.cjs +2 -0
  25. package/dist/server-renderer.cjs.map +1 -0
  26. package/dist/server-renderer.js +5 -1
  27. package/dist/server-renderer.js.map +1 -0
  28. package/package.json +77 -120
  29. package/templates/basic-app/build.js +22 -0
  30. package/templates/basic-app/dev.js +27 -0
  31. package/templates/basic-app/esbuild.config.js +28 -0
  32. package/templates/basic-app/index.html +1 -1
  33. package/templates/basic-app/package.json +29 -28
  34. package/templates/basic-app/server.js +24 -0
  35. package/templates/basic-app/src/App.jsx +16 -0
  36. package/templates/basic-app/src/App.tsx +26 -0
  37. package/templates/basic-app/src/client.jsx +5 -0
  38. package/templates/basic-app/src/client.tsx +11 -0
  39. package/templates/basic-app/src/components/Counter.jsx +13 -0
  40. package/templates/basic-app/src/components/Counter.tsx +18 -0
  41. package/templates/basic-app/src/jsx-shim.js +3 -0
  42. package/templates/basic-app/src/jsx-shim.ts +11 -0
  43. package/templates/basic-app/src/main.jsx +98 -0
  44. package/templates/basic-app/src/main.tsx +0 -1
  45. package/templates/basic-app/src/server.js +47 -0
  46. package/templates/basic-app/src/server.ts +52 -0
  47. package/templates/basic-app/tsconfig.server.json +11 -0
  48. package/templates/complete-app/lib/frontend-hamroun.js +182 -0
  49. package/templates/complete-app/package.json +2 -1
  50. package/templates/complete-app/pages/about.jsx +0 -0
  51. package/templates/complete-app/pages/index.jsx +0 -0
  52. package/templates/complete-app/pages/wasm-demo.jsx +0 -0
  53. package/templates/complete-app/public/client.js +58 -49
  54. package/templates/complete-app/public/index.html +88 -17
  55. package/templates/complete-app/public/styles.css +30 -533
  56. package/templates/complete-app/server.js +31 -222
  57. package/templates/complete-app/wasm/build.bat +0 -0
  58. package/templates/complete-app/wasm/build.sh +0 -0
  59. package/templates/complete-app/wasm/example.go +0 -0
  60. package/templates/fullstack-app/build/main.js +130 -101
  61. package/templates/fullstack-app/build/main.js.map +4 -4
  62. package/templates/fullstack-app/package-lock.json +1773 -566
  63. package/templates/ssr-template/esbuild.config.js +33 -0
  64. package/templates/ssr-template/jsx-shim.js +1 -0
  65. package/templates/ssr-template/package.json +22 -16
  66. package/templates/ssr-template/src/App.tsx +12 -52
  67. package/templates/ssr-template/src/client.tsx +3 -17
  68. package/templates/ssr-template/src/server.ts +21 -204
  69. package/templates/ssr-template/tsconfig.json +10 -13
  70. package/templates/ssr-template/tsconfig.server.json +6 -14
  71. package/templates/wasm/build-wasm.js +228 -0
  72. package/templates/wasm/esbuild.config.js +63 -0
  73. package/templates/wasm/go/main.go +256 -0
  74. package/templates/wasm/go/wasm_exec.js +0 -0
  75. package/templates/wasm/index.html +97 -0
  76. package/templates/wasm/jsx-shim.js +9 -0
  77. package/templates/{go-wasm-app → wasm}/package-lock.json +5307 -3732
  78. package/templates/wasm/package.json +42 -0
  79. package/templates/wasm/public/example.wasm +0 -0
  80. package/templates/wasm/src/App.tsx +564 -0
  81. package/templates/wasm/src/client.tsx +220 -0
  82. package/templates/wasm/src/index.tsx +21 -0
  83. package/templates/wasm/src/server.ts +145 -0
  84. package/templates/wasm/tsconfig.json +21 -0
  85. package/templates/wasm/tsconfig.node.json +13 -0
  86. package/templates/wasm/tsconfig.server.json +23 -0
  87. package/templates/wasm/vite.config.ts +56 -0
  88. package/templates/wasm/wasm-loader.js +103 -0
  89. package/dist/batch/package.json +0 -16
  90. package/dist/client-router/package.json +0 -16
  91. package/dist/component/package.json +0 -16
  92. package/dist/context/package.json +0 -16
  93. package/dist/event-bus/package.json +0 -16
  94. package/dist/forms/package.json +0 -16
  95. package/dist/hooks/package.json +0 -16
  96. package/dist/hooks-0728361a.cjs +0 -1
  97. package/dist/hooks-b58f947c.js +0 -133
  98. package/dist/hooks.js +0 -1
  99. package/dist/hooks.mjs +0 -13
  100. package/dist/index.mjs +0 -137
  101. package/dist/jsx-runtime/package.json +0 -16
  102. package/dist/jsx-runtime.mjs +0 -64
  103. package/dist/lifecycle-events/package.json +0 -16
  104. package/dist/package.json +0 -71
  105. package/dist/render-component/package.json +0 -16
  106. package/dist/renderer/package.json +0 -16
  107. package/dist/renderer.js +0 -1
  108. package/dist/renderer.mjs +0 -27
  109. package/dist/router/package.json +0 -16
  110. package/dist/server/package.json +0 -17
  111. package/dist/server/src/batch.d.ts +0 -3
  112. package/dist/server/src/batch.js +0 -23
  113. package/dist/server/src/batch.js.map +0 -1
  114. package/dist/server/src/client-router.d.ts +0 -60
  115. package/dist/server/src/client-router.js +0 -210
  116. package/dist/server/src/client-router.js.map +0 -1
  117. package/dist/server/src/component.d.ts +0 -14
  118. package/dist/server/src/component.js +0 -106
  119. package/dist/server/src/component.js.map +0 -1
  120. package/dist/server/src/context.d.ts +0 -13
  121. package/dist/server/src/context.js +0 -21
  122. package/dist/server/src/context.js.map +0 -1
  123. package/dist/server/src/event-bus.d.ts +0 -23
  124. package/dist/server/src/event-bus.js +0 -75
  125. package/dist/server/src/event-bus.js.map +0 -1
  126. package/dist/server/src/forms.d.ts +0 -40
  127. package/dist/server/src/forms.js +0 -148
  128. package/dist/server/src/forms.js.map +0 -1
  129. package/dist/server/src/hooks.d.ts +0 -12
  130. package/dist/server/src/hooks.js +0 -170
  131. package/dist/server/src/hooks.js.map +0 -1
  132. package/dist/server/src/index.client.d.ts +0 -12
  133. package/dist/server/src/index.client.js +0 -14
  134. package/dist/server/src/index.client.js.map +0 -1
  135. package/dist/server/src/index.d.ts +0 -88
  136. package/dist/server/src/index.js +0 -79
  137. package/dist/server/src/index.js.map +0 -1
  138. package/dist/server/src/jsx-runtime/jsx-dev-runtime.d.ts +0 -1
  139. package/dist/server/src/jsx-runtime/jsx-dev-runtime.js +0 -2
  140. package/dist/server/src/jsx-runtime/jsx-dev-runtime.js.map +0 -1
  141. package/dist/server/src/jsx-runtime/jsx-runtime.d.ts +0 -4
  142. package/dist/server/src/jsx-runtime/jsx-runtime.js +0 -41
  143. package/dist/server/src/jsx-runtime/jsx-runtime.js.map +0 -1
  144. package/dist/server/src/jsx-runtime.d.ts +0 -20
  145. package/dist/server/src/jsx-runtime.js +0 -105
  146. package/dist/server/src/jsx-runtime.js.map +0 -1
  147. package/dist/server/src/lifecycle-events.d.ts +0 -108
  148. package/dist/server/src/lifecycle-events.js +0 -177
  149. package/dist/server/src/lifecycle-events.js.map +0 -1
  150. package/dist/server/src/renderComponent.d.ts +0 -13
  151. package/dist/server/src/renderComponent.js +0 -30
  152. package/dist/server/src/renderComponent.js.map +0 -1
  153. package/dist/server/src/renderer.d.ts +0 -2
  154. package/dist/server/src/renderer.js +0 -31
  155. package/dist/server/src/renderer.js.map +0 -1
  156. package/dist/server/src/router.d.ts +0 -55
  157. package/dist/server/src/router.js +0 -166
  158. package/dist/server/src/router.js.map +0 -1
  159. package/dist/server/src/server/api-router.d.ts +0 -15
  160. package/dist/server/src/server/api-router.js +0 -111
  161. package/dist/server/src/server/api-router.js.map +0 -1
  162. package/dist/server/src/server/auth.d.ts +0 -32
  163. package/dist/server/src/server/auth.js +0 -80
  164. package/dist/server/src/server/auth.js.map +0 -1
  165. package/dist/server/src/server/database.d.ts +0 -24
  166. package/dist/server/src/server/database.js +0 -135
  167. package/dist/server/src/server/database.js.map +0 -1
  168. package/dist/server/src/server/index.d.ts +0 -116
  169. package/dist/server/src/server/index.js +0 -508
  170. package/dist/server/src/server/index.js.map +0 -1
  171. package/dist/server/src/server/middleware.d.ts +0 -11
  172. package/dist/server/src/server/middleware.js +0 -46
  173. package/dist/server/src/server/middleware.js.map +0 -1
  174. package/dist/server/src/server/server.d.ts +0 -9
  175. package/dist/server/src/server/server.js +0 -87
  176. package/dist/server/src/server/server.js.map +0 -1
  177. package/dist/server/src/server/templates.d.ts +0 -30
  178. package/dist/server/src/server/templates.js +0 -208
  179. package/dist/server/src/server/templates.js.map +0 -1
  180. package/dist/server/src/server/types.d.ts +0 -38
  181. package/dist/server/src/server/types.js +0 -4
  182. package/dist/server/src/server/types.js.map +0 -1
  183. package/dist/server/src/server/utils.d.ts +0 -70
  184. package/dist/server/src/server/utils.js +0 -156
  185. package/dist/server/src/server/utils.js.map +0 -1
  186. package/dist/server/src/server/wasm.d.ts +0 -9
  187. package/dist/server/src/server/wasm.js +0 -117
  188. package/dist/server/src/server/wasm.js.map +0 -1
  189. package/dist/server/src/server-renderer.d.ts +0 -5
  190. package/dist/server/src/server-renderer.js +0 -106
  191. package/dist/server/src/server-renderer.js.map +0 -1
  192. package/dist/server/src/server-types.d.ts +0 -42
  193. package/dist/server/src/server-types.js +0 -6
  194. package/dist/server/src/server-types.js.map +0 -1
  195. package/dist/server/src/store.d.ts +0 -41
  196. package/dist/server/src/store.js +0 -99
  197. package/dist/server/src/store.js.map +0 -1
  198. package/dist/server/src/types.d.ts +0 -19
  199. package/dist/server/src/types.js +0 -2
  200. package/dist/server/src/types.js.map +0 -1
  201. package/dist/server/src/utils.d.ts +0 -46
  202. package/dist/server/src/utils.js +0 -144
  203. package/dist/server/src/utils.js.map +0 -1
  204. package/dist/server/src/vdom.d.ts +0 -8
  205. package/dist/server/src/vdom.js +0 -22
  206. package/dist/server/src/vdom.js.map +0 -1
  207. package/dist/server/src/wasm.d.ts +0 -36
  208. package/dist/server/src/wasm.js +0 -159
  209. package/dist/server/src/wasm.js.map +0 -1
  210. package/dist/server/tsconfig.server.tsbuildinfo +0 -1
  211. package/dist/server-renderer/package.json +0 -16
  212. package/dist/server-renderer.mjs +0 -64
  213. package/dist/store/package.json +0 -16
  214. package/dist/types/package.json +0 -16
  215. package/dist/utils/package.json +0 -16
  216. package/dist/vdom/package.json +0 -16
  217. package/dist/wasm/package.json +0 -16
  218. package/dist/wasm.js +0 -1
  219. package/dist/wasm.mjs +0 -103
  220. package/templates/basic-app/docs/rapport_pfe.aux +0 -27
  221. package/templates/basic-app/docs/rapport_pfe.log +0 -399
  222. package/templates/basic-app/docs/rapport_pfe.out +0 -10
  223. package/templates/basic-app/docs/rapport_pfe.pdf +0 -0
  224. package/templates/basic-app/docs/rapport_pfe.tex +0 -68
  225. package/templates/basic-app/docs/rapport_pfe.toc +0 -14
  226. package/templates/complete-app/package-lock.json +0 -2536
  227. package/templates/go-wasm-app/README.md +0 -38
  228. package/templates/go-wasm-app/babel.config.js +0 -21
  229. package/templates/go-wasm-app/build-client.js +0 -49
  230. package/templates/go-wasm-app/build-wasm.js +0 -237
  231. package/templates/go-wasm-app/build.config.js +0 -62
  232. package/templates/go-wasm-app/build.js +0 -218
  233. package/templates/go-wasm-app/package.json +0 -32
  234. package/templates/go-wasm-app/public/index.html +0 -128
  235. package/templates/go-wasm-app/public/styles.css +0 -197
  236. package/templates/go-wasm-app/public/wasm/example.wasm +0 -0
  237. package/templates/go-wasm-app/public/wasm/wasm_exec_node.js +0 -39
  238. package/templates/go-wasm-app/server.js +0 -70
  239. package/templates/go-wasm-app/src/App.jsx +0 -38
  240. package/templates/go-wasm-app/src/app.js +0 -173
  241. package/templates/go-wasm-app/src/client.js +0 -57
  242. package/templates/go-wasm-app/src/components/Footer.jsx +0 -13
  243. package/templates/go-wasm-app/src/components/Header.jsx +0 -19
  244. package/templates/go-wasm-app/src/components/WasmDemo.jsx +0 -120
  245. package/templates/go-wasm-app/src/main.jsx +0 -12
  246. package/templates/go-wasm-app/src/wasm/example.go +0 -75
  247. package/templates/go-wasm-app/tsconfig.server.json +0 -18
  248. package/templates/go-wasm-app/vite.config.js +0 -45
  249. package/templates/ssr-template/client.js +0 -58
  250. package/templates/ssr-template/package-lock.json +0 -2478
  251. package/templates/ssr-template/public/index.html +0 -47
  252. package/templates/ssr-template/readme.md +0 -188
  253. package/templates/ssr-template/server.js +0 -369
  254. package/templates/ssr-template/server.ts +0 -275
  255. package/templates/ssr-template/src/client.ts +0 -61
  256. package/templates/ssr-template/src/pages/index.tsx +0 -51
  257. package/templates/ssr-template/vite.config.js +0 -57
  258. /package/{dist/Counter.d.ts → templates/complete-app/api/hello.js} +0 -0
  259. /package/templates/{go-wasm-app/public/wasm → wasm/public}/wasm_exec.js +0 -0
@@ -0,0 +1,228 @@
1
+ import { spawn } from 'child_process';
2
+ import { join, dirname } from 'path';
3
+ import { fileURLToPath } from 'url';
4
+ import fs from 'fs';
5
+
6
+ const __filename = fileURLToPath(import.meta.url);
7
+ const __dirname = dirname(__filename);
8
+
9
+ const goDir = join(__dirname, 'go');
10
+ const outputDir = join(__dirname, 'public');
11
+ const wasmFile = join(outputDir, 'example.wasm');
12
+
13
+ // Prevent infinite loops by checking if we're already running
14
+ const lockFile = join(__dirname, '.build-lock');
15
+ if (fs.existsSync(lockFile)) {
16
+ console.log('Build already in progress, skipping...');
17
+ process.exit(0);
18
+ }
19
+
20
+ // Create lock file
21
+ fs.writeFileSync(lockFile, process.pid.toString());
22
+
23
+ // Clean up lock file on exit
24
+ process.on('exit', () => {
25
+ try {
26
+ fs.unlinkSync(lockFile);
27
+ } catch (e) {
28
+ // Ignore cleanup errors
29
+ }
30
+ });
31
+
32
+ process.on('SIGINT', () => {
33
+ try {
34
+ fs.unlinkSync(lockFile);
35
+ } catch (e) {
36
+ // Ignore cleanup errors
37
+ }
38
+ process.exit(0);
39
+ });
40
+
41
+ // Ensure public directory exists
42
+ if (!fs.existsSync(outputDir)) {
43
+ fs.mkdirSync(outputDir, { recursive: true });
44
+ }
45
+
46
+ // Only create Go files if they don't exist (prevent infinite generation)
47
+ if (!fs.existsSync(goDir) || !fs.existsSync(join(goDir, 'main.go'))) {
48
+ console.log('Creating Go WASM example files...');
49
+ fs.mkdirSync(goDir, { recursive: true });
50
+
51
+ // Create the corrected Go main file with proper function names
52
+ const goMainContent = `package main
53
+
54
+ import (
55
+ "fmt"
56
+ "strings"
57
+ "syscall/js"
58
+ )
59
+
60
+ func goHello(this js.Value, inputs []js.Value) interface{} {
61
+ name := inputs[0].String()
62
+ return fmt.Sprintf("Hello, %s from Go WASM!", name)
63
+ }
64
+
65
+ func goAdd(this js.Value, inputs []js.Value) interface{} {
66
+ a := inputs[0].Int()
67
+ b := inputs[1].Int()
68
+ return a + b
69
+ }
70
+
71
+ func goMultiply(this js.Value, inputs []js.Value) interface{} {
72
+ a := inputs[0].Float()
73
+ b := inputs[1].Float()
74
+ return a * b
75
+ }
76
+
77
+ func goFibonacci(this js.Value, inputs []js.Value) interface{} {
78
+ n := inputs[0].Int()
79
+ if n <= 1 {
80
+ return n
81
+ }
82
+
83
+ a, b := 0, 1
84
+ for i := 2; i <= n; i++ {
85
+ a, b = b, a+b
86
+ }
87
+ return b
88
+ }
89
+
90
+ func goIsPrime(this js.Value, inputs []js.Value) interface{} {
91
+ n := inputs[0].Int()
92
+ if n < 2 {
93
+ return false
94
+ }
95
+ if n == 2 {
96
+ return true
97
+ }
98
+ if n%2 == 0 {
99
+ return false
100
+ }
101
+
102
+ for i := 3; i*i <= n; i += 2 {
103
+ if n%i == 0 {
104
+ return false
105
+ }
106
+ }
107
+ return true
108
+ }
109
+
110
+ func main() {
111
+ fmt.Println("Go WASM initialized")
112
+
113
+ // Register functions with correct names that match the frontend
114
+ js.Global().Set("goHello", js.FuncOf(goHello))
115
+ js.Global().Set("goAdd", js.FuncOf(goAdd))
116
+ js.Global().Set("goMultiply", js.FuncOf(goMultiply))
117
+ js.Global().Set("goFibonacci", js.FuncOf(goFibonacci))
118
+ js.Global().Set("goIsPrime", js.FuncOf(goIsPrime))
119
+
120
+ fmt.Println("Go functions registered and ready!")
121
+
122
+ // Keep the program running
123
+ select {}
124
+ }
125
+ `;
126
+
127
+ fs.writeFileSync(join(goDir, 'main.go'), goMainContent);
128
+
129
+ // Create go.mod file
130
+ const goModContent = `module wasm-example
131
+
132
+ go 1.21
133
+ `;
134
+
135
+ fs.writeFileSync(join(goDir, 'go.mod'), goModContent);
136
+
137
+ console.log('✅ Go example files created');
138
+ } else {
139
+ console.log('Go files already exist, skipping creation');
140
+ }
141
+
142
+ console.log('Building Go WASM module...');
143
+
144
+ // Set environment variables for WASM compilation
145
+ const env = {
146
+ ...process.env,
147
+ GOOS: 'js',
148
+ GOARCH: 'wasm'
149
+ };
150
+
151
+ // Build command
152
+ const buildArgs = ['build', '-o', wasmFile, 'main.go'];
153
+
154
+ console.log(`Running: go ${buildArgs.join(' ')}`);
155
+ console.log(`Working directory: ${goDir}`);
156
+ console.log(`Output: ${wasmFile}`);
157
+
158
+ const goProcess = spawn('go', buildArgs, {
159
+ cwd: goDir,
160
+ env: env,
161
+ stdio: 'inherit',
162
+ shell: true
163
+ });
164
+
165
+ goProcess.on('close', (code) => {
166
+ // Clean up lock file
167
+ try {
168
+ fs.unlinkSync(lockFile);
169
+ } catch (e) {
170
+ // Ignore cleanup errors
171
+ }
172
+
173
+ if (code === 0) {
174
+ console.log('✅ Go WASM build successful!');
175
+ console.log(`📦 WASM file created: ${wasmFile}`);
176
+
177
+ // Check if wasm_exec.js exists, if not, copy it
178
+ const wasmExecJs = join(outputDir, 'wasm_exec.js');
179
+ if (!fs.existsSync(wasmExecJs)) {
180
+ console.log('📋 Copying wasm_exec.js...');
181
+
182
+ // Try to find wasm_exec.js in GOROOT
183
+ const findWasmExec = spawn('go', ['env', 'GOROOT'], {
184
+ stdio: 'pipe',
185
+ shell: true
186
+ });
187
+
188
+ let goroot = '';
189
+ findWasmExec.stdout.on('data', (data) => {
190
+ goroot += data.toString().trim();
191
+ });
192
+
193
+ findWasmExec.on('close', () => {
194
+ if (goroot) {
195
+ const wasmExecSource = join(goroot, 'misc', 'wasm', 'wasm_exec.js');
196
+ if (fs.existsSync(wasmExecSource)) {
197
+ fs.copyFileSync(wasmExecSource, wasmExecJs);
198
+ console.log('✅ wasm_exec.js copied successfully');
199
+ } else {
200
+ console.log('⚠️ wasm_exec.js not found, you may need to copy it manually');
201
+ console.log(`Expected location: ${wasmExecSource}`);
202
+ }
203
+ }
204
+ });
205
+ }
206
+ } else {
207
+ console.error('❌ Go WASM build failed with exit code:', code);
208
+ console.log('\n💡 Troubleshooting tips:');
209
+ console.log('1. Make sure Go is installed and in your PATH');
210
+ console.log('2. Check that your Go code in ./go/main.go is valid');
211
+ console.log('3. Ensure you have Go 1.11+ for WASM support');
212
+ process.exit(1);
213
+ }
214
+ });
215
+
216
+ goProcess.on('error', (error) => {
217
+ // Clean up lock file
218
+ try {
219
+ fs.unlinkSync(lockFile);
220
+ } catch (e) {
221
+ // Ignore cleanup errors
222
+ }
223
+
224
+ console.error('❌ Failed to start Go build process:', error.message);
225
+ console.log('\n💡 Make sure Go is installed and available in your PATH');
226
+ console.log('Download Go from: https://golang.org/dl/');
227
+ process.exit(1);
228
+ });
@@ -0,0 +1,63 @@
1
+ import esbuild from 'esbuild';
2
+ import { fileURLToPath } from 'url';
3
+ import { dirname, join } from 'path';
4
+
5
+ const __filename = fileURLToPath(import.meta.url);
6
+ const __dirname = dirname(__filename);
7
+
8
+ // Build client
9
+ await esbuild.build({
10
+ entryPoints: ['src/client.tsx'],
11
+ bundle: true,
12
+ outfile: 'dist/client.js',
13
+ platform: 'browser',
14
+ format: 'esm',
15
+ minify: false,
16
+ jsx: 'transform',
17
+ jsxFactory: 'jsx',
18
+ jsxFragment: 'Fragment',
19
+ inject: ['./jsx-shim.js'],
20
+ });
21
+
22
+ // Build server
23
+ await esbuild.build({
24
+ entryPoints: ['src/server.ts'],
25
+ bundle: true,
26
+ outfile: 'dist/server.js',
27
+ platform: 'node',
28
+ format: 'esm',
29
+ external: ['frontend-hamroun'],
30
+ packages: 'external',
31
+ minify: false,
32
+ jsx: 'transform',
33
+ jsxFactory: 'jsx',
34
+ jsxFragment: 'Fragment',
35
+ inject: ['./jsx-shim.js'],
36
+ });
37
+
38
+ const config = {
39
+ entryPoints: ['src/index.js'],
40
+ bundle: true,
41
+ outfile: 'dist/bundle.js',
42
+ format: 'esm',
43
+ target: 'es2020',
44
+ minify: process.env.NODE_ENV === 'production',
45
+ sourcemap: process.env.NODE_ENV !== 'production',
46
+ platform: 'browser',
47
+ loader: {
48
+ '.wasm': 'file'
49
+ },
50
+ external: [],
51
+ define: {
52
+ 'process.env.NODE_ENV': JSON.stringify(process.env.NODE_ENV || 'development')
53
+ }
54
+ };
55
+
56
+ if (process.argv.includes('--watch')) {
57
+ const ctx = await esbuild.context(config);
58
+ await ctx.watch();
59
+ console.log('Watching for changes...');
60
+ } else {
61
+ await esbuild.build(config);
62
+ console.log('Build complete!');
63
+ }
@@ -0,0 +1,256 @@
1
+ package main
2
+
3
+ import (
4
+ "fmt"
5
+ "strings"
6
+ "syscall/js"
7
+ )
8
+
9
+ // Global variable to hold JS values for complex data exchange
10
+ var jsGlobal = js.Global()
11
+
12
+ // Hello function - greeting with name
13
+ func goHello(this js.Value, args []js.Value) interface{} {
14
+ if len(args) != 1 {
15
+ return js.ValueOf("Error: goHello requires exactly 1 argument")
16
+ }
17
+
18
+ name := args[0].String()
19
+ result := fmt.Sprintf("Hello, %s from Go WASM!", name)
20
+
21
+ fmt.Printf("Go WASM: goHello('%s') = '%s'\n", name, result)
22
+ return js.ValueOf(result)
23
+ }
24
+
25
+ // Add function - simple arithmetic
26
+ func goAdd(this js.Value, args []js.Value) interface{} {
27
+ if len(args) != 2 {
28
+ return js.ValueOf("Error: goAdd requires exactly 2 arguments")
29
+ }
30
+
31
+ a := args[0].Float()
32
+ b := args[1].Float()
33
+ result := a + b
34
+
35
+ fmt.Printf("Go WASM: goAdd(%f, %f) = %f\n", a, b, result)
36
+ return js.ValueOf(result)
37
+ }
38
+
39
+ // Multiply function - simple arithmetic
40
+ func goMultiply(this js.Value, args []js.Value) interface{} {
41
+ if len(args) != 2 {
42
+ return js.ValueOf("Error: goMultiply requires exactly 2 arguments")
43
+ }
44
+
45
+ a := args[0].Float()
46
+ b := args[1].Float()
47
+ result := a * b
48
+
49
+ fmt.Printf("Go WASM: goMultiply(%f, %f) = %f\n", a, b, result)
50
+ return js.ValueOf(result)
51
+ }
52
+
53
+ // Fibonacci function - recursive computation
54
+ func goFibonacci(this js.Value, args []js.Value) interface{} {
55
+ if len(args) != 1 {
56
+ return js.ValueOf("Error: goFibonacci requires exactly 1 argument")
57
+ }
58
+
59
+ n := int(args[0].Float())
60
+ if n < 0 {
61
+ return js.ValueOf("Error: goFibonacci requires non-negative number")
62
+ }
63
+
64
+ result := fibonacciCalc(n)
65
+ fmt.Printf("Go WASM: goFibonacci(%d) = %d\n", n, result)
66
+ return js.ValueOf(result)
67
+ }
68
+
69
+ // Prime check function
70
+ func goIsPrime(this js.Value, args []js.Value) interface{} {
71
+ if len(args) != 1 {
72
+ return js.ValueOf("Error: goIsPrime requires exactly 1 argument")
73
+ }
74
+
75
+ n := int(args[0].Float())
76
+ if n < 2 {
77
+ return js.ValueOf(false)
78
+ }
79
+ if n == 2 {
80
+ return js.ValueOf(true)
81
+ }
82
+ if n%2 == 0 {
83
+ return js.ValueOf(false)
84
+ }
85
+
86
+ for i := 3; i*i <= n; i += 2 {
87
+ if n%i == 0 {
88
+ return js.ValueOf(false)
89
+ }
90
+ }
91
+
92
+ fmt.Printf("Go WASM: goIsPrime(%d) = %t\n", n, true)
93
+ return js.ValueOf(true)
94
+ }
95
+
96
+ // Helper function for fibonacci calculation
97
+ func fibonacciCalc(n int) int {
98
+ if n <= 1 {
99
+ return n
100
+ }
101
+
102
+ a, b := 0, 1
103
+ for i := 2; i <= n; i++ {
104
+ a, b = b, a+b
105
+ }
106
+ return b
107
+ }
108
+
109
+ // Process array function - demonstrates array handling
110
+ func goProcessArray(this js.Value, args []js.Value) interface{} {
111
+ if len(args) != 1 {
112
+ return js.ValueOf("Error: goProcessArray requires exactly 1 argument")
113
+ }
114
+
115
+ jsArray := args[0]
116
+ if jsArray.Type() != js.TypeObject {
117
+ return js.ValueOf("Error: argument must be an array")
118
+ }
119
+
120
+ length := jsArray.Get("length").Int()
121
+ goSlice := make([]int, length)
122
+
123
+ // Convert JS array to Go slice
124
+ for i := 0; i < length; i++ {
125
+ goSlice[i] = int(jsArray.Index(i).Float())
126
+ }
127
+
128
+ // Process the slice (double each element and add index)
129
+ processedSlice := make([]interface{}, length)
130
+ for i, val := range goSlice {
131
+ processedSlice[i] = (val * 2) + i
132
+ }
133
+
134
+ fmt.Printf("Go WASM: goProcessArray([%s]) = [", strings.Trim(fmt.Sprint(goSlice), "[]"))
135
+ for i, val := range processedSlice {
136
+ if i > 0 {
137
+ fmt.Printf(" ")
138
+ }
139
+ fmt.Printf("%v", val)
140
+ }
141
+ fmt.Printf("]\n")
142
+
143
+ // Convert back to JS array
144
+ result := jsGlobal.Get("Array").New(length)
145
+ for i, val := range processedSlice {
146
+ result.SetIndex(i, val)
147
+ }
148
+
149
+ return result
150
+ }
151
+
152
+ // Calculate PI using series approximation
153
+ func goCalculatePI(this js.Value, args []js.Value) interface{} {
154
+ if len(args) != 1 {
155
+ return js.ValueOf("Error: goCalculatePI requires exactly 1 argument")
156
+ }
157
+
158
+ iterations := int(args[0].Float())
159
+ pi := 0.0
160
+
161
+ for i := 0; i < iterations; i++ {
162
+ term := 1.0 / float64(2*i+1)
163
+ if i%2 == 1 {
164
+ term = -term
165
+ }
166
+ pi += term
167
+ }
168
+
169
+ result := pi * 4
170
+ fmt.Printf("Go WASM: goCalculatePI(%d iterations) = %f\n", iterations, result)
171
+ return js.ValueOf(result)
172
+ }
173
+
174
+ // Performance benchmark function
175
+ func goPerformanceBenchmark(this js.Value, args []js.Value) interface{} {
176
+ if len(args) != 1 {
177
+ return js.ValueOf("Error: goPerformanceBenchmark requires exactly 1 argument")
178
+ }
179
+
180
+ iterations := int(args[0].Float())
181
+
182
+ // Simple computational benchmark
183
+ sum := 0
184
+ for i := 0; i < iterations; i++ {
185
+ sum += i * i
186
+ }
187
+
188
+ // Convert Go map to JS object
189
+ jsResult := jsGlobal.Get("Object").New()
190
+ jsResult.Set("iterations", js.ValueOf(iterations))
191
+ jsResult.Set("result", js.ValueOf(sum))
192
+ jsResult.Set("message", js.ValueOf(fmt.Sprintf("Completed %d iterations in Go WASM", iterations)))
193
+
194
+ fmt.Printf("Go WASM: goPerformanceBenchmark(%d) = %d\n", iterations, sum)
195
+ return jsResult
196
+ }
197
+
198
+ // String utilities function
199
+ func goStringUtils(this js.Value, args []js.Value) interface{} {
200
+ if len(args) != 1 {
201
+ return js.ValueOf("Error: goStringUtils requires exactly 1 argument")
202
+ }
203
+
204
+ input := args[0].String()
205
+
206
+ // Create result object with various string operations
207
+ result := jsGlobal.Get("Object").New()
208
+ result.Set("original", js.ValueOf(input))
209
+ result.Set("uppercase", js.ValueOf(strings.ToUpper(input)))
210
+ result.Set("lowercase", js.ValueOf(strings.ToLower(input)))
211
+ result.Set("reversed", js.ValueOf(reverseString(input)))
212
+ result.Set("length", js.ValueOf(len(input)))
213
+ result.Set("wordCount", js.ValueOf(len(strings.Fields(input))))
214
+
215
+ fmt.Printf("Go WASM: goStringUtils('%s') completed\n", input)
216
+ return result
217
+ }
218
+
219
+ // Helper function to reverse a string
220
+ func reverseString(s string) string {
221
+ runes := []rune(s)
222
+ for i, j := 0, len(runes)-1; i < j; i, j = i+1, j-1 {
223
+ runes[i], runes[j] = runes[j], runes[i]
224
+ }
225
+ return string(runes)
226
+ }
227
+
228
+ // Initialize and register functions
229
+ func main() {
230
+ fmt.Println("🚀 Go WASM module initializing...")
231
+
232
+ // Register all functions to the global JS scope with "go" prefix
233
+ jsGlobal.Set("goHello", js.FuncOf(goHello))
234
+ jsGlobal.Set("goAdd", js.FuncOf(goAdd))
235
+ jsGlobal.Set("goMultiply", js.FuncOf(goMultiply))
236
+ jsGlobal.Set("goFibonacci", js.FuncOf(goFibonacci))
237
+ jsGlobal.Set("goIsPrime", js.FuncOf(goIsPrime))
238
+ jsGlobal.Set("goProcessArray", js.FuncOf(goProcessArray))
239
+ jsGlobal.Set("goCalculatePI", js.FuncOf(goCalculatePI))
240
+ jsGlobal.Set("goPerformanceBenchmark", js.FuncOf(goPerformanceBenchmark))
241
+ jsGlobal.Set("goStringUtils", js.FuncOf(goStringUtils))
242
+
243
+ fmt.Println("✅ Go WASM functions registered:")
244
+ fmt.Println(" • goHello(name) - Greeting function")
245
+ fmt.Println(" • goAdd(a, b) - Addition")
246
+ fmt.Println(" • goMultiply(a, b) - Multiplication")
247
+ fmt.Println(" • goFibonacci(n) - Fibonacci sequence")
248
+ fmt.Println(" • goIsPrime(n) - Prime number check")
249
+ fmt.Println(" • goProcessArray(arr) - Array processing")
250
+ fmt.Println(" • goCalculatePI(iterations) - PI calculation")
251
+ fmt.Println(" • goPerformanceBenchmark(n) - Performance testing")
252
+ fmt.Println(" • goStringUtils(str) - String utilities")
253
+
254
+ // Keep the program running
255
+ select {}
256
+ }
File without changes
@@ -0,0 +1,97 @@
1
+ <!DOCTYPE html>
2
+ <html lang="en">
3
+ <head>
4
+ <meta charset="UTF-8">
5
+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
6
+ <title>Frontend Hamroun + Go WASM</title>
7
+ <style>
8
+ body {
9
+ margin: 0;
10
+ font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
11
+ }
12
+
13
+ .loading-fallback {
14
+ display: flex;
15
+ justify-content: center;
16
+ align-items: center;
17
+ min-height: 100vh;
18
+ flex-direction: column;
19
+ background: #f7f7f7;
20
+ }
21
+
22
+ .loading-spinner {
23
+ width: 40px;
24
+ height: 40px;
25
+ border: 4px solid #f3f3f3;
26
+ border-top: 4px solid #007acc;
27
+ border-radius: 50%;
28
+ animation: spin 1s linear infinite;
29
+ margin-bottom: 20px;
30
+ }
31
+
32
+ @keyframes spin {
33
+ 0% { transform: rotate(0deg); }
34
+ 100% { transform: rotate(360deg); }
35
+ }
36
+ </style>
37
+ </head>
38
+ <body>
39
+ <div id="app">
40
+ <div class="loading-fallback">
41
+ <div class="loading-spinner"></div>
42
+ <h2>Loading Frontend Hamroun + WASM...</h2>
43
+ <p>Initializing application and WebAssembly runtime...</p>
44
+ </div>
45
+ </div>
46
+
47
+ <!-- Go WASM Runtime -->
48
+ <script src="/wasm_exec.js"></script>
49
+
50
+ <!-- Application -->
51
+ <script type="module">
52
+ import { jsx, render } from 'frontend-hamroun';
53
+ import App from './src/App.tsx';
54
+
55
+ // Wait for WASM runtime to be available
56
+ function waitForGo() {
57
+ return new Promise((resolve) => {
58
+ if (window.Go) {
59
+ resolve();
60
+ } else {
61
+ setTimeout(() => waitForGo().then(resolve), 50);
62
+ }
63
+ });
64
+ }
65
+
66
+ async function startApp() {
67
+ try {
68
+ // Wait for Go WASM runtime
69
+ await waitForGo();
70
+
71
+ // Render the app
72
+ const appElement = jsx(App, {});
73
+ render(appElement, document.getElementById('app'));
74
+ } catch (error) {
75
+ console.error('Failed to start app:', error);
76
+ document.getElementById('app').innerHTML = `
77
+ <div class="loading-fallback">
78
+ <h2 style="color: #dc2626;">Application Error</h2>
79
+ <p>Failed to initialize the application. Check the console for more details.</p>
80
+ <button onclick="window.location.reload()" style="
81
+ background: #007acc;
82
+ color: white;
83
+ border: none;
84
+ padding: 10px 20px;
85
+ border-radius: 5px;
86
+ cursor: pointer;
87
+ margin-top: 10px;
88
+ ">Reload Page</button>
89
+ </div>
90
+ `;
91
+ }
92
+ }
93
+
94
+ startApp();
95
+ </script>
96
+ </body>
97
+ </html>
@@ -0,0 +1,9 @@
1
+ // JSX Runtime shim for Frontend Hamroun
2
+ import { jsx, jsxs, Fragment } from 'frontend-hamroun';
3
+
4
+ // Make JSX runtime available globally
5
+ globalThis.jsx = jsx;
6
+ globalThis.jsxs = jsxs;
7
+ globalThis.Fragment = Fragment;
8
+
9
+ export { jsx, jsxs, Fragment };