@thi.ng/wasm-api-bindgen 1.2.40 → 1.2.42

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 (3) hide show
  1. package/CHANGELOG.md +7 -1
  2. package/cli.js +89 -88
  3. package/package.json +3 -3
package/CHANGELOG.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # Change Log
2
2
 
3
- - **Last updated**: 2025-09-02T13:15:31Z
3
+ - **Last updated**: 2025-09-25T11:10:32Z
4
4
  - **Generator**: [thi.ng/monopub](https://thi.ng/monopub)
5
5
 
6
6
  All notable changes to this project will be documented in this file.
@@ -11,6 +11,12 @@ See [Conventional Commits](https://conventionalcommits.org/) for commit guidelin
11
11
  **Note:** Unlisted _patch_ versions only involve non-code or otherwise excluded changes
12
12
  and/or version bumps of transitive dependencies.
13
13
 
14
+ ### [1.2.42](https://github.com/thi-ng/umbrella/tree/@thi.ng/wasm-api-bindgen@1.2.42) (2025-09-25)
15
+
16
+ #### ♻️ Refactoring
17
+
18
+ - simplify CLI impl via cliApp() wrapper ([f0ca0a9](https://github.com/thi-ng/umbrella/commit/f0ca0a9))
19
+
14
20
  ### [1.2.40](https://github.com/thi-ng/umbrella/tree/@thi.ng/wasm-api-bindgen@1.2.40) (2025-09-02)
15
21
 
16
22
  #### 🩹 Bug fixes
package/cli.js CHANGED
@@ -1,19 +1,17 @@
1
1
  import {
2
2
  ARG_DRY_RUN,
3
- ParseError,
4
3
  THING_HEADER,
4
+ cliApp,
5
+ configureLogLevel,
5
6
  flag,
6
7
  oneOf,
7
8
  oneOfMulti,
8
- parse,
9
9
  string,
10
- strings,
11
- usage
10
+ strings
12
11
  } from "@thi.ng/args";
13
12
  import { isArray, isPlainObject, isString } from "@thi.ng/checks";
14
13
  import { illegalArgs } from "@thi.ng/errors";
15
14
  import { readJSON, readText, writeJSON, writeText } from "@thi.ng/file-io";
16
- import { ConsoleLogger } from "@thi.ng/logger";
17
15
  import { mutIn } from "@thi.ng/paths";
18
16
  import { dirname, join, resolve } from "node:path";
19
17
  import { C11 } from "./c11.js";
@@ -29,36 +27,6 @@ import {
29
27
  import { TYPESCRIPT } from "./typescript.js";
30
28
  import { ZIG } from "./zig.js";
31
29
  const GENERATORS = { c11: C11, ts: TYPESCRIPT, zig: ZIG };
32
- const argOpts = {
33
- ...ARG_DRY_RUN,
34
- analytics: string({
35
- alias: "a",
36
- hint: "FILE",
37
- desc: "output file path for raw codegen analytics"
38
- }),
39
- config: string({
40
- alias: "c",
41
- hint: "FILE",
42
- desc: "JSON config file with codegen options"
43
- }),
44
- debug: flag({
45
- alias: "d",
46
- default: false,
47
- desc: "enable debug output & functions"
48
- }),
49
- lang: oneOfMulti(Object.keys(GENERATORS), {
50
- alias: "l",
51
- desc: "target language",
52
- default: ["ts", "zig"],
53
- delim: ","
54
- }),
55
- out: strings({ alias: "o", hint: "FILE", desc: "output file path" }),
56
- string: oneOf(["slice", "ptr"], {
57
- alias: "s",
58
- hint: "TYPE",
59
- desc: "Force string type implementation"
60
- })
61
- };
62
30
  const PKG = readJSON(join(process.argv[2], "package.json"));
63
31
  const APP_NAME = PKG.name.split("/")[1];
64
32
  const HEADER = THING_HEADER(
@@ -66,21 +34,6 @@ const HEADER = THING_HEADER(
66
34
  PKG.version,
67
35
  "Multi-language data bindings code generator"
68
36
  );
69
- const usageOpts = {
70
- lineWidth: process.stdout.columns,
71
- prefix: `${HEADER}
72
-
73
- usage: ${APP_NAME} [OPTS] JSON-INPUT-FILE(S) ...
74
- ${APP_NAME} --help
75
-
76
- `,
77
- showGroupNames: true,
78
- paramWidth: 32
79
- };
80
- const showUsage = () => {
81
- process.stderr.write(usage(argOpts, usageOpts));
82
- process.exit(1);
83
- };
84
37
  const invalidSpec = (path, msg) => {
85
38
  throw new Error(`invalid typedef: ${path}${msg ? ` (${msg})` : ""}`);
86
39
  };
@@ -165,47 +118,95 @@ const resolveUserCode = (ctx, conf, key) => {
165
118
  }
166
119
  }
167
120
  };
168
- try {
169
- const result = parse(argOpts, process.argv, { start: 3, usageOpts });
170
- if (!result) process.exit(1);
171
- const { result: opts, rest } = result;
172
- if (!rest.length) showUsage();
173
- if (opts.out && opts.lang.length != opts.out.length) {
174
- illegalArgs(
175
- `expected ${opts.lang.length} outputs, but got ${opts.out.length}`
176
- );
177
- }
178
- const ctx = {
179
- logger: new ConsoleLogger("wasm-api", opts.debug ? "DEBUG" : "INFO"),
180
- config: { global: {} },
181
- opts
182
- };
183
- if (opts.config) {
184
- opts.config = resolve(opts.config);
185
- ctx.config = readJSON(opts.config, ctx.logger);
186
- for (let id in ctx.config) {
187
- const conf = ctx.config[id];
188
- resolveUserCode(ctx, conf, "pre");
189
- resolveUserCode(ctx, conf, "post");
121
+ const CMD = {
122
+ desc: "",
123
+ opts: {},
124
+ inputs: [1, Infinity],
125
+ fn: async ({ opts, inputs, logger }) => {
126
+ if (opts.out && opts.lang.length !== opts.out.length) {
127
+ illegalArgs(
128
+ `expected ${opts.lang.length} outputs, but got ${opts.out.length}`
129
+ );
130
+ }
131
+ const ctx = {
132
+ logger,
133
+ config: { global: {} },
134
+ opts
135
+ };
136
+ if (opts.config) {
137
+ opts.config = resolve(opts.config);
138
+ ctx.config = readJSON(opts.config, ctx.logger);
139
+ for (let id in ctx.config) {
140
+ const conf = ctx.config[id];
141
+ resolveUserCode(ctx, conf, "pre");
142
+ resolveUserCode(ctx, conf, "post");
143
+ }
144
+ }
145
+ opts.debug && mutIn(ctx, ["config", "global", "debug"], true);
146
+ opts.string && mutIn(ctx, ["config", "global", "stringType"], opts.string);
147
+ const types = parseTypeSpecs(ctx, inputs);
148
+ generateOutputs(ctx, types);
149
+ if (ctx.opts.analytics) {
150
+ writeJSON(
151
+ resolve(ctx.opts.analytics),
152
+ types,
153
+ void 0,
154
+ " ",
155
+ ctx.logger
156
+ );
190
157
  }
191
158
  }
192
- opts.debug && mutIn(ctx, ["config", "global", "debug"], true);
193
- opts.string && mutIn(ctx, ["config", "global", "stringType"], opts.string);
194
- const types = parseTypeSpecs(ctx, rest);
195
- generateOutputs(ctx, types);
196
- if (ctx.opts.analytics) {
197
- writeJSON(
198
- resolve(ctx.opts.analytics),
199
- types,
200
- void 0,
201
- " ",
202
- ctx.logger
203
- );
159
+ };
160
+ cliApp({
161
+ name: APP_NAME,
162
+ start: 3,
163
+ opts: {
164
+ ...ARG_DRY_RUN,
165
+ analytics: string({
166
+ alias: "a",
167
+ hint: "FILE",
168
+ desc: "output file path for raw codegen analytics"
169
+ }),
170
+ config: string({
171
+ alias: "c",
172
+ hint: "FILE",
173
+ desc: "JSON config file with codegen options"
174
+ }),
175
+ debug: flag({
176
+ alias: "d",
177
+ default: false,
178
+ desc: "enable debug output & functions"
179
+ }),
180
+ lang: oneOfMulti(Object.keys(GENERATORS), {
181
+ alias: "l",
182
+ desc: "target language",
183
+ default: ["ts", "zig"],
184
+ delim: ","
185
+ }),
186
+ out: strings({ alias: "o", hint: "FILE", desc: "output file path" }),
187
+ string: oneOf(["slice", "ptr"], {
188
+ alias: "s",
189
+ hint: "TYPE",
190
+ desc: "Force string type implementation"
191
+ })
192
+ },
193
+ commands: { CMD },
194
+ single: true,
195
+ usage: {
196
+ lineWidth: process.stdout.columns,
197
+ prefix: `${HEADER}
198
+
199
+ usage: ${APP_NAME} [OPTS] JSON-INPUT-FILE(S) ...
200
+ ${APP_NAME} --help
201
+ `,
202
+ showGroupNames: true,
203
+ paramWidth: 32
204
+ },
205
+ ctx: async (ctx) => {
206
+ configureLogLevel(ctx.logger, ctx.opts.debug);
207
+ return ctx;
204
208
  }
205
- } catch (e) {
206
- if (!(e instanceof ParseError)) process.stderr.write(e.message);
207
- process.exit(1);
208
- }
209
+ });
209
210
  export {
210
211
  APP_NAME,
211
212
  HEADER,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@thi.ng/wasm-api-bindgen",
3
- "version": "1.2.40",
3
+ "version": "1.2.42",
4
4
  "description": "Polyglot bindings code generators (TS/JS, Zig, C11) for hybrid WebAssembly projects",
5
5
  "type": "module",
6
6
  "module": "./index.js",
@@ -42,7 +42,7 @@
42
42
  },
43
43
  "dependencies": {
44
44
  "@thi.ng/api": "^8.12.2",
45
- "@thi.ng/args": "^2.9.3",
45
+ "@thi.ng/args": "^2.10.1",
46
46
  "@thi.ng/arrays": "^2.13.11",
47
47
  "@thi.ng/binary": "^3.4.60",
48
48
  "@thi.ng/checks": "^3.7.18",
@@ -128,5 +128,5 @@
128
128
  "tag": "wasm",
129
129
  "year": 2022
130
130
  },
131
- "gitHead": "4ebea5f30d4e2d28a12dfb01b39533fdfda0ab43\n"
131
+ "gitHead": "b7ede4f099767e0175ea8e09257208f73970b220\n"
132
132
  }