@niyamulahsan/create-deskapp 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 (104) hide show
  1. package/package.json +16 -16
  2. package/template/.env.example +20 -13
  3. package/template/AGENTS.md +699 -0
  4. package/template/package.json +3 -0
  5. package/template/src/config/app.ts +26 -24
  6. package/template/src/config/winsetup.ts +93 -91
  7. package/template/src/core/api/binding-error.ts +57 -0
  8. package/template/src/core/api/bindings.generated.ts +2 -0
  9. package/template/src/core/api/generate.manifest.ts +84 -80
  10. package/template/src/core/api/registry.ts +58 -48
  11. package/template/src/core/config.ts +101 -99
  12. package/template/src/core/database/aggregate.ts +89 -85
  13. package/template/src/core/database/config.ts +50 -48
  14. package/template/src/core/database/connection.ts +116 -114
  15. package/template/src/core/database/migrate-hooks.ts +86 -84
  16. package/template/src/core/database/paginate.ts +226 -224
  17. package/template/src/core/database/reset.ts +21 -19
  18. package/template/src/core/database/seed.ts +169 -167
  19. package/template/src/core/database/status.ts +37 -35
  20. package/template/src/core/env.ts +108 -106
  21. package/template/src/core/facade.ts +63 -61
  22. package/template/src/core/maker/db/fresh.ts +10 -8
  23. package/template/src/core/maker/db/generate.ts +13 -11
  24. package/template/src/core/maker/db/helpers.ts +92 -96
  25. package/template/src/core/maker/db/migrate.ts +37 -35
  26. package/template/src/core/maker/db/mod.ts +93 -91
  27. package/template/src/core/maker/db/module-migrate.ts +56 -54
  28. package/template/src/core/maker/db/push.ts +23 -21
  29. package/template/src/core/maker/db/reset.ts +8 -6
  30. package/template/src/core/maker/db/seed.ts +9 -7
  31. package/template/src/core/maker/db/status.ts +8 -6
  32. package/template/src/core/maker/help.ts +59 -57
  33. package/template/src/core/maker/make/controller.ts +25 -22
  34. package/template/src/core/maker/make/helpers.ts +97 -91
  35. package/template/src/core/maker/make/mod.ts +69 -67
  36. package/template/src/core/maker/make/model.ts +16 -14
  37. package/template/src/core/maker/make/module.ts +53 -39
  38. package/template/src/core/maker/make/seeder.ts +23 -21
  39. package/template/src/core/maker/make/test.ts +33 -30
  40. package/template/src/core/maker/mod.ts +85 -83
  41. package/template/src/core/maker/run/mod.ts +134 -132
  42. package/template/src/core/maker/stub.ts +26 -24
  43. package/template/src/core/maker/stubs/controller/controller.controller.stub +57 -55
  44. package/template/src/core/maker/stubs/controller/controller.schema.stub +18 -13
  45. package/template/src/core/maker/stubs/facade/facade.stub +21 -0
  46. package/template/src/core/maker/stubs/model/model.stub +10 -8
  47. package/template/src/core/maker/stubs/seeder/seeder.stub +18 -16
  48. package/template/src/core/maker/stubs/test/test.stub +9 -7
  49. package/template/src/core/maker/sync-config.ts +93 -94
  50. package/template/src/core/utils/password.ts +29 -27
  51. package/template/src/core/utils/playwright.ts +123 -121
  52. package/template/src/core/utils/queue.ts +68 -66
  53. package/template/src/core/utils/scheduler.ts +62 -60
  54. package/template/src/core/utils/storage.ts +3 -1
  55. package/template/src/core/utils/validation.ts +37 -35
  56. package/template/src/database/schema.ts +2 -0
  57. package/template/src/main.ts +120 -118
  58. package/template/src/modules/app/__tests__/demo.controller.test.ts +75 -0
  59. package/template/src/modules/app/__tests__/net.controller.test.ts +65 -0
  60. package/template/src/modules/app/__tests__/playwright.controller.test.ts +50 -0
  61. package/template/src/modules/app/__tests__/storage.controller.test.ts +114 -0
  62. package/template/src/modules/app/__tests__/window.controller.test.ts +98 -0
  63. package/template/src/modules/app/controllers/demo.controller.ts +120 -118
  64. package/template/src/modules/app/controllers/net.controller.ts +50 -48
  65. package/template/src/modules/app/controllers/playwright.controller.ts +142 -140
  66. package/template/src/modules/app/controllers/storage.controller.ts +231 -229
  67. package/template/src/modules/app/controllers/window.controller.ts +2 -0
  68. package/template/src/modules/app/facade.ts +21 -0
  69. package/template/src/preload.ts +25 -2
  70. package/template/src/ui/src/App.vue +4 -2
  71. package/template/src/ui/src/app.ts +38 -23
  72. package/template/src/ui/src/bindings.d.ts +18 -16
  73. package/template/src/ui/src/components/Button.vue +34 -32
  74. package/template/src/ui/src/components/Checkbox.vue +26 -29
  75. package/template/src/ui/src/components/Input.vue +221 -227
  76. package/template/src/ui/src/components/InputGroup.vue +141 -0
  77. package/template/src/ui/src/components/InputPasswordToggle.vue +204 -0
  78. package/template/src/ui/src/components/Modal.vue +65 -55
  79. package/template/src/ui/src/components/Spinner.vue +44 -42
  80. package/template/src/ui/src/components/Switch.vue +62 -65
  81. package/template/src/ui/src/components/TextArea.vue +108 -121
  82. package/template/src/ui/src/components/Toast.vue +55 -56
  83. package/template/src/ui/src/components/datatable/DataTableSkeleton.vue +100 -98
  84. package/template/src/ui/src/components/datatable/Pagination.vue +153 -125
  85. package/template/src/ui/src/components/datatable/SelectOpption.vue +36 -35
  86. package/template/src/ui/src/components/datatable/index.vue +336 -258
  87. package/template/src/ui/src/env.d.ts +16 -13
  88. package/template/src/ui/src/global.d.ts +21 -2
  89. package/template/src/ui/src/helpers/nformatter.ts +12 -10
  90. package/template/src/ui/src/pages/dashboard/index.vue +690 -687
  91. package/template/src/ui/src/plugins/browserDetect.ts +57 -0
  92. package/template/src/ui/src/plugins/gum.ts +576 -549
  93. package/template/src/ui/src/plugins/pulse.ts +181 -147
  94. package/template/src/ui/src/plugins/routeProgress.ts +89 -0
  95. package/template/src/ui/src/router/index.ts +44 -25
  96. package/template/src/ui/src/stores/example.ts +2 -0
  97. package/template/src/ui/vite.config.ts +40 -38
  98. package/template/src/window/app-menu.ts +89 -87
  99. package/template/src/window/config.ts +14 -12
  100. package/template/src/window/context-menu.ts +23 -21
  101. package/template/src/window/dialogs.ts +92 -90
  102. package/template/src/window/manager.ts +2 -0
  103. package/template/src/window/native.ts +47 -45
  104. package/template/src/window/tray.ts +132 -130
