frontend-hamroun 1.2.75 → 1.2.77
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/dist/batch/package.json +16 -0
- package/dist/client-router/package.json +16 -0
- package/dist/component/package.json +16 -0
- package/dist/context/package.json +16 -0
- package/dist/event-bus/package.json +16 -0
- package/dist/forms/package.json +16 -0
- package/dist/hooks/package.json +16 -0
- package/dist/jsx-runtime/package.json +16 -0
- package/dist/lifecycle-events/package.json +16 -0
- package/dist/package.json +71 -0
- package/dist/render-component/package.json +16 -0
- package/dist/renderer/package.json +16 -0
- package/dist/router/package.json +16 -0
- package/dist/server/package.json +17 -0
- package/dist/server/src/client-router.d.ts +60 -0
- package/dist/server/src/client-router.js +210 -0
- package/dist/server/src/client-router.js.map +1 -0
- package/dist/server/src/component.js +1 -1
- package/dist/server/src/event-bus.d.ts +23 -0
- package/dist/server/src/event-bus.js +75 -0
- package/dist/server/src/event-bus.js.map +1 -0
- package/dist/server/src/forms.d.ts +40 -0
- package/dist/server/src/forms.js +148 -0
- package/dist/server/src/forms.js.map +1 -0
- package/dist/server/src/hooks.js +2 -2
- package/dist/server/src/index.js +19 -11
- package/dist/server/src/lifecycle-events.d.ts +108 -0
- package/dist/server/src/lifecycle-events.js +177 -0
- package/dist/server/src/lifecycle-events.js.map +1 -0
- package/dist/server/src/renderComponent.js +1 -1
- package/dist/server/src/renderer.js +3 -3
- package/dist/server/src/router.d.ts +55 -0
- package/dist/server/src/router.js +166 -0
- package/dist/server/src/router.js.map +1 -0
- package/dist/server/src/server/index.d.ts +75 -2
- package/dist/server/src/server/index.js +224 -8
- package/dist/server/src/server/index.js.map +1 -1
- package/dist/server/src/server/server.js +1 -1
- package/dist/server/src/server/templates.d.ts +28 -0
- package/dist/server/src/server/templates.js +204 -0
- package/dist/server/src/server/templates.js.map +1 -0
- package/dist/server/src/server/utils.d.ts +70 -0
- package/dist/server/src/server/utils.js +156 -0
- package/dist/server/src/server/utils.js.map +1 -0
- package/dist/server/src/server-renderer.js +1 -1
- package/dist/server/src/store.d.ts +41 -0
- package/dist/server/src/store.js +99 -0
- package/dist/server/src/store.js.map +1 -0
- package/dist/server/src/utils.d.ts +46 -0
- package/dist/server/src/utils.js +144 -0
- package/dist/server/src/utils.js.map +1 -0
- package/dist/server/tsconfig.server.tsbuildinfo +1 -1
- package/dist/server-renderer/package.json +16 -0
- package/dist/store/package.json +16 -0
- package/dist/types/package.json +16 -0
- package/dist/utils/package.json +16 -0
- package/dist/vdom/package.json +16 -0
- package/dist/wasm/package.json +16 -0
- package/package.json +14 -13
- package/templates/complete-app/build.js +284 -0
- package/templates/complete-app/package.json +40 -0
- package/templates/complete-app/public/styles.css +345 -0
- package/templates/complete-app/src/api/index.js +31 -0
- package/templates/complete-app/src/client.js +93 -0
- package/templates/complete-app/src/components/App.js +66 -0
- package/templates/complete-app/src/components/Footer.js +19 -0
- package/templates/complete-app/src/components/Header.js +38 -0
- package/templates/complete-app/src/pages/About.js +59 -0
- package/templates/complete-app/src/pages/Home.js +54 -0
- package/templates/complete-app/src/pages/WasmDemo.js +136 -0
- package/templates/complete-app/src/server.js +186 -0
- package/templates/complete-app/src/wasm/build.bat +16 -0
- package/templates/complete-app/src/wasm/build.sh +16 -0
- package/templates/complete-app/src/wasm/example.go +101 -0
- package/templates/fullstack-app/build/main.css +225 -15
- package/templates/fullstack-app/build/main.css.map +2 -2
- package/templates/fullstack-app/build/main.js +657 -372
- package/templates/fullstack-app/build/main.js.map +4 -4
- package/templates/fullstack-app/build.ts +3 -4
- package/templates/fullstack-app/public/styles.css +222 -15
- package/templates/fullstack-app/server.ts +46 -12
- package/templates/fullstack-app/src/components/ClientHome.tsx +0 -0
- package/templates/fullstack-app/src/components/ErrorBoundary.tsx +36 -0
- package/templates/fullstack-app/src/components/Layout.tsx +23 -26
- package/templates/fullstack-app/src/components/StateDemo.tsx +207 -0
- package/templates/fullstack-app/src/components/UserList.tsx +30 -13
- package/templates/fullstack-app/src/data/api.ts +173 -38
- package/templates/fullstack-app/src/main.tsx +88 -154
- package/templates/fullstack-app/src/middleware.ts +28 -0
- package/templates/fullstack-app/src/pages/404.tsx +28 -0
- package/templates/fullstack-app/src/pages/[id].tsx +0 -0
- package/templates/fullstack-app/src/pages/_app.tsx +11 -0
- package/templates/fullstack-app/src/pages/_document.tsx +25 -0
- package/templates/fullstack-app/src/pages/_error.tsx +45 -0
- package/templates/fullstack-app/src/pages/about.tsx +71 -0
- package/templates/fullstack-app/src/pages/api/users/[id].ts +73 -0
- package/templates/fullstack-app/src/pages/api/users/index.ts +43 -0
- package/templates/fullstack-app/src/pages/index.tsx +97 -20
- package/templates/fullstack-app/src/pages/users/[id].tsx +153 -0
- package/templates/fullstack-app/src/pages/wasm-demo.tsx +1 -0
- package/templates/go/example.go +99 -86
- package/templates/go-wasm-app/babel.config.js +8 -2
- package/templates/go-wasm-app/build.config.js +62 -0
- package/templates/go-wasm-app/build.js +218 -0
- package/templates/go-wasm-app/package.json +21 -12
- package/templates/go-wasm-app/server.js +59 -510
- package/templates/go-wasm-app/src/app.js +173 -0
- package/templates/go-wasm-app/vite.config.js +16 -5
- package/templates/ssr-template/client.js +54 -26
- package/templates/ssr-template/server.js +5 -28
- package/templates/ssr-template/vite.config.js +21 -5
- package/dist/server/wasm.d.ts +0 -7
- package/dist/wasm.d.ts +0 -37
@@ -0,0 +1,218 @@
|
|
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,23 +1,32 @@
|
|
1
1
|
{
|
2
2
|
"name": "go-wasm-app",
|
3
3
|
"version": "1.0.0",
|
4
|
-
"
|
5
|
-
"
|
6
|
-
"main": "server.js",
|
4
|
+
"type": "commonjs",
|
5
|
+
"description": "Frontend Hamroun app with Go WebAssembly integration",
|
7
6
|
"scripts": {
|
8
|
-
"
|
9
|
-
"
|
10
|
-
"
|
11
|
-
"
|
12
|
-
"
|
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"
|
13
12
|
},
|
14
13
|
"dependencies": {
|
15
14
|
"express": "^4.18.2",
|
16
|
-
"frontend-hamroun": "
|
17
|
-
"fs-extra": "^10.0.0"
|
15
|
+
"frontend-hamroun": "latest"
|
18
16
|
},
|
19
17
|
"devDependencies": {
|
20
|
-
"
|
21
|
-
"
|
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
|
+
}
|
22
31
|
}
|
23
32
|
}
|