@effindomv2/fui-as 0.1.1 → 0.1.3

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.
@@ -5,12 +5,13 @@ set -euo pipefail
5
5
  PACKAGE_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
6
6
  REPO_ROOT="$(cd "${PACKAGE_DIR}/../.." && pwd)"
7
7
  DEMO_OUT_DIR="${REPO_ROOT}/public/v2/fui-as/demo"
8
+ MVC_OUT_DIR="${REPO_ROOT}/public/v2/fui-as/demo-mvc"
8
9
  HELLO_OUT_DIR="${REPO_ROOT}/public/v2/fui-as/demo-hello-world"
9
10
  HOST_SERVICE_GENERATOR_BUILD="${PACKAGE_DIR}/build/generate-host-services.mjs"
10
11
  HOST_EVENT_GENERATOR_BUILD="${PACKAGE_DIR}/build/generate-host-events.mjs"
11
12
  BUILD_TARGET="${1:-all}"
12
13
 
13
- mkdir -p "${PACKAGE_DIR}/build" "${DEMO_OUT_DIR}" "${HELLO_OUT_DIR}"
14
+ mkdir -p "${PACKAGE_DIR}/build" "${DEMO_OUT_DIR}" "${MVC_OUT_DIR}" "${HELLO_OUT_DIR}" "${PACKAGE_DIR}/templates/demo-mvc/src/host/generated" "${PACKAGE_DIR}/templates/demo-hello-world/src/host/generated"
14
15
  cd "${PACKAGE_DIR}"
15
16
 