@@ -23,6 +23,7 @@
23
23
  "lint:fix": "biome check --write .",
24
24
  "format": "biome format --write .",
25
25
  "format:check": "biome format .",
26
+ "typecheck": "tsc --noEmit -p tsconfig.json && tsc --noEmit -p src/ui/tsconfig.json",
26
27
  "test": "vitest run",
27
28
  "test:watch": "vitest",
28
29
  "test:coverage": "vitest run --coverage"
@@ -40,7 +41,9 @@
40
41
  },
41
42
  "devDependencies": {
42
43
  "@biomejs/biome": "^2.5.7",
44
+ "@types/bootstrap": "^5.2.11",
43
45
  "@types/node": "^22.20.5",
46
+ "@unhead/vue": "^3.4.3",
44
47
  "@vitejs/plugin-vue": "^6.0.8",
45
48
  "@vitest/coverage-v8": "^5.1.0",
46
49
  "bootstrap": "^5.3.8",
@@ -1,24 +1,26 @@
1
- /**
2
- * App identity config — edit this file to name/brand your app (0 hassle).
3
- * After changing, run: `npm run config:sync` (or `npm run maker -- config:sync`)
4
- * to update package.json + NSIS installer fields. Runtime config also reads from here.
5
- *
6
- * You can add more config files in this folder later (e.g. database.ts, window.ts)
7
- * and export them from here or import directly.
8
- */
9
- export const appConfig = {
10
- /** npm package name (kebab-case) */
11
- name: "deskapp",
12
- /** Display / product name (installer name, app title, shortcuts) */
13
- productName: "Deskapp",
14
- /** Short description */
15
- description: "Deskapp - Electron desktop app framework",
16
- /** Unique app/protocol identifier (reverse-domain style) */
17
- appId: "com.deskapp.app",
18
- /** Deep-link/protocol scheme (lowercase, no spaces) */
19
- protocol: "deskapp",
20
- /** Folders used by the NSIS "Full uninstall" option (user data). Keep in sync with actual storage/userData names. */
21
- uninstallDataFolders: ["Deskapp", "deskapp", "com.deskapp.app"],
22
- } as const;
23
-
24
- export type AppConfig = typeof appConfig;
1
+ // ./src/config/app.ts
2
+
3
+ /**
4
+ * App identity config — edit this file to name/brand your app (0 hassle).
5
+ * After changing, run: `npm run config:sync` (or `npm run maker -- config:sync`)
6
+ * to update package.json + NSIS installer fields. Runtime config also reads from here.
7
+ *
8
+ * You can add more config files in this folder later (e.g. database.ts, window.ts)
9
+ * and export them from here or import directly.
10
+ */
11
+ export const appConfig = {
12
+ /** npm package name (kebab-case) */
13
+ name: "deskapp",
14
+ /** Display / product name (installer name, app title, shortcuts) */
15
+ productName: "Deskapp",
16
+ /** Short description */
17
+ description: "Deskapp - Electron desktop app framework",
18
+ /** Unique app/protocol identifier (reverse-domain style) */
19
+ appId: "com.deskapp.app",
20
+ /** Deep-link/protocol scheme (lowercase, no spaces) */
21
+ protocol: "deskapp",
22
+ /** Folders used by the NSIS "Full uninstall" option (user data). Keep in sync with actual storage/userData names. */
23
+ uninstallDataFolders: ["Deskapp", "deskapp", "com.deskapp.app"]
24
+ } as const;
25
+
26
+ export type AppConfig = typeof appConfig;
@@ -1,91 +1,93 @@
1
- /**
2
- * Window setup/config — edit this file to configure app windows (0 hassle).
3
- * Each entry in `windows` becomes a native BrowserWindow at boot.
4
- * The first entry ("main") is the primary window.
5
- *
6
- * For runtime windows (opened on demand), pass a `WindowPreset` to `win.openWindow()`.
7
- */
8
-
9
- import { config } from "@/core/config";
10
-
11
- export type DevToolsMode = "bottom" | "right" | "left" | "undocked" | "detach";
12
-
13
- export const windowDev = {
14
- /**
15
- * Auto-open DevTools in development only (never in production/packaged).
16
- * Set mode: "bottom" | "right" | "left" | "undocked" | "detach", or "none" to disable.
17
- */
18
- devTools: "bottom" as DevToolsMode | "none"
19
- };
20
-
21
- export interface ChromeParts {
22
- /** Application/window menu. */
23
- appMenu?: boolean;
24
- /** Right-click context menu. */
25
- contextMenu?: boolean;
26
- /** System tray icon/menu (windowed). */
27
- tray?: boolean;
28
- }
29
-
30
- export interface WindowPreset {
31
- /** Window title. Falls back to the app name if unset. */
32
- title: string;
33
- /** Initial width in logical pixels. */
34
- width: number;
35
- /** Initial height in logical pixels. */
36
- height: number;
37
- /** Initial horizontal position; centered if omitted. */
38
- x?: number;
39
- /** Initial vertical position; centered if omitted. */
40
- y?: number;
41
- /** Whether the user can resize the window. */
42
- resizable?: boolean;
43
- /** Keep the window above others. */
44
- alwaysOnTop?: boolean;
45
- /** Remove the title bar and window chrome (creation-only). */
46
- frameless?: boolean;
47
- /** Floating, non-activating panel that doesn't steal focus (creation-only). */
48
- noActivate?: boolean;
49
- /** Blend the title bar into the content (creation-only). */
50
- transparentTitlebar?: boolean;
51
- /** In-app path the window loads on startup (frontend route). */
52
- route?: string;
53
- /**
54
- * Desktop chrome for the FIRST (main) boot window only.
55
- * - `true` / omitted: app menu + context menu + tray (default)
56
- * - `false`: none
57
- * - object: granular control, e.g. `{ appMenu: true, contextMenu: true, tray: false }`
58
- * (omitted parts default to `false` when an object is provided)
59
- */
60
- chrome?: boolean | ChromeParts;
61
- }
62
-
63
- /** Normalize chrome config to explicit part flags. */
64
- export function resolveChrome(chrome: WindowPreset["chrome"]): Required<ChromeParts> {
65
- if (chrome === false) return { appMenu: false, contextMenu: false, tray: false };
66
- if (chrome === true || chrome === undefined) return { appMenu: true, contextMenu: true, tray: true };
67
- return {
68
- appMenu: !!chrome.appMenu,
69
- contextMenu: !!chrome.contextMenu,
70
- tray: !!chrome.tray
71
- };
72
- }
73
-
74
- /**
75
- * Named window presets. Only these open at boot. The "main" entry is always
76
- * created first; every extra entry also opens as a fresh window at startup.
77
- */
78
- export const windows: Record<string, WindowPreset> = {
79
- main: {
80
- title: config.appName,
81
- width: 900,
82
- height: 600,
83
- resizable: true,
84
- alwaysOnTop: false,
85
- route: "/",
86
- chrome: true
87
- }
88
- };
89
-
90
- /** The main (first-created) window preset. */
91
- export const windowConfig: WindowPreset = windows.main;
1
+ // ./src/config/winsetup.ts
2
+
3
+ /**
4
+ * Window setup/config — edit this file to configure app windows (0 hassle).
5
+ * Each entry in `windows` becomes a native BrowserWindow at boot.
6
+ * The first entry ("main") is the primary window.
7
+ *
8
+ * For runtime windows (opened on demand), pass a `WindowPreset` to `win.openWindow()`.
9
+ */
10
+
11
+ import { config } from "@/core/config";
12
+
13
+ export type DevToolsMode = "bottom" | "right" | "left" | "undocked" | "detach";
14
+
15
+ export const windowDev = {
16
+ /**
17
+ * Auto-open DevTools in development only (never in production/packaged).
18
+ * Set mode: "bottom" | "right" | "left" | "undocked" | "detach", or "none" to disable.
19
+ */
20
+ devTools: "bottom" as DevToolsMode | "none"
21
+ };
22
+
23
+ export interface ChromeParts {
24
+ /** Application/window menu. */
25
+ appMenu?: boolean;
26
+ /** Right-click context menu. */
27
+ contextMenu?: boolean;
28
+ /** System tray icon/menu (windowed). */
29
+ tray?: boolean;
30
+ }
31
+
32
+ export interface WindowPreset {
33
+ /** Window title. Falls back to the app name if unset. */
34
+ title: string;
35
+ /** Initial width in logical pixels. */
36
+ width: number;
37
+ /** Initial height in logical pixels. */
38
+ height: number;
39
+ /** Initial horizontal position; centered if omitted. */
40
+ x?: number;
41
+ /** Initial vertical position; centered if omitted. */
42
+ y?: number;
43
+ /** Whether the user can resize the window. */
44
+ resizable?: boolean;
45
+ /** Keep the window above others. */
46
+ alwaysOnTop?: boolean;
47
+ /** Remove the title bar and window chrome (creation-only). */
48
+ frameless?: boolean;
49
+ /** Floating, non-activating panel that doesn't steal focus (creation-only). */
50
+ noActivate?: boolean;
51
+ /** Blend the title bar into the content (creation-only). */
52
+ transparentTitlebar?: boolean;
53
+ /** In-app path the window loads on startup (frontend route). */
54
+ route?: string;
55
+ /**
56
+ * Desktop chrome for the FIRST (main) boot window only.
57
+ * - `true` / omitted: app menu + context menu + tray (default)
58
+ * - `false`: none
59
+ * - object: granular control, e.g. `{ appMenu: true, contextMenu: true, tray: false }`
60
+ * (omitted parts default to `false` when an object is provided)
61
+ */
62
+ chrome?: boolean | ChromeParts;
63
+ }
64
+
65
+ /** Normalize chrome config to explicit part flags. */
66
+ export function resolveChrome(chrome: WindowPreset["chrome"]): Required<ChromeParts> {
67
+ if (chrome === false) return { appMenu: false, contextMenu: false, tray: false };
68
+ if (chrome === true || chrome === undefined) return { appMenu: true, contextMenu: true, tray: true };
69
+ return {
70
+ appMenu: !!chrome.appMenu,
71
+ contextMenu: !!chrome.contextMenu,
72
+ tray: !!chrome.tray
73
+ };
74
+ }
75
+
76
+ /**
77
+ * Named window presets. Only these open at boot. The "main" entry is always
78
+ * created first; every extra entry also opens as a fresh window at startup.
79
+ */
80
+ export const windows: Record<string, WindowPreset> = {
81
+ main: {
82
+ title: config.appName,
83
+ width: 900,
84
+ height: 600,
85
+ resizable: true,
86
+ alwaysOnTop: false,
87
+ route: "/",
88
+ chrome: true
89
+ }
90
+ };
91
+
92
+ /** The main (first-created) window preset. */
93
+ export const windowConfig: WindowPreset = windows.main;
@@ -0,0 +1,57 @@
1
+ // ./src/core/api/binding-error.ts
2
+
3
+ /**
4
+ * Error envelopes for the bindings bridge.
5
+ *
6
+ * Electron's `ipcRenderer.invoke` cannot carry a thrown value across the IPC
7
+ * boundary: it serializes the rejection down to a single string message, so
8
+ * every custom property (`status`, `errors`, …) is lost. A controller that
9
+ * throws `validate.run`'s `{ status: 422, errors }` would reach the renderer as
10
+ * `Error("Error invoking remote method '…': [object Object]")`, and
11
+ * `form.errors.<field>` would never populate.
12
+ *
13
+ * To keep the data, `bindAll` catches handler failures and **returns** this
14
+ * tagged envelope instead of throwing; the preload bridge detects the tag and
15
+ * rejects with an `Error` carrying `.response.data = envelope`, which is the
16
+ * shape `gum` reads. See `guide/gum.md`.
17
+ */
18
+
19
+ export const BINDING_ERROR = "__deskappError" as const;
20
+
21
+ /** Structured-clone-safe payload carried by a binding error envelope. */
22
+ export interface BindingErrorPayload {
23
+ message: string;
24
+ [key: string]: unknown;
25
+ }
26
+
27
+ /** A serialized handler error, tagged so the preload bridge can spot it. */
28
+ export type BindingErrorEnvelope = BindingErrorPayload & { __deskappError: true };
29
+
30
+ /** True when a handler's resolved value is actually a serialized error. */
31
+ export function isBindingErrorEnvelope(value: unknown): value is BindingErrorEnvelope {
32
+ return typeof value === "object" && value !== null && (value as Record<string, unknown>)[BINDING_ERROR] === true;
33
+ }
34
+
35
+ /** Flatten any thrown value into a cloneable payload (own props + message/stack). */
36
+ export function serializeBindingError(error: unknown): BindingErrorPayload {
37
+ if (error instanceof Error) {
38
+ const payload: BindingErrorPayload = { message: error.message };
39
+ if (error.name) payload.name = error.name;
40
+ if (error.stack) payload.stack = error.stack;
41
+ for (const key of Object.keys(error)) {
42
+ payload[key] = (error as unknown as Record<string, unknown>)[key];
43
+ }
44
+ return payload;
45
+ }
46
+ if (typeof error === "object" && error !== null) {
47
+ const source = error as Record<string, unknown>;
48
+ const message = typeof source.message === "string" ? source.message : String(error);
49
+ return { ...source, message };
50
+ }
51
+ return { message: String(error) };
52
+ }
53
+
54
+ /** Wrap a thrown value in the tagged envelope `bindAll` returns. */
55
+ export function toBindingErrorEnvelope(error: unknown): BindingErrorEnvelope {
56
+ return { [BINDING_ERROR]: true, ...serializeBindingError(error) };
57
+ }
@@ -1,3 +1,5 @@
1
+ // ./src/core/api/bindings.generated.ts
2
+
1
3
  // AUTO-GENERATED by `npm run maker -- bindings:gen`. Do not edit.
2
4
  // Regenerates the controller list so packaged builds don't rely on scanning
3
5
  // the filesystem at runtime.
@@ -1,80 +1,84 @@
1
- import fs from "node:fs";
2
- import path from "node:path";
3
- import { fileURLToPath } from "node:url";
4
-
5
- const __filename = fileURLToPath(import.meta.url);
6
- const __dirname = path.dirname(__filename);
7
-
8
- // Project root: src/core/api -> ../../..
9
- const PROJECT_ROOT = path.resolve(__dirname, "..", "..", "..");
10
- const MODULES_DIR = path.join(PROJECT_ROOT, "src", "modules");
11
- const OUT_FILE = path.join(PROJECT_ROOT, "src", "core", "api", "bindings.generated.ts");
12
-
13
- interface ControllerEntry {
14
- module: string;
15
- controller: string;
16
- importPath: string;
17
- }
18
-
19
- function collectControllers(): ControllerEntry[] {
20
- const entries: ControllerEntry[] = [];
21
- if (!fs.existsSync(MODULES_DIR)) return entries;
22
-
23
- for (const modDirent of fs.readdirSync(MODULES_DIR, { withFileTypes: true })) {
24
- if (!modDirent.isDirectory()) continue;
25
- const moduleName = modDirent.name;
26
- const controllersDir = path.join(MODULES_DIR, moduleName, "controllers");
27
- if (!fs.existsSync(controllersDir)) continue;
28
-
29
- for (const file of fs.readdirSync(controllersDir, { withFileTypes: true })) {
30
- if (!file.isFile() || !file.name.endsWith(".controller.ts")) continue;
31
- const controller = file.name.replace(/\.controller\.ts$/, "");
32
- entries.push({
33
- module: moduleName,
34
- controller,
35
- importPath: `@/modules/${moduleName}/controllers/${controller}.controller`
36
- });
37
- }
38
- }
39
-
40
- return entries.sort((a, b) => `${a.module}.${a.controller}`.localeCompare(`${b.module}.${b.controller}`));
41
- }
42
-
43
- function generate(): void {
44
- const controllers = collectControllers();
45
- const imports = controllers.map((c, i) => `import * as mod${i} from "${c.importPath}";`).join("\n");
46
- const items = controllers.map((c, i) => ` { module: "${c.module}", controller: "${c.controller}", mod: mod${i} }`).join(",\n");
47
-
48
- const content = `// AUTO-GENERATED by \`npm run maker -- bindings:gen\`. Do not edit.
49
- // Regenerates the controller list so packaged builds don't rely on scanning
50
- // the filesystem at runtime.
51
-
52
- ${imports || "// no controllers found"}
53
-
54
- export interface GeneratedController {
55
- module: string;
56
- controller: string;
57
- mod: Record<string, unknown>;
58
- }
59
-
60
- export const GENERATED_CONTROLLERS: GeneratedController[] = [
61
- ${items}
62
- ];
63
- `;
64
-
65
- fs.mkdirSync(path.dirname(OUT_FILE), { recursive: true });
66
- fs.writeFileSync(OUT_FILE, content, "utf8");
67
- console.log(`[bindings:gen] wrote ${path.relative(PROJECT_ROOT, OUT_FILE)} (${controllers.length} controller(s))`);
68
- }
69
-
70
- function isMain(): boolean {
71
- try {
72
- return process.argv[1] && path.resolve(process.argv[1]) === path.resolve(fileURLToPath(import.meta.url));
73
- } catch {
74
- return false;
75
- }
76
- }
77
-
78
- if (isMain()) generate();
79
-
80
- export { collectControllers, generate };
1
+ // ./src/core/api/generate.manifest.ts
2
+
3
+ import fs from "node:fs";
4
+ import path from "node:path";
5
+ import { fileURLToPath } from "node:url";
6
+
7
+ const __filename = fileURLToPath(import.meta.url);
8
+ const __dirname = path.dirname(__filename);
9
+
10
+ // Project root: src/core/api -> ../../..
11
+ const PROJECT_ROOT = path.resolve(__dirname, "..", "..", "..");
12
+ const MODULES_DIR = path.join(PROJECT_ROOT, "src", "modules");
13
+ const OUT_FILE = path.join(PROJECT_ROOT, "src", "core", "api", "bindings.generated.ts");
14
+
15
+ interface ControllerEntry {
16
+ module: string;
17
+ controller: string;
18
+ importPath: string;
19
+ }
20
+
21
+ function collectControllers(): ControllerEntry[] {
22
+ const entries: ControllerEntry[] = [];
23
+ if (!fs.existsSync(MODULES_DIR)) return entries;
24
+
25
+ for (const modDirent of fs.readdirSync(MODULES_DIR, { withFileTypes: true })) {
26
+ if (!modDirent.isDirectory()) continue;
27
+ const moduleName = modDirent.name;
28
+ const controllersDir = path.join(MODULES_DIR, moduleName, "controllers");
29
+ if (!fs.existsSync(controllersDir)) continue;
30
+
31
+ for (const file of fs.readdirSync(controllersDir, { withFileTypes: true })) {
32
+ if (!file.isFile() || !file.name.endsWith(".controller.ts")) continue;
33
+ const controller = file.name.replace(/\.controller\.ts$/, "");
34
+ entries.push({
35
+ module: moduleName,
36
+ controller,
37
+ importPath: `@/modules/${moduleName}/controllers/${controller}.controller`
38
+ });
39
+ }
40
+ }
41
+
42
+ return entries.sort((a, b) => `${a.module}.${a.controller}`.localeCompare(`${b.module}.${b.controller}`));
43
+ }
44
+
45
+ function generate(): void {
46
+ const controllers = collectControllers();
47
+ const imports = controllers.map((c, i) => `import * as mod${i} from "${c.importPath}";`).join("\n");
48
+ const items = controllers.map((c, i) => ` { module: "${c.module}", controller: "${c.controller}", mod: mod${i} }`).join(",\n");
49
+
50
+ const content = `// ./src/core/api/bindings.generated.ts
51
+
52
+ // AUTO-GENERATED by \`npm run maker -- bindings:gen\`. Do not edit.
53
+ // Regenerates the controller list so packaged builds don't rely on scanning
54
+ // the filesystem at runtime.
55
+
56
+ ${imports || "// no controllers found"}
57
+
58
+ export interface GeneratedController {
59
+ module: string;
60
+ controller: string;
61
+ mod: Record<string, unknown>;
62
+ }
63
+
64
+ export const GENERATED_CONTROLLERS: GeneratedController[] = [
65
+ ${items}
66
+ ];
67
+ `;
68
+
69
+ fs.mkdirSync(path.dirname(OUT_FILE), { recursive: true });
70
+ fs.writeFileSync(OUT_FILE, content, "utf8");
71
+ console.log(`[bindings:gen] wrote ${path.relative(PROJECT_ROOT, OUT_FILE)} (${controllers.length} controller(s))`);
72
+ }
73
+
74
+ function isMain(): boolean {
75
+ try {
76
+ return process.argv[1] && path.resolve(process.argv[1]) === path.resolve(fileURLToPath(import.meta.url));
77
+ } catch {
78
+ return false;
79
+ }
80
+ }
81
+
82
+ if (isMain()) generate();
83
+
84
+ export { collectControllers, generate };
@@ -1,48 +1,58 @@
1
- import { ipcMain } from "electron";
2
- import { GENERATED_CONTROLLERS } from "@/core/api/bindings.generated";
3
-
4
- /** A callable handler registered for the frontend. */
5
- export type BoundHandler = (...args: unknown[]) => unknown;
6
-
7
- /** A controller module exposing a `handlers` map for registration. */
8
- interface ControllerModule {
9
- handlers?: Record<string, BoundHandler>;
10
- }
11
-
12
- /**
13
- * Collect every registered handler across modules, keyed by
14
- * `<module>.<controller>.<handler>` (e.g., `auth.role.index`).
15
- */
16
- export function collectHandlers(): Map<string, BoundHandler> {
17
- const handlers = new Map<string, BoundHandler>();
18
-
19
- for (const entry of GENERATED_CONTROLLERS) {
20
- const mod = entry.mod as ControllerModule;
21
- if (!mod.handlers) continue;
22
- for (const key of Object.keys(mod.handlers)) {
23
- handlers.set(`${entry.module}.${entry.controller}.${key}`, mod.handlers[key]);
24
- }
25
- }
26
-
27
- return handlers;
28
- }
29
-
30
- /**
31
- * Register all handlers with Electron's ipcMain.
32
- * In Electron, we don't bind to a specific window; we bind globally.
33
- */
34
- export function bindAll(): void {
35
- const handlers = collectHandlers();
36
- for (const [name, fn] of handlers) {
37
- ipcMain.handle(`deskapp:${name}`, async (_event, ...args: unknown[]) => {
38
- return await fn(...args);
39
- });
40
- }
41
- // Sync channel so preload can expose a concrete, cloneable bindings object.
42
- ipcMain.removeHandler?.("deskapp:__list__" as never);
43
- ipcMain.on("deskapp:__list__", (event) => {
44
- event.returnValue = [...handlers.keys()];
45
- });
46
- ipcMain.handle("deskapp:__list__", async () => [...handlers.keys()]);
47
- console.log(`[bindings] registered ${handlers.size} IPC handler(s)`);
48
- }
1
+ // ./src/core/api/registry.ts
2
+
3
+ import { ipcMain } from "electron";
4
+ import { toBindingErrorEnvelope } from "@/core/api/binding-error";
5
+ import { GENERATED_CONTROLLERS } from "@/core/api/bindings.generated";
6
+
7
+ /** A callable handler registered for the frontend. */
8
+ export type BoundHandler = (...args: unknown[]) => unknown;
9
+
10
+ /** A controller module exposing a `handlers` map for registration. */
11
+ interface ControllerModule {
12
+ handlers?: Record<string, BoundHandler>;
13
+ }
14
+
15
+ /**
16
+ * Collect every registered handler across modules, keyed by
17
+ * `<module>.<controller>.<handler>` (e.g., `auth.role.index`).
18
+ */
19
+ export function collectHandlers(): Map<string, BoundHandler> {
20
+ const handlers = new Map<string, BoundHandler>();
21
+
22
+ for (const entry of GENERATED_CONTROLLERS) {
23
+ const mod = entry.mod as ControllerModule;
24
+ if (!mod.handlers) continue;
25
+ for (const key of Object.keys(mod.handlers)) {
26
+ handlers.set(`${entry.module}.${entry.controller}.${key}`, mod.handlers[key]);
27
+ }
28
+ }
29
+
30
+ return handlers;
31
+ }
32
+
33
+ /**
34
+ * Register all handlers with Electron's ipcMain.
35
+ * In Electron, we don't bind to a specific window; we bind globally.
36
+ */
37
+ export function bindAll(): void {
38
+ const handlers = collectHandlers();
39
+ for (const [name, fn] of handlers) {
40
+ ipcMain.handle(`deskapp:${name}`, async (_event, ...args: unknown[]) => {
41
+ try {
42
+ return await fn(...args);
43
+ } catch (error) {
44
+ // Electron drops a thrown value's properties across IPC (only a string
45
+ // message survives), so return a tagged envelope the preload bridge
46
+ // turns back into a rejection. See `@/core/api/binding-error`.
47
+ return toBindingErrorEnvelope(error);
48
+ }
49
+ });
50
+ }
51
+ // Sync channel so preload can expose a concrete, cloneable bindings object.
52
+ ipcMain.removeHandler?.("deskapp:__list__" as never);
53
+ ipcMain.on("deskapp:__list__", (event) => {
54
+ event.returnValue = [...handlers.keys()];
55
+ });
56
+ ipcMain.handle("deskapp:__list__", async () => [...handlers.keys()]);
57
+ console.log(`[bindings] registered ${handlers.size} IPC handler(s)`);
58
+ }