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
@@ -1,38 +0,0 @@
1
- # Frontend Hamroun - Go WebAssembly Template with SSR
2
-
3
- This template demonstrates integration between Frontend Hamroun, Go WebAssembly, and Server-Side Rendering for high-performance web applications.
4
-
5
- ## Features
6
-
7
- - 🔄 Go + WebAssembly integration
8
- - 🌐 Server-Side Rendering with client hydration
9
- - ⚡ High-performance computation in both browser and server
10
- - 🚀 Same Go code runs in both environments
11
- - 🔍 SEO-friendly with pre-rendered HTML
12
-
13
- ## Prerequisites
14
-
15
- - [Node.js](https://nodejs.org/) (v14+)
16
- - [Go](https://golang.org/dl/) (v1.16+)
17
-
18
- ## Getting Started
19
-
20
- 1. Install dependencies:
21
- ```
22
- npm install
23
- ```
24
-
25
- 2. Start the development server:
26
- ```
27
- npm run dev
28
- ```
29
-
30
- 3. Open your browser and navigate to `http://localhost:3000`
31
-
32
- The development server includes:
33
- - Automatic WASM compilation from Go source
34
- - Server-side rendering with Express
35
- - Hot reloading of server code with Node's `--watch` flag
36
- - Client-side hydration for interactivity
37
-
38
- ## Project Structure
@@ -1,21 +0,0 @@
1
- const config = {
2
- presets: [
3
- ['@babel/preset-env', {
4
- targets: {
5
- node: 'current'
6
- },
7
- // Enable dynamic imports for both ESM and CommonJS
8
- modules: false
9
- }]
10
- ],
11
- plugins: [
12
- ['@babel/plugin-transform-react-jsx', {
13
- pragma: 'createElement',
14
- pragmaFrag: 'Fragment'
15
- }]
16
- ]
17
- };
18
-
19
- // Support both ESM and CommonJS
20
- export default config;
21
- module.exports = config;
@@ -1,49 +0,0 @@
1
- import fs from 'fs-extra';
2
- import path from 'path';
3
- import { fileURLToPath } from 'url';
4
-
5
- // Get __dirname equivalent in ESM
6
- const __filename = fileURLToPath(import.meta.url);
7
- const __dirname = path.dirname(__filename);
8
-
9
- // Output directory
10
- const outputDir = path.join(__dirname, 'dist');
11
-
12
- // Ensure output directory exists
13
- fs.ensureDirSync(outputDir);
14
-
15
- // Copy necessary files for production
16
- console.log('Copying files for production...');
17
-
18
- // Copy HTML template
19
- fs.copySync(path.join(__dirname, 'public', 'index.html'), path.join(outputDir, 'index.html'));
20
-
21
- // Copy WASM files
22
- const wasmDir = path.join(__dirname, 'public', 'wasm');
23
- const distWasmDir = path.join(outputDir, 'wasm');
24
- fs.ensureDirSync(distWasmDir);
25
-
26
- if (fs.existsSync(wasmDir)) {
27
- fs.copySync(wasmDir, distWasmDir);
28
- console.log('Copied WASM files to:', distWasmDir);
29
- } else {
30
- console.warn('WASM directory not found:', wasmDir);
31
- }
32
-
33
- // Copy client.js for hydration
34
- const srcDir = path.join(__dirname, 'src');
35
- const distSrcDir = path.join(outputDir, 'src');
36
- fs.ensureDirSync(distSrcDir);
37
- fs.copySync(path.join(srcDir, 'client.js'), path.join(distSrcDir, 'client.js'));
38
-
39
- // Copy any other static assets
40
- const publicDir = path.join(__dirname, 'public');
41
- fs.readdirSync(publicDir).forEach(file => {
42
- if (file !== 'index.html' && file !== 'wasm') {
43
- const srcPath = path.join(publicDir, file);
44
- const destPath = path.join(outputDir, file);
45
- fs.copySync(srcPath, destPath);
46
- }
47
- });
48
-
49
- console.log('Build completed successfully.');
@@ -1,237 +0,0 @@
1
- import { execSync } from 'child_process';
2
- import { fileURLToPath } from 'url';
3
- import { dirname, resolve, join } from 'path';
4
- import fs from 'fs';
5
- import os from 'os';
6
-
7
- // Get __dirname equivalent in ESM
8
- const __filename = fileURLToPath(import.meta.url);
9
- const __dirname = dirname(__filename);
10
-
11
- // Check if running on Windows
12
- const isWindows = os.platform() === 'win32';
13
-
14
- // Check if Go is installed
15
- function checkGoInstallation() {
16
- try {
17
- const output = execSync('go version', { encoding: 'utf8' });
18
- console.log(`✓ Found Go: ${output.trim()}`);
19
- return true;
20
- } catch (error) {
21
- console.error('✗ Go is not installed or not in PATH');
22
- console.error('Please install Go from https://golang.org/dl/');
23
- return false;
24
- }
25
- }
26
-
27
- // Ensure directory exists
28
- function ensureDir(dir) {
29
- if (!fs.existsSync(dir)) {
30
- fs.mkdirSync(dir, { recursive: true });
31
- console.log(`Created directory: ${dir}`);
32
- }
33
- }
34
-
35
- // Build Go WASM modules
36
- async function buildWasmModules() {
37
- // Check if Go is installed
38
- if (!checkGoInstallation()) {
39
- process.exit(1);
40
- }
41
-
42
- // Directory containing Go source files
43
- const goSourceDir = resolve(__dirname, 'src', 'wasm');
44
-
45
- // Output directory for WASM files
46
- const wasmOutputDir = resolve(__dirname, 'public', 'wasm');
47
-
48
- // Create directories if they don't exist
49
- ensureDir(goSourceDir);
50
- ensureDir(wasmOutputDir);
51
-
52
- // Get the Go root directory
53
- const goRoot = execSync('go env GOROOT', { encoding: 'utf8' }).trim();
54
-
55
- // Copy the wasm_exec.js files to the output directory (for both browser and Node.js)
56
- const wasmExecJsPath = join(goRoot, 'misc', 'wasm', 'wasm_exec.js');
57
- const wasmExecJsDest = join(wasmOutputDir, 'wasm_exec.js');
58
-
59
- const wasmExecNodeJsPath = join(goRoot, 'misc', 'wasm', 'wasm_exec_node.js');
60
- const wasmExecNodeJsDest = join(wasmOutputDir, 'wasm_exec_node.js');
61
-
62
- console.log(`Copying ${wasmExecJsPath} to ${wasmExecJsDest}`);
63
- fs.copyFileSync(wasmExecJsPath, wasmExecJsDest);
64
-
65
- console.log(`Copying ${wasmExecNodeJsPath} to ${wasmExecNodeJsDest}`);
66
- fs.copyFileSync(wasmExecNodeJsPath, wasmExecNodeJsDest);
67
-
68
- // Build all Go files in the WASM directory
69
- const goFiles = fs.readdirSync(goSourceDir).filter(file => file.endsWith('.go'));
70
-
71
- if (goFiles.length === 0) {
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
- `;
152
-
153
- fs.writeFileSync(exampleGoFile, exampleGoContent);
154
- console.log(`Created example Go file at ${exampleGoFile}`);
155
-
156
- // Add the new file to the list
157
- goFiles.push('example.go');
158
- }
159
-
160
- // Build each Go file
161
- for (const goFile of goFiles) {
162
- const goFilePath = join(goSourceDir, goFile);
163
- const wasmFileName = goFile.replace('.go', '.wasm');
164
- const wasmFilePath = join(wasmOutputDir, wasmFileName);
165
-
166
- console.log(`Building ${goFile} to ${wasmFilePath}`);
167
-
168
- try {
169
- // Create a unique temporary directory with timestamp
170
- const timestamp = Date.now();
171
- const tempDir = join(os.tmpdir(), `go-wasm-build-${timestamp}`);
172
-
173
- // Ensure the directory is clean (doesn't exist from previous builds)
174
- if (fs.existsSync(tempDir)) {
175
- if (isWindows) {
176
- // On Windows, we need to handle directory removal differently
177
- execSync(`rmdir /s /q "${tempDir}"`, { shell: true });
178
- } else {
179
- fs.rmSync(tempDir, { recursive: true, force: true });
180
- }
181
- }
182
-
183
- // Create the temporary directory
184
- ensureDir(tempDir);
185
-
186
- // Copy the Go file to the temp directory
187
- const tempGoFile = join(tempDir, goFile);
188
- fs.copyFileSync(goFilePath, tempGoFile);
189
-
190
- // Initialize Go module
191
- console.log(`Initializing Go module in ${tempDir}`);
192
- execSync(`go mod init wasmapp`, { cwd: tempDir });
193
-
194
- // Build the WASM module with OS-specific command
195
- if (isWindows) {
196
- // Fix: Use Windows-specific environment variable setting
197
- execSync(`go build -o "${wasmFilePath}" "${tempGoFile}"`, {
198
- cwd: tempDir,
199
- env: {
200
- ...process.env,
201
- GOOS: 'js',
202
- GOARCH: 'wasm'
203
- }
204
- });
205
- } else {
206
- // Unix/Linux/Mac command
207
- execSync(`GOOS=js GOARCH=wasm go build -o "${wasmFilePath}" "${tempGoFile}"`, {
208
- cwd: tempDir
209
- });
210
- }
211
-
212
- // Clean up temporary directory
213
- try {
214
- if (isWindows) {
215
- execSync(`rmdir /s /q "${tempDir}"`, { shell: true });
216
- } else {
217
- fs.rmSync(tempDir, { recursive: true, force: true });
218
- }
219
- } catch (cleanupError) {
220
- console.warn(`Warning: Failed to clean up temp directory ${tempDir}:`, cleanupError);
221
- }
222
-
223
- console.log(`✓ Successfully built ${wasmFileName}`);
224
- } catch (error) {
225
- console.error(`✗ Error building ${goFile}:`);
226
- console.error(error.message);
227
- if (error.stdout) console.error(error.stdout.toString());
228
- if (error.stderr) console.error(error.stderr.toString());
229
- }
230
- }
231
- }
232
-
233
- // Run the build process
234
- buildWasmModules().catch(error => {
235
- console.error('Build failed:', error);
236
- process.exit(1);
237
- });
@@ -1,62 +0,0 @@
1
- // CommonJS/ESM compatible build configuration
2
- const buildConfig = {
3
- /**
4
- * Determines if we should build for dual module support
5
- */
6
- dualModuleSupport: true,
7
-
8
- /**
9
- * Entry points for both client and server
10
- */
11
- entryPoints: {
12
- client: 'src/client.js',
13
- server: 'src/server.js'
14
- },
15
-
16
- /**
17
- * Output formats to generate
18
- */
19
- outputFormats: ['esm', 'cjs'],
20
-
21
- /**
22
- * Output directory configuration
23
- */
24
- output: {
25
- dir: 'dist',
26
- client: {
27
- esm: 'assets/[name].mjs',
28
- cjs: 'assets/[name].js'
29
- },
30
- server: {
31
- esm: 'server/[name].mjs',
32
- cjs: 'server/[name].js'
33
- }
34
- },
35
-
36
- /**
37
- * WebAssembly configuration
38
- */
39
- wasm: {
40
- enabled: true,
41
- goBinaryPath: 'go',
42
- sourceDir: 'src/wasm',
43
- outputDir: 'public/wasm',
44
- copyGoRuntime: true
45
- },
46
-
47
- /**
48
- * Additional build options
49
- */
50
- options: {
51
- minify: process.env.NODE_ENV === 'production',
52
- sourcemap: true,
53
- target: 'es2020'
54
- }
55
- };
56
-
57
- // Make it work in both ESM and CommonJS environments
58
- if (typeof module !== 'undefined' && module.exports) {
59
- module.exports = buildConfig;
60
- }
61
-
62
- export default buildConfig;
@@ -1,218 +0,0 @@
1
- // Support both ESM and CommonJS imports
2
- const path = require('path');
3
- const fs = require('fs');
4
- const esbuild = require('esbuild');
5
- const { execSync } = require('child_process');
6
- const config = require('./build.config.js');
7
-
8
- // Define colors for console output
9
- const colors = {
10
- reset: "\x1b[0m",
11
- bright: "\x1b[1m",
12
- dim: "\x1b[2m",
13
- underscore: "\x1b[4m",
14
- blink: "\x1b[5m",
15
- cyan: "\x1b[36m",
16
- green: "\x1b[32m",
17
- yellow: "\x1b[33m",
18
- red: "\x1b[31m"
19
- };
20
-
21
- // Helper for formatted console logs
22
- function log(message, type = 'info') {
23
- const timestamp = new Date().toISOString().split('T')[1].split('.')[0];
24
- const prefix = {
25
- info: `${colors.bright}${colors.cyan}[INFO]${colors.reset}`,
26
- success: `${colors.bright}${colors.green}[SUCCESS]${colors.reset}`,
27
- warning: `${colors.bright}${colors.yellow}[WARNING]${colors.reset}`,
28
- error: `${colors.bright}${colors.red}[ERROR]${colors.reset}`
29
- };
30
-
31
- console.log(`${colors.dim}[${timestamp}]${colors.reset} ${prefix[type] || prefix.info} ${message}`);
32
- }
33
-
34
- // Main build function
35
- async function build() {
36
- try {
37
- log(`Starting build process (${process.env.NODE_ENV || 'development'} mode)`);
38
-
39
- // Ensure output directories
40
- ensureDir(path.join(__dirname, 'dist'));
41
- ensureDir(path.join(__dirname, 'dist/server'));
42
- ensureDir(path.join(__dirname, 'dist/assets'));
43
- ensureDir(path.join(__dirname, 'public/wasm'));
44
-
45
- // Build the WASM modules if enabled
46
- if (config.wasm.enabled) {
47
- await buildWasmModules();
48
- }
49
-
50
- // Build the client code
51
- await buildClient();
52
-
53
- // Build the server code if it exists
54
- if (fs.existsSync(path.join(__dirname, config.entryPoints.server))) {
55
- await buildServer();
56
- }
57
-
58
- log('Build completed successfully', 'success');
59
- } catch (error) {
60
- log(`Build failed: ${error.message}`, 'error');
61
- console.error(error);
62
- process.exit(1);
63
- }
64
- }
65
-
66
- // Build WebAssembly modules
67
- async function buildWasmModules() {
68
- const sourceDir = path.join(__dirname, config.wasm.sourceDir);
69
- const outputDir = path.join(__dirname, config.wasm.outputDir);
70
-
71
- if (!fs.existsSync(sourceDir)) {
72
- log(`WASM source directory not found: ${sourceDir}`, 'warning');
73
- return;
74
- }
75
-
76
- log('Building WebAssembly modules...');
77
-
78
- // Get all .go files that need to be compiled
79
- const goFiles = fs.readdirSync(sourceDir)
80
- .filter(file => file.endsWith('.go'));
81
-
82
- if (goFiles.length === 0) {
83
- log('No Go files found to compile', 'warning');
84
- return;
85
- }
86
-
87
- // Compile each Go file to WASM
88
- for (const goFile of goFiles) {
89
- const goFilePath = path.join(sourceDir, goFile);
90
- const wasmFileName = goFile.replace('.go', '.wasm');
91
- const wasmFilePath = path.join(outputDir, wasmFileName);
92
-
93
- log(`Compiling ${goFile} to WebAssembly...`);
94
-
95
- try {
96
- // Set environment variables for Go WASM compilation
97
- const env = {
98
- ...process.env,
99
- GOOS: 'js',
100
- GOARCH: 'wasm'
101
- };
102
-
103
- // Compile Go to WASM
104
- execSync(`${config.wasm.goBinaryPath} build -o "${wasmFilePath}" "${goFilePath}"`, {
105
- env,
106
- stdio: 'inherit'
107
- });
108
-
109
- log(`Successfully compiled ${goFile} to ${wasmFileName}`, 'success');
110
- } catch (error) {
111
- log(`Failed to compile ${goFile}: ${error.message}`, 'error');
112
- throw error;
113
- }
114
- }
115
-
116
- // Copy wasm_exec.js from Go installation to public folder
117
- if (config.wasm.copyGoRuntime) {
118
- try {
119
- const goRoot = execSync(`${config.wasm.goBinaryPath} env GOROOT`, { encoding: 'utf8' }).trim();
120
- const wasmExecSrc = path.join(goRoot, 'misc', 'wasm', 'wasm_exec.js');
121
- const wasmExecDest = path.join(outputDir, 'wasm_exec.js');
122
-
123
- fs.copyFileSync(wasmExecSrc, wasmExecDest);
124
- log('Copied wasm_exec.js runtime to public folder', 'success');
125
- } catch (error) {
126
- log(`Failed to copy wasm_exec.js: ${error.message}`, 'warning');
127
- }
128
- }
129
- }
130
-
131
- // Build client code with esbuild
132
- async function buildClient() {
133
- const formats = config.dualModuleSupport ? config.outputFormats : ['esm'];
134
-
135
- for (const format of formats) {
136
- const outfile = path.join(
137
- __dirname,
138
- 'dist',
139
- config.output.client[format].replace('[name]', 'client')
140
- );
141
-
142
- log(`Building client bundle (${format})...`);
143
-
144
- await esbuild.build({
145
- entryPoints: [path.join(__dirname, config.entryPoints.client)],
146
- bundle: true,
147
- outfile,
148
- format,
149
- platform: 'browser',
150
- target: config.options.target,
151
- minify: config.options.minify,
152
- sourcemap: config.options.sourcemap,
153
- define: {
154
- 'process.env.NODE_ENV': JSON.stringify(process.env.NODE_ENV || 'development'),
155
- '__ESM__': format === 'esm' ? 'true' : 'false'
156
- },
157
- jsxFactory: 'jsx',
158
- jsxFragment: 'Fragment',
159
- banner: {
160
- js: format === 'esm'
161
- ? `import { jsx, Fragment } from 'frontend-hamroun/jsx-runtime';`
162
- : `const { jsx, Fragment } = require('frontend-hamroun/jsx-runtime');`
163
- }
164
- });
165
- }
166
-
167
- log('Client build completed', 'success');
168
- }
169
-
170
- // Build server code with esbuild
171
- async function buildServer() {
172
- const formats = config.dualModuleSupport ? config.outputFormats : ['cjs'];
173
-
174
- for (const format of formats) {
175
- const outfile = path.join(
176
- __dirname,
177
- 'dist',
178
- config.output.server[format].replace('[name]', 'server')
179
- );
180
-
181
- log(`Building server bundle (${format})...`);
182
-
183
- await esbuild.build({
184
- entryPoints: [path.join(__dirname, config.entryPoints.server)],
185
- bundle: true,
186
- outfile,
187
- format,
188
- platform: 'node',
189
- target: config.options.target,
190
- minify: config.options.minify,
191
- sourcemap: config.options.sourcemap,
192
- external: ['express', 'cors', 'path', 'fs', 'frontend-hamroun', 'frontend-hamroun/*'],
193
- define: {
194
- 'process.env.NODE_ENV': JSON.stringify(process.env.NODE_ENV || 'development'),
195
- '__ESM__': format === 'esm' ? 'true' : 'false'
196
- }
197
- });
198
- }
199
-
200
- log('Server build completed', 'success');
201
- }
202
-
203
- // Utility to ensure directory exists
204
- function ensureDir(dir) {
205
- if (!fs.existsSync(dir)) {
206
- fs.mkdirSync(dir, { recursive: true });
207
- }
208
- }
209
-
210
- // Execute the build
211
- build();
212
-
213
- // Support both CommonJS and ESM
214
- if (typeof module !== 'undefined' && module.exports) {
215
- module.exports = { build };
216
- }
217
-
218
- export { build };
@@ -1,32 +0,0 @@
1
- {
2
- "name": "go-wasm-app",
3
- "version": "1.0.0",
4
- "type": "commonjs",
5
- "description": "Frontend Hamroun app with Go WebAssembly integration",
6
- "scripts": {
7
- "dev": "cross-env NODE_ENV=development node server.js",
8
- "build": "cross-env NODE_ENV=production node build.js",
9
- "build:wasm": "node build.js --wasm-only",
10
- "start": "cross-env NODE_ENV=production node dist/server/server.js",
11
- "test": "vitest run"
12
- },
13
- "dependencies": {
14
- "express": "^4.18.2",
15
- "frontend-hamroun": "latest"
16
- },
17
- "devDependencies": {
18
- "cross-env": "^7.0.3",
19
- "esbuild": "^0.19.5",
20
- "nodemon": "^3.0.1",
21
- "vitest": "^0.34.6"
22
- },
23
- "engines": {
24
- "node": ">=16.0.0"
25
- },
26
- "exports": {
27
- ".": {
28
- "import": "./dist/assets/client.mjs",
29
- "require": "./dist/assets/client.js"
30
- }
31
- }
32
- }