frontend-hamroun 1.2.70 → 1.2.72

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "frontend-hamroun",
3
- "version": "1.2.70",
3
+ "version": "1.2.72",
4
4
  "description": "A lightweight full-stack JavaScript framework",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
@@ -9,7 +9,6 @@ This template demonstrates integration between Frontend Hamroun, Go WebAssembly,
9
9
  - ⚡ High-performance computation in both browser and server
10
10
  - 🚀 Same Go code runs in both environments
11
11
  - 🔍 SEO-friendly with pre-rendered HTML
12
- - 🧩 Example Go WASM modules and usage patterns
13
12
 
14
13
  ## Prerequisites
15
14
 
@@ -19,4 +18,21 @@ This template demonstrates integration between Frontend Hamroun, Go WebAssembly,
19
18
  ## Getting Started
20
19
 
21
20
  1. Install dependencies:
22
-
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
@@ -0,0 +1,15 @@
1
+ export default {
2
+ presets: [
3
+ ['@babel/preset-env', {
4
+ targets: {
5
+ node: 'current'
6
+ }
7
+ }]
8
+ ],
9
+ plugins: [
10
+ ['@babel/plugin-transform-react-jsx', {
11
+ pragma: 'createElement',
12
+ pragmaFrag: 'Fragment'
13
+ }]
14
+ ]
15
+ };
@@ -0,0 +1,49 @@
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.');
@@ -24,6 +24,14 @@ function checkGoInstallation() {
24
24
  }
25
25
  }
26
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
+
27
35
  // Build Go WASM modules
28
36
  async function buildWasmModules() {
29
37
  // Check if Go is installed
@@ -37,10 +45,9 @@ async function buildWasmModules() {
37
45
  // Output directory for WASM files
38
46
  const wasmOutputDir = resolve(__dirname, 'public', 'wasm');
39
47
 
40
- // Create output directory if it doesn't exist
41
- if (!fs.existsSync(wasmOutputDir)) {
42
- fs.mkdirSync(wasmOutputDir, { recursive: true });
43
- }
48
+ // Create directories if they don't exist
49
+ ensureDir(goSourceDir);
50
+ ensureDir(wasmOutputDir);
44
51
 
45
52
  // Get the Go root directory
46
53
  const goRoot = execSync('go env GOROOT', { encoding: 'utf8' }).trim();
@@ -59,77 +66,12 @@ async function buildWasmModules() {
59
66
  fs.copyFileSync(wasmExecNodeJsPath, wasmExecNodeJsDest);
60
67
 
61
68
  // Build all Go files in the WASM directory
62
- if (fs.existsSync(goSourceDir)) {
63
- const goFiles = fs.readdirSync(goSourceDir)
64
- .filter(file => file.endsWith('.go'));
65
-
66
- if (goFiles.length === 0) {
67
- console.log('No Go files found in src/wasm');
68
- return;
69
- }
70
-
71
- for (const goFile of goFiles) {
72
- const goFilePath = join(goSourceDir, goFile);
73
- const wasmFileName = goFile.replace('.go', '.wasm');
74
- const wasmFilePath = join(wasmOutputDir, wasmFileName);
75
-
76
- console.log(`Building ${goFile} to ${wasmFilePath}`);
77
-
78
- try {
79
- // Create a unique temporary directory with timestamp
80
- const timestamp = Date.now();
81
- const tempDir = join(os.tmpdir(), `go-wasm-build-${timestamp}`);
82
-
83
- // Ensure the directory is clean (doesn't exist from previous builds)
84
- if (fs.existsSync(tempDir)) {
85
- fs.rmSync(tempDir, { recursive: true, force: true });
86
- }
87
-
88
- fs.mkdirSync(tempDir, { recursive: true });
89
-
90
- // Copy the Go file to the temp directory
91
- const tempGoFile = join(tempDir, goFile);
92
- fs.copyFileSync(goFilePath, tempGoFile);
93
-
94
- // Initialize Go module
95
- console.log(`Initializing Go module in ${tempDir}`);
96
- execSync(`go mod init wasmapp`, { cwd: tempDir });
97
-
98
- // Build the WASM module with OS-specific command
99
- if (isWindows) {
100
- // Fix: Windows command without spaces in environment variables
101
- // and using environment object instead of command-line args
102
- execSync(`go build -o "${wasmFilePath}" "${tempGoFile}"`, {
103
- cwd: tempDir,
104
- env: {
105
- ...process.env,
106
- GOOS: 'js',
107
- GOARCH: 'wasm'
108
- }
109
- });
110
- } else {
111
- // Unix/Linux/Mac command
112
- execSync(`GOOS=js GOARCH=wasm go build -o "${wasmFilePath}" "${tempGoFile}"`, {
113
- cwd: tempDir
114
- });
115
- }
116
-
117
- // Clean up temporary directory
118
- fs.rmSync(tempDir, { recursive: true, force: true });
119
-
120
- console.log(`✓ Successfully built ${wasmFileName}`);
121
- } catch (error) {
122
- console.error(`✗ Error building ${goFile}:`);
123
- console.error(error.message);
124
- if (error.stdout) console.error(error.stdout.toString());
125
- if (error.stderr) console.error(error.stderr.toString());
126
- }
127
- }
128
- } else {
129
- console.log(`Go source directory ${goSourceDir} not found, creating it...`);
130
- fs.mkdirSync(goSourceDir, { recursive: true });
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');
131
73
 
132
- // Create an example Go file if the directory is empty
74
+ // Create an example Go file
133
75
  const exampleGoFile = join(goSourceDir, 'example.go');
134
76
  const exampleGoContent = `//go:build js && wasm
135
77
  // +build js,wasm
@@ -211,9 +153,80 @@ func main() {
211
153
  fs.writeFileSync(exampleGoFile, exampleGoContent);
212
154
  console.log(`Created example Go file at ${exampleGoFile}`);
213
155
 
214
- // Build the example file
215
- console.log('Building example Go file...');
216
- buildWasmModules();
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
+ }
217
230
  }
218
231
  }
219
232