16
17
  build_demo_app() {
@@ -28,6 +29,8 @@ generate_host_services() {
28
29
  local definition_file="$1"
29
30
  local export_name="$2"
30
31
  local output_file="$3"
32
+ local primitives_import="${4:-}"
33
+ local host_import_module="${5:-}"
31
34
 
32
35
  npx esbuild "${PACKAGE_DIR}/scripts/generate-host-services.ts" \
33
36
  --bundle \
@@ -37,13 +40,23 @@ generate_host_services() {
37
40
  --packages=external \
38
41
  --outfile="${HOST_SERVICE_GENERATOR_BUILD}"
39
42
 
40
- node "${HOST_SERVICE_GENERATOR_BUILD}" "${definition_file}" "${export_name}" "${output_file}"
43
+ if [ -n "${primitives_import}" ] && [ -n "${host_import_module}" ]; then
44
+ node "${HOST_SERVICE_GENERATOR_BUILD}" \
45
+ "${definition_file}" "${export_name}" "${output_file}" "${primitives_import}" "${host_import_module}"
46
+ elif [ -n "${primitives_import}" ]; then
47
+ node "${HOST_SERVICE_GENERATOR_BUILD}" "${definition_file}" "${export_name}" "${output_file}" "${primitives_import}"
48
+ elif [ -n "${host_import_module}" ]; then
49
+ node "${HOST_SERVICE_GENERATOR_BUILD}" "${definition_file}" "${export_name}" "${output_file}" "" "${host_import_module}"
50
+ else
51
+ node "${HOST_SERVICE_GENERATOR_BUILD}" "${definition_file}" "${export_name}" "${output_file}"
52
+ fi
41
53
  }
42
54
 
43
55
  generate_host_events() {
44
56
  local definition_file="$1"
45
57
  local export_name="$2"
46
58
  local output_file="$3"
59
+ local primitives_import="${4:-}"
47
60
 
48
61
  npx esbuild "${PACKAGE_DIR}/scripts/generate-host-events.ts" \
49
62
  --bundle \
@@ -53,12 +66,21 @@ generate_host_events() {
53
66
  --packages=external \
54
67
  --outfile="${HOST_EVENT_GENERATOR_BUILD}"
55
68
 
56
- node "${HOST_EVENT_GENERATOR_BUILD}" "${definition_file}" "${export_name}" "${output_file}"
69
+ if [ -n "${primitives_import}" ]; then
70
+ node "${HOST_EVENT_GENERATOR_BUILD}" "${definition_file}" "${export_name}" "${output_file}" "${primitives_import}"
71
+ else
72
+ node "${HOST_EVENT_GENERATOR_BUILD}" "${definition_file}" "${export_name}" "${output_file}"
73
+ fi
57
74
  }
58
75
 
59
76
  generate_host_services "demo/src/host-services.ts" "demoHostServices" "demo/src/generated/HostServices.ts"
60
77
  generate_host_events "demo/src/host-events.ts" "demoHostEvents" "demo/src/generated/HostEvents.ts"
61
78
  generate_host_services "demo/src/worker-host-services.ts" "demoWorkerHostServices" "demo/src/generated/WorkerHostServices.ts"
79
+ generate_host_services "scripts/framework-host-services.ts" "frameworkHostServices" "src/core/generated/FrameworkHostServices.ts" "" "fui_host"
80
+ generate_host_services "templates/demo-hello-world/src/host/host-services.ts" "appHostServices" "templates/demo-hello-world/src/host/generated/HostServices.ts" "../../fui/FuiPrimitives"
81
+ generate_host_events "templates/demo-hello-world/src/host/host-events.ts" "appHostEvents" "templates/demo-hello-world/src/host/generated/HostEvents.ts" "../../fui/FuiPrimitives"
82
+ generate_host_services "templates/demo-mvc/src/host/host-services.ts" "appHostServices" "templates/demo-mvc/src/host/generated/HostServices.ts" "../../fui/FuiPrimitives"
83
+ generate_host_events "templates/demo-mvc/src/host/host-events.ts" "appHostEvents" "templates/demo-mvc/src/host/generated/HostEvents.ts" "../../fui/FuiPrimitives"
62
84
 
63
85
  case "${BUILD_TARGET}" in
64
86
  all)
@@ -66,7 +88,9 @@ case "${BUILD_TARGET}" in
66
88
  build_demo_app "demo/src/routes/demo_home.ts" "${DEMO_OUT_DIR}/home.wasm"
67
89
  build_demo_app "demo/src/routes/demo_advanced_controls.ts" "${DEMO_OUT_DIR}/advanced-controls.wasm"
68
90
  build_demo_app "demo/src/routes/templated-controls.ts" "${DEMO_OUT_DIR}/templated-controls.wasm"
69
- build_demo_app "demo-hello-world/src/App.ts" "${HELLO_OUT_DIR}/app.wasm"
91
+ build_demo_app "templates/demo-mvc/src/routes/mvc_home.ts" "${MVC_OUT_DIR}/mvc-home.wasm"
92
+ build_demo_app "templates/demo-mvc/src/routes/mvc_settings.ts" "${MVC_OUT_DIR}/mvc-settings.wasm"
93
+ build_demo_app "templates/demo-hello-world/src/App.ts" "${HELLO_OUT_DIR}/app.wasm"
70
94
  ;;
71
95
  dashboard)
72
96
  build_demo_app "demo/src/dashboard.ts" "${DEMO_OUT_DIR}/demo.wasm"
@@ -80,12 +104,18 @@ case "${BUILD_TARGET}" in
80
104
  templated-controls|templated)
81
105
  build_demo_app "demo/src/routes/templated-controls.ts" "${DEMO_OUT_DIR}/templated-controls.wasm"
82
106
  ;;
107
+ mvc-home|mvc-home-page)
108
+ build_demo_app "templates/demo-mvc/src/routes/mvc_home.ts" "${MVC_OUT_DIR}/mvc-home.wasm"
109
+ ;;
110
+ mvc-settings|mvc-settings-page)
111
+ build_demo_app "templates/demo-mvc/src/routes/mvc_settings.ts" "${MVC_OUT_DIR}/mvc-settings.wasm"
112
+ ;;
83
113
  hello-world|hello)
84
- build_demo_app "demo-hello-world/src/App.ts" "${HELLO_OUT_DIR}/app.wasm"
114
+ build_demo_app "templates/demo-hello-world/src/App.ts" "${HELLO_OUT_DIR}/app.wasm"
85
115
  ;;
