@microsoft/dynwinrt-codegen 0.1.0-preview.1 → 0.1.0-preview.2

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/README.md ADDED
@@ -0,0 +1,87 @@
1
+ # @microsoft/dynwinrt-codegen
2
+
3
+ **Generate typed JavaScript + TypeScript bindings for any Windows Runtime (WinRT) API from `.winmd` metadata.**
4
+
5
+ Pair this with the [`@microsoft/dynwinrt`](https://www.npmjs.com/package/@microsoft/dynwinrt) runtime to call modern Windows APIs (WinAppSDK, Windows AI, notifications, storage, networking, …) **directly from JavaScript / TypeScript** — full IntelliSense, no native build step, no C# projection, no per-Windows-version recompile.
6
+
7
+ ## Why use this?
8
+
9
+ Until now, the choices for calling a Windows API from Node.js or Electron were:
10
+
11
+ - **Write a C++ `node-addon-api` addon** — needs `node-gyp`, MSVC, Python, the right Windows SDK, and a CI matrix per Electron version.
12
+ - **Write a C# addon via `node-api-dotnet`** — needs the .NET SDK, a `csproj` build step, and a hand-maintained C# wrapper for every API surface.
13
+ - **Wait for an official projection** — Windows ships `.winmd` metadata months before a JavaScript-friendly projection appears.
14
+
15
+ `dynwinrt-codegen` reads the same `.winmd` metadata the Windows SDK already ships and emits **typed JavaScript + `.d.ts` wrappers** that call WinRT through [`@microsoft/dynwinrt`](https://www.npmjs.com/package/@microsoft/dynwinrt) at runtime. There is no native build in your Electron / Node project. You generate the bindings once, commit them (or regenerate on demand), and import them like any other module:
16
+
17
+ ```ts
18
+ import { LanguageModel, LanguageModelOptions } from './bindings/winrt';
19
+ const model = await LanguageModel.createAsync();
20
+ ```
21
+
22
+ You get IntelliSense in your IDE, type errors at `tsc` time, and the underlying COM call dispatched dynamically at runtime — no MSBuild involved.
23
+
24
+ The trade-off: `dynwinrt-codegen` is designed for **data-style WinRT APIs** (AI, storage, notifications, networking, globalization, …) and skips XAML / WinUI namespaces, which need composable-class aggregation patterns the codegen doesn't implement. For everything else, this is the easiest path from JavaScript to native Windows.
25
+
26
+ ## CLI usage
27
+
28
+ ```bash
29
+ npm install -D @microsoft/dynwinrt-codegen @microsoft/dynwinrt
30
+
31
+ # A single class (auto-detects the Windows SDK winmd)
32
+ npx dynwinrt-codegen generate \
33
+ --namespace Windows.Foundation \
34
+ --class-name Uri \
35
+ --output ./generated
36
+
37
+ # An entire namespace
38
+ npx dynwinrt-codegen generate \
39
+ --namespace Windows.Web.Http \
40
+ --output ./generated
41
+
42
+ # A custom .winmd (e.g., a WinAppSDK NuGet package or your own SDK)
43
+ npx dynwinrt-codegen generate \
44
+ --winmd "C:\path\to\Microsoft.WindowsAppSDK.AI.winmd" \
45
+ --output ./generated
46
+ ```
47
+
48
+ ### Flags
49
+
50
+ | Flag | Description |
51
+ |---|---|
52
+ | `--winmd PATH[;PATH...]` | Path to `.winmd` file(s) (auto-detects Windows SDK if omitted) |
53
+ | `--folder PATH` | Directory containing `.winmd` files |
54
+ | `--namespace NAMESPACE` | WinRT namespace to generate (omit for all non-`Windows.*` namespaces) |
55
+ | `--class-name CLASS` | Specific class (transitively pulls in dependencies) |
56
+ | `--ref PATH` | Additional `.winmd` files for type resolution only (no code emitted) |
57
+ | `--lang js` | Target language (currently `js` only) |
58
+ | `--output DIR` | Output directory (default `./generated`) |
59
+ | `--dry-run` | Validate input, don't write files |
60
+
61
+ ## What gets generated
62
+
63
+ For each WinRT class, the codegen emits:
64
+
65
+ - **A typed wrapper class** with properties and methods using camelCase JS conventions
66
+ - **A factory** (`.create(...)`, `.createInstance(...)`) for activation
67
+ - **An interface registration** (`DynWinRtType.registerInterface()`) wired to the COM vtable
68
+ - **`IAsyncOperation<T>` awaitables** with `.progress(cb)` for streaming results
69
+ - **Generic collections** (`IVector<T>`, `IMap<K,V>`, `IIterable<T>`)
70
+ - **Structs** with `pack`/`unpack` helpers
71
+ - **Enums** (`Object.freeze`'d in JS, `enum` in `.d.ts`)
72
+ - **Delegate types** (IID + parameter signatures) for event handlers
73
+ - **An `index.js` + `index.d.ts`** re-exporting every emitted symbol from one place
74
+
75
+ ## Platform
76
+
77
+ - **Windows only** (x64 / arm64) — the binary is built per architecture and selected automatically by the npm install
78
+ - The generated bindings depend on [`@microsoft/dynwinrt`](https://www.npmjs.com/package/@microsoft/dynwinrt) at runtime
79
+
80
+ ## Links
81
+
82
+ - 📦 [`@microsoft/dynwinrt`](https://www.npmjs.com/package/@microsoft/dynwinrt) — the runtime the generated code targets
83
+ - 🐛 [Source on GitHub](https://github.com/microsoft/dynwinrt) — issues, contributions, internal design docs
84
+
85
+ ## License
86
+
87
+ [MIT](https://github.com/microsoft/dynwinrt/blob/main/LICENSE)
Binary file
Binary file
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@microsoft/dynwinrt-codegen",
3
- "version": "0.1.0-preview.1",
3
+ "version": "0.1.0-preview.2",
4
4
  "description": "Generate typed bindings from WinRT metadata (.winmd) files for use with @microsoft/dynwinrt",
5
5
  "license": "MIT",
6
6
  "repository": {
@@ -24,7 +24,8 @@
24
24
  "files": [
25
25
  "bin/",
26
26
  "cli.js",
27
- "LICENSE"
27
+ "LICENSE",
28
+ "README.md"
28
29
  ],
29
30
  "dependencies": {
30
31