@cordy/electro-generator 1.2.4 → 1.2.6

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 (2) hide show
  1. package/dist/index.mjs +14 -0
  2. package/package.json +3 -3
package/dist/index.mjs CHANGED
@@ -48,6 +48,14 @@ function generatePreload(viewName, features, policy, preloadExtension) {
48
48
  }
49
49
  featureEntries.push(` ${q(feature.id)}: {\n${serviceEntries.join("\n")}\n },`);
50
50
  }
51
+ if (allowedFeatures.length > 0) featureEntries.push(` events: {
52
+ on: (channel: string, handler: (...args: unknown[]) => void) => {
53
+ const ipcChannel = \`electro:event:\${channel}\`;
54
+ const listener = (_event: unknown, payload: unknown) => handler(payload);
55
+ ipcRenderer.on(ipcChannel, listener);
56
+ return () => { ipcRenderer.removeListener(ipcChannel, listener); };
57
+ },
58
+ },`);
51
59
  let content = `${HEADER}
52
60
  import { contextBridge, ipcRenderer } from "electron";
53
61
 
@@ -83,6 +91,12 @@ function generateBridgeTypes(viewName, features, policy) {
83
91
  }
84
92
  featureTypes.push(` ${q(feature.id)}: {\n${serviceTypes.join("\n")}\n };`);
85
93
  }
94
+ const eventKeys = [];
95
+ for (const feature of allowedFeatures) for (const evt of feature.events ?? []) eventKeys.push(`"${feature.id}:${evt.id}"`);
96
+ if (allowedFeatures.length > 0) {
97
+ const channelType = eventKeys.length > 0 ? eventKeys.join(" | ") : "string";
98
+ featureTypes.push(` events: {\n on(channel: ${channelType} | (string & {}), handler: (payload: unknown) => void): () => void;\n };`);
99
+ }
86
100
  const content = `${HEADER}
87
101
  export interface ElectroBridge ${featureTypes.length > 0 ? `{\n${featureTypes.join("\n")}\n }` : "{}"}
88
102
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cordy/electro-generator",
3
- "version": "1.2.4",
3
+ "version": "1.2.6",
4
4
  "description": "Code generator for @cordy/electro — scans features and emits preload scripts and bridge types",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -44,14 +44,14 @@
44
44
  "prepublishOnly": "bun run build"
45
45
  },
46
46
  "peerDependencies": {
47
- "@cordy/electro": "1.2.4"
47
+ "@cordy/electro": "1.2.6"
48
48
  },
49
49
  "dependencies": {
50
50
  "oxc-parser": "^0.114.0",
51
51
  "tinyglobby": "^0.2.15"
52
52
  },
53
53
  "devDependencies": {
54
- "@cordy/electro": "1.2.4",
54
+ "@cordy/electro": "1.2.6",
55
55
  "tsdown": "^0.20.3",
56
56
  "vitest": "v4.1.0-beta.3"
57
57
  }