86
116
  *)
87
117
  echo "Unknown build target: ${BUILD_TARGET}" >&2
88
- echo "Usage: bash scripts/build-demo-as.sh [all|dashboard|home|advanced-controls|templated-controls|hello-world]" >&2
118
+ echo "Usage: bash scripts/build-demo-as.sh [all|dashboard|home|advanced-controls|templated-controls|mvc-home|mvc-settings|hello-world]" >&2
89
119
  exit 1
90
120
  ;;
91
121
  esac
package/scripts/build.sh CHANGED
@@ -8,6 +8,7 @@ BROWSER_SRC_DIR="${PACKAGE_DIR}/browser/src"
8
8
  SMOKE_FIXTURE_DIR="${PACKAGE_DIR}/tests/fixtures/smoke"
9
9
  OUT_DIR="${REPO_ROOT}/public/v2/fui-as"
10
10
  DEMO_OUT_DIR="${OUT_DIR}/demo"
11
+ MVC_OUT_DIR="${OUT_DIR}/demo-mvc"
11
12
  HELLO_OUT_DIR="${OUT_DIR}/demo-hello-world"
12
13
  WORKER_BUILD_DIR="${PACKAGE_DIR}/build/workers"
13
14
  WORKER_BOOTSTRAP_BUILD="${PACKAGE_DIR}/build/worker-bootstrap.js"
@@ -23,7 +24,7 @@ RUNTIME_CONFIG_FILE="effindom-runtime-config.js"
23
24
  DEFAULT_MANIFEST_PATH="./runtime/dist/effindom.v2.manifest.json"
24
25
 
25
26
  rm -rf "${OUT_DIR}"
26
- mkdir -p "${PACKAGE_DIR}/build" "${OUT_DIR}" "${DEMO_OUT_DIR}" "${HELLO_OUT_DIR}" "${WORKER_BUILD_DIR}"
27
+ mkdir -p "${PACKAGE_DIR}/build" "${OUT_DIR}" "${DEMO_OUT_DIR}" "${MVC_OUT_DIR}" "${HELLO_OUT_DIR}" "${WORKER_BUILD_DIR}" "${PACKAGE_DIR}/templates/demo-mvc/src/host/generated" "${PACKAGE_DIR}/templates/demo-hello-world/src/host/generated"
27
28
 
28
29
  cd "${PACKAGE_DIR}"
29
30
 
