frontend-hamroun 1.2.71 → 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.71",
3
+ "version": "1.2.72",
4
4
  "description": "A lightweight full-stack JavaScript framework",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
@@ -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,17 +45,10 @@ 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
- // Create Go source directory if it doesn't exist
46
- if (!fs.existsSync(goSourceDir)) {
47
- fs.mkdirSync(goSourceDir, { recursive: true });
48
- console.log(`Created Go source directory: ${goSourceDir}`);
49
- }
50
-
51
52
  // Get the Go root directory
52
53
  const goRoot = execSync('go env GOROOT', { encoding: 'utf8' }).trim();
53
54
 
@@ -61,30 +62,17 @@ async function buildWasmModules() {
61
62
  console.log(`Copying ${wasmExecJsPath} to ${wasmExecJsDest}`);
62
63
  fs.copyFileSync(wasmExecJsPath, wasmExecJsDest);
63
64
 
64
- // Copy Node.js WASM executor if it exists
65
- if (fs.existsSync(wasmExecNodeJsPath)) {
66
- console.log(`Copying ${wasmExecNodeJsPath} to ${wasmExecNodeJsDest}`);
67
- fs.copyFileSync(wasmExecNodeJsPath, wasmExecNodeJsDest);
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');
68
73
 
69
- // Also try to copy the go_js_wasm_exec script that's needed in some Go versions
70
- try {
71
- const goJsWasmExecPath = join(goRoot, 'misc', 'wasm', 'go_js_wasm_exec');
72
- if (fs.existsSync(goJsWasmExecPath)) {
73
- const goJsWasmExecDest = join(wasmOutputDir, 'go_js_wasm_exec');
74
- fs.copyFileSync(goJsWasmExecPath, goJsWasmExecDest);
75
- fs.chmodSync(goJsWasmExecDest, '755'); // Make executable
76
- console.log(`Copied go_js_wasm_exec to ${goJsWasmExecDest}`);
77
- }
78
- } catch (error) {
79
- console.warn("Could not copy go_js_wasm_exec:", error.message);
80
- }
81
- } else {
82
- console.warn(`${wasmExecNodeJsPath} not found, skipping Node.js WASM support`);
83
- }
84
-
85
- // Create an example Go file if it doesn't exist
86
- const exampleGoFile = join(goSourceDir, 'example.go');
87
- if (!fs.existsSync(exampleGoFile)) {
74
+ // Create an example Go file
75
+ const exampleGoFile = join(goSourceDir, 'example.go');
88
76
  const exampleGoContent = `//go:build js && wasm
89
77
  // +build js,wasm
90
78
 
@@ -164,14 +152,9 @@ func main() {
164
152
 
165
153
  fs.writeFileSync(exampleGoFile, exampleGoContent);
166
154
  console.log(`Created example Go file at ${exampleGoFile}`);
167
- }
168
-
169
- // Get list of Go files
170
- const goFiles = fs.readdirSync(goSourceDir).filter(file => file.endsWith('.go'));
171
-
172
- if (goFiles.length === 0) {
173
- console.log('No Go files found in src/wasm');
174
- return;
155
+
156
+ // Add the new file to the list
157
+ goFiles.push('example.go');
175
158
  }
176
159
 
177
160
  // Build each Go file
@@ -189,10 +172,16 @@ func main() {
189
172
 
190
173
  // Ensure the directory is clean (doesn't exist from previous builds)
191
174
  if (fs.existsSync(tempDir)) {
192
- fs.rmSync(tempDir, { recursive: true, force: true });
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
+ }
193
181
  }
194
182
 
195
- fs.mkdirSync(tempDir, { recursive: true });
183
+ // Create the temporary directory
184
+ ensureDir(tempDir);
196
185
 
197
186
  // Copy the Go file to the temp directory
198
187
  const tempGoFile = join(tempDir, goFile);
@@ -221,7 +210,15 @@ func main() {
221
210
  }
222
211
 
223
212
  // Clean up temporary directory
224
- fs.rmSync(tempDir, { recursive: true, force: true });
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
+ }
225
222
 
226
223
  console.log(`✓ Successfully built ${wasmFileName}`);
227
224
  } catch (error) {
@@ -5,17 +5,19 @@
5
5
  "type": "module",
6
6
  "main": "server.js",
7
7
  "scripts": {
8
- "prepare": "mkdir -p public/wasm || mkdir public\\wasm",
9
8
  "build:wasm": "node build-wasm.js",
10
- "dev": "npm run prepare && npm run build:wasm && node --watch server.js",
11
- "build": "npm run build:wasm && mkdir -p dist && cp -r public/* dist/",
12
- "start": "NODE_ENV=production node server.js"
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
+ "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.70"
16
+ "frontend-hamroun": "^1.2.71",
17
+ "fs-extra": "^10.0.0"
17
18
  },
18
19
  "devDependencies": {
19
- "@babel/core": "^7.22.9"
20
+ "@babel/core": "^7.22.9",
21
+ "cross-env": "^7.0.3"
20
22
  }
21
23
  }