@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.
- package/package.json +16 -16
- package/template/.env.example +20 -13
- package/template/AGENTS.md +699 -0
- package/template/package.json +3 -0
- package/template/src/config/app.ts +26 -24
- package/template/src/config/winsetup.ts +93 -91
- package/template/src/core/api/binding-error.ts +57 -0
- package/template/src/core/api/bindings.generated.ts +2 -0
- package/template/src/core/api/generate.manifest.ts +84 -80
- package/template/src/core/api/registry.ts +58 -48
- package/template/src/core/config.ts +101 -99
- package/template/src/core/database/aggregate.ts +89 -85
- package/template/src/core/database/config.ts +50 -48
- package/template/src/core/database/connection.ts +116 -114
- package/template/src/core/database/migrate-hooks.ts +86 -84
- package/template/src/core/database/paginate.ts +226 -224
- package/template/src/core/database/reset.ts +21 -19
- package/template/src/core/database/seed.ts +169 -167
- package/template/src/core/database/status.ts +37 -35
- package/template/src/core/env.ts +108 -106
- package/template/src/core/facade.ts +63 -61
- package/template/src/core/maker/db/fresh.ts +10 -8
- package/template/src/core/maker/db/generate.ts +13 -11
- package/template/src/core/maker/db/helpers.ts +92 -96
- package/template/src/core/maker/db/migrate.ts +37 -35
- package/template/src/core/maker/db/mod.ts +93 -91
- package/template/src/core/maker/db/module-migrate.ts +56 -54
- package/template/src/core/maker/db/push.ts +23 -21
- package/template/src/core/maker/db/reset.ts +8 -6
- package/template/src/core/maker/db/seed.ts +9 -7
- package/template/src/core/maker/db/status.ts +8 -6
- package/template/src/core/maker/help.ts +59 -57
- package/template/src/core/maker/make/controller.ts +25 -22
- package/template/src/core/maker/make/helpers.ts +97 -91
- package/template/src/core/maker/make/mod.ts +69 -67
- package/template/src/core/maker/make/model.ts +16 -14
- package/template/src/core/maker/make/module.ts +53 -39
- package/template/src/core/maker/make/seeder.ts +23 -21
- package/template/src/core/maker/make/test.ts +33 -30
- package/template/src/core/maker/mod.ts +85 -83
- package/template/src/core/maker/run/mod.ts +134 -132
- package/template/src/core/maker/stub.ts +26 -24
- package/template/src/core/maker/stubs/controller/controller.controller.stub +57 -55
- package/template/src/core/maker/stubs/controller/controller.schema.stub +18 -13
- package/template/src/core/maker/stubs/facade/facade.stub +21 -0
- package/template/src/core/maker/stubs/model/model.stub +10 -8
- package/template/src/core/maker/stubs/seeder/seeder.stub +18 -16
- package/template/src/core/maker/stubs/test/test.stub +9 -7
- package/template/src/core/maker/sync-config.ts +93 -94
- package/template/src/core/utils/password.ts +29 -27
- package/template/src/core/utils/playwright.ts +123 -121
- package/template/src/core/utils/queue.ts +68 -66
- package/template/src/core/utils/scheduler.ts +62 -60
- package/template/src/core/utils/storage.ts +3 -1
- package/template/src/core/utils/validation.ts +37 -35
- package/template/src/database/schema.ts +2 -0
- package/template/src/main.ts +120 -118
- package/template/src/modules/app/__tests__/demo.controller.test.ts +75 -0
- package/template/src/modules/app/__tests__/net.controller.test.ts +65 -0
- package/template/src/modules/app/__tests__/playwright.controller.test.ts +50 -0
- package/template/src/modules/app/__tests__/storage.controller.test.ts +114 -0
- package/template/src/modules/app/__tests__/window.controller.test.ts +98 -0
- package/template/src/modules/app/controllers/demo.controller.ts +120 -118
- package/template/src/modules/app/controllers/net.controller.ts +50 -48
- package/template/src/modules/app/controllers/playwright.controller.ts +142 -140
- package/template/src/modules/app/controllers/storage.controller.ts +231 -229
- package/template/src/modules/app/controllers/window.controller.ts +2 -0
- package/template/src/modules/app/facade.ts +21 -0
- package/template/src/preload.ts +25 -2
- package/template/src/ui/src/App.vue +4 -2
- package/template/src/ui/src/app.ts +38 -23
- package/template/src/ui/src/bindings.d.ts +18 -16
- package/template/src/ui/src/components/Button.vue +34 -32
- package/template/src/ui/src/components/Checkbox.vue +26 -29
- package/template/src/ui/src/components/Input.vue +221 -227
- package/template/src/ui/src/components/InputGroup.vue +141 -0
- package/template/src/ui/src/components/InputPasswordToggle.vue +204 -0
- package/template/src/ui/src/components/Modal.vue +65 -55
- package/template/src/ui/src/components/Spinner.vue +44 -42
- package/template/src/ui/src/components/Switch.vue +62 -65
- package/template/src/ui/src/components/TextArea.vue +108 -121
- package/template/src/ui/src/components/Toast.vue +55 -56
- package/template/src/ui/src/components/datatable/DataTableSkeleton.vue +100 -98
- package/template/src/ui/src/components/datatable/Pagination.vue +153 -125
- package/template/src/ui/src/components/datatable/SelectOpption.vue +36 -35
- package/template/src/ui/src/components/datatable/index.vue +336 -258
- package/template/src/ui/src/env.d.ts +16 -13
- package/template/src/ui/src/global.d.ts +21 -2
- package/template/src/ui/src/helpers/nformatter.ts +12 -10
- package/template/src/ui/src/pages/dashboard/index.vue +690 -687
- package/template/src/ui/src/plugins/browserDetect.ts +57 -0
- package/template/src/ui/src/plugins/gum.ts +576 -549
- package/template/src/ui/src/plugins/pulse.ts +181 -147
- package/template/src/ui/src/plugins/routeProgress.ts +89 -0
- package/template/src/ui/src/router/index.ts +44 -25
- package/template/src/ui/src/stores/example.ts +2 -0
- package/template/src/ui/vite.config.ts +40 -38
- package/template/src/window/app-menu.ts +89 -87
- package/template/src/window/config.ts +14 -12
- package/template/src/window/context-menu.ts +23 -21
- package/template/src/window/dialogs.ts +92 -90
- package/template/src/window/manager.ts +2 -0
- package/template/src/window/native.ts +47 -45
- package/template/src/window/tray.ts +132 -130
package/template/package.json
CHANGED
|
@@ -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
|
-
|
|
3
|
-
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
|
|
9
|
-
export
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
/**
|
|
13
|
-
|
|
14
|
-
/**
|
|
15
|
-
|
|
16
|
-
/**
|
|
17
|
-
|
|
18
|
-
/**
|
|
19
|
-
|
|
20
|
-
/**
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
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
|
-
|
|
3
|
-
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
export
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
/**
|
|
25
|
-
|
|
26
|
-
/**
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
/**
|
|
34
|
-
|
|
35
|
-
/** Initial
|
|
36
|
-
|
|
37
|
-
/** Initial
|
|
38
|
-
|
|
39
|
-
/** Initial
|
|
40
|
-
|
|
41
|
-
/**
|
|
42
|
-
|
|
43
|
-
/**
|
|
44
|
-
|
|
45
|
-
/**
|
|
46
|
-
|
|
47
|
-
/**
|
|
48
|
-
|
|
49
|
-
/**
|
|
50
|
-
|
|
51
|
-
/**
|
|
52
|
-
|
|
53
|
-
/**
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
*
|
|
57
|
-
* -
|
|
58
|
-
*
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
return {
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
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,80 +1,84 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
import
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
const
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
const
|
|
47
|
-
|
|
48
|
-
const
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
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
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
/** A
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
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
|
+
}
|