@@ -64,6 +65,8 @@ generate_host_services() {
64
65
  local definition_file="$1"
65
66
  local export_name="$2"
66
67
  local output_file="$3"
68
+ local primitives_import="${4:-}"
69
+ local host_import_module="${5:-}"
67
70
 
68
71
  npx esbuild "${PACKAGE_DIR}/scripts/generate-host-services.ts" \
69
72
  --bundle \
@@ -73,13 +76,23 @@ generate_host_services() {
73
76
  --packages=external \
74
77
  --outfile="${HOST_SERVICE_GENERATOR_BUILD}"
75
78
 
76
- node "${HOST_SERVICE_GENERATOR_BUILD}" "${definition_file}" "${export_name}" "${output_file}"
79
+ if [ -n "${primitives_import}" ] && [ -n "${host_import_module}" ]; then
80
+ node "${HOST_SERVICE_GENERATOR_BUILD}" \
81
+ "${definition_file}" "${export_name}" "${output_file}" "${primitives_import}" "${host_import_module}"
82
+ elif [ -n "${primitives_import}" ]; then
83
+ node "${HOST_SERVICE_GENERATOR_BUILD}" "${definition_file}" "${export_name}" "${output_file}" "${primitives_import}"
84
+ elif [ -n "${host_import_module}" ]; then
85
+ node "${HOST_SERVICE_GENERATOR_BUILD}" "${definition_file}" "${export_name}" "${output_file}" "" "${host_import_module}"
86
+ else
87
+ node "${HOST_SERVICE_GENERATOR_BUILD}" "${definition_file}" "${export_name}" "${output_file}"
88
+ fi
77
89
  }
78
90
 
79
91
  generate_host_events() {
80
92
  local definition_file="$1"
81
93
  local export_name="$2"
82
94
  local output_file="$3"
95
+ local primitives_import="${4:-}"
83
96
 
84
97
  npx esbuild "${PACKAGE_DIR}/scripts/generate-host-events.ts" \
85
98
  --bundle \
@@ -89,7 +102,11 @@ generate_host_events() {
89
102
  --packages=external \
90
103
  --outfile="${HOST_EVENT_GENERATOR_BUILD}"
91
104
 
92
- node "${HOST_EVENT_GENERATOR_BUILD}" "${definition_file}" "${export_name}" "${output_file}"
105
+ if [ -n "${primitives_import}" ]; then
106
+ node "${HOST_EVENT_GENERATOR_BUILD}" "${definition_file}" "${export_name}" "${output_file}" "${primitives_import}"
107
+ else
108
+ node "${HOST_EVENT_GENERATOR_BUILD}" "${definition_file}" "${export_name}" "${output_file}"
109
+ fi
93
110
  }
94
111
 
95
112
  find_worker_entries() {
@@ -162,6 +179,10 @@ copy_runtime_assets() {
162
179
  cp "${RUNTIME_DIST_DIR}/icu-asset.json" "${destination}/runtime/dist/icu-asset.json"
163
180
  fi
164
181
  cp -R "${RUNTIME_DIST_DIR}/runtime" "${destination}/runtime/dist/runtime"
182
+ if [ -d "${RUNTIME_DIST_DIR}/fonts" ]; then
183
+ mkdir -p "${destination}/runtime"
184
+ cp -R "${RUNTIME_DIST_DIR}/fonts" "${destination}/runtime/fonts"
185
+ fi
165
186
  }
166
187
 
167
188
  build_workers() {
@@ -231,13 +252,20 @@ copy_worker_assets() {
231
252
  generate_host_services "demo/src/host-services.ts" "demoHostServices" "demo/src/generated/HostServices.ts"
232
253
  generate_host_events "demo/src/host-events.ts" "demoHostEvents" "demo/src/generated/HostEvents.ts"
233
254
  generate_host_services "demo/src/worker-host-services.ts" "demoWorkerHostServices" "demo/src/generated/WorkerHostServices.ts"
255
+ generate_host_services "scripts/framework-host-services.ts" "frameworkHostServices" "src/core/generated/FrameworkHostServices.ts" "" "fui_host"
256
+ generate_host_services "templates/demo-hello-world/src/host/host-services.ts" "appHostServices" "templates/demo-hello-world/src/host/generated/HostServices.ts" "../../fui/FuiPrimitives"
257
+ generate_host_events "templates/demo-hello-world/src/host/host-events.ts" "appHostEvents" "templates/demo-hello-world/src/host/generated/HostEvents.ts" "../../fui/FuiPrimitives"
258
+ generate_host_services "templates/demo-mvc/src/host/host-services.ts" "appHostServices" "templates/demo-mvc/src/host/generated/HostServices.ts" "../../fui/FuiPrimitives"
259
+ generate_host_events "templates/demo-mvc/src/host/host-events.ts" "appHostEvents" "templates/demo-mvc/src/host/generated/HostEvents.ts" "../../fui/FuiPrimitives"
234
260
 
235
261
  build_app "tests/fixtures/smoke/app.ts" "${OUT_DIR}/app.wasm"
236
262
  build_app "demo/src/dashboard.ts" "${DEMO_OUT_DIR}/demo.wasm"
237
263
  build_app "demo/src/routes/demo_home.ts" "${DEMO_OUT_DIR}/home.wasm"
238
264
  build_app "demo/src/routes/demo_advanced_controls.ts" "${DEMO_OUT_DIR}/advanced-controls.wasm"
239
265
  build_app "demo/src/routes/templated-controls.ts" "${DEMO_OUT_DIR}/templated-controls.wasm"
240
- build_app "demo-hello-world/src/App.ts" "${HELLO_OUT_DIR}/app.wasm"
266
+ build_app "templates/demo-mvc/src/routes/mvc_home.ts" "${MVC_OUT_DIR}/mvc-home.wasm"
267
+ build_app "templates/demo-mvc/src/routes/mvc_settings.ts" "${MVC_OUT_DIR}/mvc-settings.wasm"
268
+ build_app "templates/demo-hello-world/src/App.ts" "${HELLO_OUT_DIR}/app.wasm"
241
269
  build_workers
242
270
  write_worker_manifest
243
271
 
@@ -259,7 +287,16 @@ npx esbuild "${PACKAGE_DIR}/demo/harness.ts" \
259
287
  --outfile="${DEMO_OUT_DIR}/harness.js" \
260
288
  --sourcemap
261
289
 
262
- npx esbuild "${PACKAGE_DIR}/demo-hello-world/harness.ts" \
290
+ npx esbuild "${PACKAGE_DIR}/templates/demo-mvc/harness.ts" \
291
+ --bundle \
292
+ --format=esm \
293
+ --platform=browser \
294
+ --target=es2020 \
295
+ --minify \
296
+ --outfile="${MVC_OUT_DIR}/harness.js" \
297
+ --sourcemap
298
+
299
+ npx esbuild "${PACKAGE_DIR}/templates/demo-hello-world/harness.ts" \
263
300
  --bundle \
264
301
  --format=esm \
265
302
  --platform=browser \
@@ -281,6 +318,8 @@ cp "${FILE_PROCESSING_WORKER_BUILD}" "${OUT_DIR}/file-processing-worker.js"
281
318
  cp "${FILE_PROCESSING_WORKER_MAP_BUILD}" "${OUT_DIR}/file-processing-worker.js.map"
282
319
  cp "${FILE_PROCESSING_WORKER_BUILD}" "${DEMO_OUT_DIR}/file-processing-worker.js"
283
320
  cp "${FILE_PROCESSING_WORKER_MAP_BUILD}" "${DEMO_OUT_DIR}/file-processing-worker.js.map"
321
+ cp "${FILE_PROCESSING_WORKER_BUILD}" "${MVC_OUT_DIR}/file-processing-worker.js"
322
+ cp "${FILE_PROCESSING_WORKER_MAP_BUILD}" "${MVC_OUT_DIR}/file-processing-worker.js.map"
284
323
  cp "${FILE_PROCESSING_WORKER_BUILD}" "${HELLO_OUT_DIR}/file-processing-worker.js"
285
324
  cp "${FILE_PROCESSING_WORKER_MAP_BUILD}" "${HELLO_OUT_DIR}/file-processing-worker.js.map"
286
325
 
@@ -304,22 +343,43 @@ npx esbuild "${PACKAGE_DIR}/demo/worker-host-services.ts" \
304
343
 
305
344
  cp "${SMOKE_FIXTURE_DIR}/index.html" "${OUT_DIR}/index.html"
306
345
  cp "${PACKAGE_DIR}/demo/index.html" "${DEMO_OUT_DIR}/index.html"
307
- cp "${PACKAGE_DIR}/demo-hello-world/index.html" "${HELLO_OUT_DIR}/index.html"
346
+ cp "${PACKAGE_DIR}/templates/demo-hello-world/index.html" "${HELLO_OUT_DIR}/index.html"
308
347
  cp "${PACKAGE_DIR}/demo/demo-texture.png" "${DEMO_OUT_DIR}/demo-texture.png"
309
348
  cp "${PACKAGE_DIR}/demo/demo-secondary-texture.png" "${DEMO_OUT_DIR}/demo-secondary-texture.png"
310
349
 
311
350
  mkdir -p "${DEMO_OUT_DIR}/advanced-controls" "${DEMO_OUT_DIR}/templated-controls"
312
351
  cp "${PACKAGE_DIR}/demo/route-shell.html" "${DEMO_OUT_DIR}/advanced-controls/index.html"
313
352
  cp "${PACKAGE_DIR}/demo/route-shell.html" "${DEMO_OUT_DIR}/templated-controls/index.html"
353
+ mkdir -p "${MVC_OUT_DIR}/mvc-home" "${MVC_OUT_DIR}/mvc-settings"
354
+ cp "${PACKAGE_DIR}/templates/demo-mvc/route-shell.html" "${MVC_OUT_DIR}/mvc-home/index.html"
355
+ cp "${PACKAGE_DIR}/templates/demo-mvc/route-shell.html" "${MVC_OUT_DIR}/mvc-settings/index.html"
356
+ cat > "${MVC_OUT_DIR}/index.html" <<'EOF'
357
+ <!doctype html>
358
+ <html lang="en">
359
+ <head>
360
+ <meta charset="utf-8" />
361
+ <meta http-equiv="refresh" content="0; url=./mvc-home/" />
362
+ <title>FUI-AS MVC Demo</title>
363
+ </head>
364
+ <body>
365
+ <p>Redirecting to <a href="./mvc-home/">MVC Home</a>…</p>
366
+ </body>
367
+ </html>
368
+ EOF
314
369
 
315
370
  copy_runtime_assets "${OUT_DIR}"
316
371
  copy_runtime_assets "${DEMO_OUT_DIR}"
372
+ copy_runtime_assets "${MVC_OUT_DIR}"
317
373
  copy_runtime_assets "${HELLO_OUT_DIR}"
318
374
  copy_worker_assets "${OUT_DIR}"
319
375
  copy_worker_assets "${DEMO_OUT_DIR}"
376
+ copy_worker_assets "${MVC_OUT_DIR}"
320
377
  copy_worker_assets "${HELLO_OUT_DIR}"
321
378
  write_runtime_config "${OUT_DIR}" "${DEFAULT_MANIFEST_PATH}"
322
379
  write_runtime_config "${DEMO_OUT_DIR}" "${DEFAULT_MANIFEST_PATH}"
380
+ write_runtime_config "${MVC_OUT_DIR}" "${DEFAULT_MANIFEST_PATH}"
323
381
  write_runtime_config "${HELLO_OUT_DIR}" "${DEFAULT_MANIFEST_PATH}"
324
382
  write_runtime_config "${DEMO_OUT_DIR}/advanced-controls" "../runtime/dist/effindom.v2.manifest.json"
325
383
  write_runtime_config "${DEMO_OUT_DIR}/templated-controls" "../runtime/dist/effindom.v2.manifest.json"
384
+ write_runtime_config "${MVC_OUT_DIR}/mvc-home" "../runtime/dist/effindom.v2.manifest.json"
385
+ write_runtime_config "${MVC_OUT_DIR}/mvc-settings" "../runtime/dist/effindom.v2.manifest.json"
@@ -0,0 +1,40 @@
1
+ import { defineHostServices, hostService } from "../browser/src/host-services";
2
+
3
+ function unsupported(): never {
4
+ throw new Error("Framework host service definitions are generator metadata only.");
5
+ }
6
+
7
+ export const frameworkHostServices = defineHostServices({
8
+ frameworkHost: {
9
+ nowMs: hostService({
10
+ importName: "fui_now_ms",
11
+ args: [] as const,
12
+ returns: "f64",
13
+ implementation: () => unsupported(),
14
+ }),
15
+ isDarkMode: hostService({
16
+ importName: "fui_is_dark_mode",
17
+ args: [] as const,
18
+ returns: "bool",
19
+ implementation: () => unsupported(),
20
+ }),
21
+ accentColor: hostService({
22
+ importName: "fui_get_accent_color",
23
+ args: [] as const,
24
+ returns: "u32",
25
+ implementation: () => unsupported(),
26
+ }),
27
+ platformFamily: hostService({
28
+ importName: "fui_get_platform_family",
29
+ args: [] as const,
30
+ returns: "u32",
31
+ implementation: () => unsupported(),
32
+ }),
33
+ isCoarsePointer: hostService({
34
+ importName: "fui_is_coarse_pointer",
35
+ args: [] as const,
36
+ returns: "bool",
37
+ implementation: () => unsupported(),
38
+ }),
39
+ },
40
+ });
@@ -22,6 +22,11 @@ function relativeImport(fromFile: string, targetFile: string): string {
22
22
  return toPosix(relative);
23
23
  }
24
24
 
25
+ function sourcePathForHeader(sourceModulePath: string): string {
26
+ const relative = path.relative(process.cwd(), sourceModulePath);
27
+ return toPosix(relative.startsWith(".") ? relative : `./${relative}`);
28
+ }
29
+
25
30
  function asTypeName(type: HostServiceTypeName): string {
26
31
  switch (type) {
27
32
  case "string":
@@ -30,8 +35,26 @@ function asTypeName(type: HostServiceTypeName): string {
30
35
  return "bool";
31
36
  case "i32":
32
37
  return "i32";
38
+ case "u32":
39
+ return "u32";
40
+ case "i64":
41
+ return "i64";
42
+ case "u64":
43
+ return "u64";
33
44
  case "f64":
34
45
  return "f64";
46
+ case "bytes":
47
+ return "Uint8Array";
48
+ case "i32_array":
49
+ return "Int32Array";
50
+ case "u32_array":
51
+ return "Uint32Array";
52
+ case "i64_array":
53
+ return "Int64Array";
54
+ case "u64_array":
55
+ return "Uint64Array";
56
+ case "f64_array":
57
+ return "Float64Array";
35
58
  case "void":
36
59
  return "void";
37
60
  }
@@ -53,7 +76,15 @@ function callbackTypeFor(method: NormalizedHostEventMethod): string {
53
76
  function emitExportArgs(method: NormalizedHostEventMethod): string {
54
77
  const parts: Array<string> = [];
55
78
  method.args.forEach((type, index) => {
56
- if (type === "string") {
79
+ if (
80
+ type === "string" ||
81
+ type === "bytes" ||
82
+ type === "i32_array" ||
83
+ type === "u32_array" ||
84
+ type === "i64_array" ||
85
+ type === "u64_array" ||
86
+ type === "f64_array"
87
+ ) {
57
88
  parts.push(`arg${String(index)}Ptr: usize`, `arg${String(index)}Len: u32`);
58
89
  return;
59
90
  }
@@ -66,6 +97,47 @@ function emitDecodedArgs(method: NormalizedHostEventMethod): Array<string> {
66
97
  const lines: Array<string> = [];
67
98
  method.args.forEach((type, index) => {
68
99
  if (type !== "string") {
100
+ if (type === "bytes") {
101
+ lines.push(` const arg${String(index)} = new Uint8Array(<i32>arg${String(index)}Len);`);
102
+ lines.push(` if (arg${String(index)}Len > 0) {`);
103
+ lines.push(` memory.copy(arg${String(index)}.dataStart, arg${String(index)}Ptr, <usize>arg${String(index)}Len);`);
104
+ lines.push(" }");
105
+ return;
106
+ }
107
+ if (type === "i32_array") {
108
+ lines.push(` const arg${String(index)} = new Int32Array(<i32>arg${String(index)}Len);`);
109
+ lines.push(` if (arg${String(index)}Len > 0) {`);
110
+ lines.push(` memory.copy(arg${String(index)}.dataStart, arg${String(index)}Ptr, <usize>arg${String(index)}Len << 2);`);
111
+ lines.push(" }");
112
+ return;
113
+ }
114
+ if (type === "f64_array") {
115
+ lines.push(` const arg${String(index)} = new Float64Array(<i32>arg${String(index)}Len);`);
116
+ lines.push(` if (arg${String(index)}Len > 0) {`);
117
+ lines.push(` memory.copy(arg${String(index)}.dataStart, arg${String(index)}Ptr, <usize>arg${String(index)}Len << 3);`);
118
+ lines.push(" }");
119
+ return;
120
+ }
121
+ if (type === "u32_array") {
122
+ lines.push(` const arg${String(index)} = new Uint32Array(<i32>arg${String(index)}Len);`);
123
+ lines.push(` if (arg${String(index)}Len > 0) {`);
124
+ lines.push(` memory.copy(arg${String(index)}.dataStart, arg${String(index)}Ptr, <usize>arg${String(index)}Len << 2);`);
125
+ lines.push(" }");
126
+ return;
127
+ }
128
+ if (type === "i64_array") {
129
+ lines.push(` const arg${String(index)} = new Int64Array(<i32>arg${String(index)}Len);`);
130
+ lines.push(` if (arg${String(index)}Len > 0) {`);
131
+ lines.push(` memory.copy(arg${String(index)}.dataStart, arg${String(index)}Ptr, <usize>arg${String(index)}Len << 3);`);
132
+ lines.push(" }");
133
+ return;
134
+ }
135
+ if (type === "u64_array") {
136
+ lines.push(` const arg${String(index)} = new Uint64Array(<i32>arg${String(index)}Len);`);
137
+ lines.push(` if (arg${String(index)}Len > 0) {`);
138
+ lines.push(` memory.copy(arg${String(index)}.dataStart, arg${String(index)}Ptr, <usize>arg${String(index)}Len << 3);`);
139
+ lines.push(" }");
140
+ }
69
141
  return;
70
142
  }
71
143
  lines.push(
@@ -141,10 +213,11 @@ function emitBindingsFile(
141
213
  exportName: string,
142
214
  outputPath: string,
143
215
  methods: ReturnType<typeof listHostEventMethods>,
216
+ primitivesImportOverride: string | undefined,
144
217
  ): string {
145
- const callbackImport = relativeImport(outputPath, path.resolve(PACKAGE_DIR, "src/FuiPrimitives.ts"));
218
+ const callbackImport = primitivesImportOverride ?? relativeImport(outputPath, path.resolve(PACKAGE_DIR, "src/FuiPrimitives.ts"));
146
219
  const blocks: Array<string> = [
147
- `// Generated by scripts/generate-host-events.ts from ${toPosix(sourceModulePath)}#${exportName}.`,
220
+ `// Generated by scripts/generate-host-events.ts from ${sourcePathForHeader(sourceModulePath)}#${exportName}.`,
148
221
  `import { Callback0, Callback1, Callback2 } from "${callbackImport}";`,
149
222
  "",
150
223
  ];
@@ -159,15 +232,15 @@ function emitBindingsFile(
159
232
  }
160
233
 
161
234
  async function main(): Promise<void> {
162
- const [moduleArg, exportName, outputArg] = process.argv.slice(2);
235
+ const [moduleArg, exportName, outputArg, primitivesImportArg] = process.argv.slice(2);
163
236
  if (moduleArg === undefined || exportName === undefined || outputArg === undefined) {
164
- throw new Error("Usage: generate-host-events <module-path> <export-name> <output-path>");
237
+ throw new Error("Usage: generate-host-events <module-path> <export-name> <output-path> [primitives-import]");
165
238
  }
166
239
  const modulePath = path.resolve(process.cwd(), moduleArg);
167
240
  const outputPath = path.resolve(process.cwd(), outputArg);
168
241
  const registry = await loadHostEvents(modulePath, exportName);
169
242
  const methods = listHostEventMethods(registry as never);
170
- const content = emitBindingsFile(modulePath, exportName, outputPath, methods);
243
+ const content = emitBindingsFile(modulePath, exportName, outputPath, methods, primitivesImportArg);
171
244
  await fs.mkdir(path.dirname(outputPath), { recursive: true });
172
245
  await fs.writeFile(outputPath, content, "utf8");
173
246
  }