@niyamulahsan/create-deskapp 0.0.0-stage → 1.2.1

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 (132) hide show
  1. package/README.md +49 -2
  2. package/bin/create.js +136 -0
  3. package/package.json +14 -4
  4. package/template/.env +13 -0
  5. package/template/.env.example +13 -0
  6. package/template/.vscode/extensions.json +6 -0
  7. package/template/.vscode/settings.json +37 -0
  8. package/template/LICENSE +21 -0
  9. package/template/README.md +29 -0
  10. package/template/biome.json +99 -0
  11. package/template/drizzle.config.ts +32 -0
  12. package/template/gitignore-stub +19 -0
  13. package/template/package.json +111 -0
  14. package/template/scripts/build-electron.mjs +55 -0
  15. package/template/scripts/dev-electron.mjs +53 -0
  16. package/template/scripts/installer.nsh +14 -0
  17. package/template/src/config/app.ts +24 -0
  18. package/template/src/core/api/bindings.generated.ts +23 -0
  19. package/template/src/core/api/generate.manifest.ts +86 -0
  20. package/template/src/core/api/registry.ts +48 -0
  21. package/template/src/core/config.ts +99 -0
  22. package/template/src/core/database/aggregate.ts +85 -0
  23. package/template/src/core/database/config.ts +48 -0
  24. package/template/src/core/database/connection.ts +114 -0
  25. package/template/src/core/database/migrate-hooks.ts +84 -0
  26. package/template/src/core/database/paginate.ts +224 -0
  27. package/template/src/core/database/reset.ts +19 -0
  28. package/template/src/core/database/seed.ts +169 -0
  29. package/template/src/core/database/status.ts +32 -0
  30. package/template/src/core/env.ts +106 -0
  31. package/template/src/core/facade.ts +59 -0
  32. package/template/src/core/maker/db/fresh.ts +8 -0
  33. package/template/src/core/maker/db/generate.ts +11 -0
  34. package/template/src/core/maker/db/helpers.ts +96 -0
  35. package/template/src/core/maker/db/migrate.ts +36 -0
  36. package/template/src/core/maker/db/mod.ts +63 -0
  37. package/template/src/core/maker/db/module-migrate.ts +53 -0
  38. package/template/src/core/maker/db/push.ts +21 -0
  39. package/template/src/core/maker/db/reset.ts +6 -0
  40. package/template/src/core/maker/db/seed.ts +7 -0
  41. package/template/src/core/maker/db/status.ts +6 -0
  42. package/template/src/core/maker/help.ts +66 -0
  43. package/template/src/core/maker/make/controller.ts +27 -0
  44. package/template/src/core/maker/make/helpers.ts +93 -0
  45. package/template/src/core/maker/make/mod.ts +68 -0
  46. package/template/src/core/maker/make/model.ts +14 -0
  47. package/template/src/core/maker/make/module.ts +62 -0
  48. package/template/src/core/maker/make/seeder.ts +21 -0
  49. package/template/src/core/maker/make/test.ts +30 -0
  50. package/template/src/core/maker/mod.ts +83 -0
  51. package/template/src/core/maker/run/mod.ts +112 -0
  52. package/template/src/core/maker/stub.ts +24 -0
  53. package/template/src/core/maker/stubs/controller/controller.controller.stub +55 -0
  54. package/template/src/core/maker/stubs/controller/controller.schema.stub +13 -0
  55. package/template/src/core/maker/stubs/model/model.stub +8 -0
  56. package/template/src/core/maker/stubs/seeder/seeder.stub +16 -0
  57. package/template/src/core/maker/stubs/test/test.stub +7 -0
  58. package/template/src/core/maker/sync-config.ts +94 -0
  59. package/template/src/core/utils/password.ts +27 -0
  60. package/template/src/core/utils/playwright.ts +121 -0
  61. package/template/src/core/utils/queue.ts +59 -0
  62. package/template/src/core/utils/scheduler.ts +70 -0
  63. package/template/src/core/utils/storage.ts +599 -0
  64. package/template/src/core/utils/validation.ts +35 -0
  65. package/template/src/database/migrations/sqlite/meta/_journal.json +1 -0
  66. package/template/src/database/schema.ts +6 -0
  67. package/template/src/icons/apple-touch-icon.png +0 -0
  68. package/template/src/icons/deskapp.png +0 -0
  69. package/template/src/icons/favicon-96x96.png +0 -0
  70. package/template/src/icons/favicon.ico +0 -0
  71. package/template/src/icons/favicon.svg +1 -0
  72. package/template/src/icons/site.webmanifest +21 -0
  73. package/template/src/icons/tray.png +0 -0
  74. package/template/src/icons/web-app-manifest-192x192.png +0 -0
  75. package/template/src/icons/web-app-manifest-512x512.png +0 -0
  76. package/template/src/main.ts +116 -0
  77. package/template/src/modules/app/controllers/demo.controller.ts +118 -0
  78. package/template/src/modules/app/controllers/net.controller.ts +48 -0
  79. package/template/src/modules/app/controllers/playwright.controller.ts +140 -0
  80. package/template/src/modules/app/controllers/storage.controller.ts +229 -0
  81. package/template/src/modules/app/controllers/window.controller.ts +107 -0
  82. package/template/src/preload.ts +35 -0
  83. package/template/src/storage/.gitkeep +1 -0
  84. package/template/src/storage/app/private/.gitkeep +1 -0
  85. package/template/src/storage/app/private/samples/.gitkeep +1 -0
  86. package/template/src/storage/app/private/samples/state.json +5 -0
  87. package/template/src/storage/app/private/uploads/.gitkeep +1 -0
  88. package/template/src/storage/app/public/.gitkeep +1 -0
  89. package/template/src/storage/app/tmp/generated/.gitkeep +1 -0
  90. package/template/src/storage/logs/.gitkeep +0 -0
  91. package/template/src/storage/logs/app.log +0 -0
  92. package/template/src/storage/logs/fatal.log +0 -0
  93. package/template/src/ui/.vscode/extensions.json +3 -0
  94. package/template/src/ui/index.html +14 -0
  95. package/template/src/ui/public/icons.svg +24 -0
  96. package/template/src/ui/src/App.vue +3 -0
  97. package/template/src/ui/src/app.ts +23 -0
  98. package/template/src/ui/src/assets/fonts/public-sans/public-sans-latin-ext.woff2 +0 -0
  99. package/template/src/ui/src/assets/fonts/public-sans/public-sans-latin.woff2 +0 -0
  100. package/template/src/ui/src/assets/images/deskapp.png +0 -0
  101. package/template/src/ui/src/assets/images/favicon/favicon.ico +0 -0
  102. package/template/src/ui/src/assets/scss/custom.scss +186 -0
  103. package/template/src/ui/src/bindings.d.ts +16 -0
  104. package/template/src/ui/src/components/Button.vue +32 -0
  105. package/template/src/ui/src/components/Checkbox.vue +29 -0
  106. package/template/src/ui/src/components/Input.vue +227 -0
  107. package/template/src/ui/src/components/Modal.vue +55 -0
  108. package/template/src/ui/src/components/Spinner.vue +42 -0
  109. package/template/src/ui/src/components/Switch.vue +65 -0
  110. package/template/src/ui/src/components/TextArea.vue +121 -0
  111. package/template/src/ui/src/components/Toast.vue +56 -0
  112. package/template/src/ui/src/components/datatable/DataTableSkeleton.vue +98 -0
  113. package/template/src/ui/src/components/datatable/Pagination.vue +125 -0
  114. package/template/src/ui/src/components/datatable/SelectOpption.vue +35 -0
  115. package/template/src/ui/src/components/datatable/index.vue +258 -0
  116. package/template/src/ui/src/env.d.ts +13 -0
  117. package/template/src/ui/src/global.d.ts +35 -0
  118. package/template/src/ui/src/helpers/nformatter.ts +10 -0
  119. package/template/src/ui/src/pages/dashboard/index.vue +687 -0
  120. package/template/src/ui/src/plugins/gum.ts +549 -0
  121. package/template/src/ui/src/plugins/gum.ts.bak +683 -0
  122. package/template/src/ui/src/plugins/pulse.ts +148 -0
  123. package/template/src/ui/src/router/index.ts +25 -0
  124. package/template/src/ui/src/stores/example.ts +27 -0
  125. package/template/src/ui/tsconfig.json +15 -0
  126. package/template/src/ui/vite.config.ts +38 -0
  127. package/template/src/window/config.ts +71 -0
  128. package/template/src/window/dialogs.ts +67 -0
  129. package/template/src/window/manager.ts +139 -0
  130. package/template/src/window/native.ts +215 -0
  131. package/template/tsconfig.json +22 -0
  132. package/template/vitest.config.ts +34 -0
@@ -0,0 +1,30 @@
1
+ import path from "node:path";
2
+ import { loadStub } from "../stub";
3
+ import type { MakerOptions } from "./helpers";
4
+ import { assertModuleExists, assertName, moduleDir, writeFile } from "./helpers";
5
+
6
+ /**
7
+ * make:test / module:make-test - create a Vitest file in a module's __tests__ folder.
8
+ * Nexwire-style: `module:make-test <module> [name]` -> __tests__/<name|module>.test.ts
9
+ */
10
+ export function makeTest(module: string, name?: string, options: MakerOptions = {}): void {
11
+ const moduleName = assertName(module, "Module name");
12
+ assertModuleExists(moduleName);
13
+ const rawName = name && name.trim() ? assertName(name, "Test name") : moduleName;
14
+ // strip trailing .test/.spec if provided
15
+ const testName = rawName.replace(/\.(test|spec)$/i, "");
16
+
17
+ const filePath = path.join(moduleDir(moduleName), "__tests__", `${testName}.test.ts`);
18
+ const content = loadStub("test/test.stub", {
19
+ module: moduleName,
20
+ name: testName === moduleName ? "" : testName
21
+ }).replace(/\{\{#name\}\}[\s\S]*?\{\{\/name\}\}/g, (m) => {
22
+ // simple conditional: keep inner text when name is non-empty
23
+ return testName === moduleName ? "" : m.replace(/\{\{#name\}\}|\{\{\/name\}\}/g, "");
24
+ });
25
+
26
+ writeFile(filePath, content, options, "Test file");
27
+ if (!options.dryRun) {
28
+ console.log(`Run tests with: npm test (or \`npm run maker -- test\`).`);
29
+ }
30
+ }
@@ -0,0 +1,83 @@
1
+ import { registerDbCommands } from "./db/mod";
2
+ import { printCommandHelp, printHelp, type CommandDef } from "./help";
3
+ import { registerMakeCommands } from "./make/mod";
4
+ import { registerRunCommands } from "./run/mod";
5
+
6
+ const commands = new Map<string, CommandDef>();
7
+
8
+ function register(cmd: CommandDef) {
9
+ commands.set(cmd.name, cmd);
10
+ }
11
+
12
+ registerMakeCommands(register);
13
+ registerDbCommands(register);
14
+ registerRunCommands(register);
15
+
16
+ function parseFlags(argv: string[]): { flags: Record<string, string | boolean>; positionals: string[] } {
17
+ const flags: Record<string, string | boolean> = {};
18
+ const positionals: string[] = [];
19
+ for (let i = 0; i < argv.length; i++) {
20
+ const arg = argv[i];
21
+ if (arg === "--") {
22
+ positionals.push(...argv.slice(i + 1));
23
+ break;
24
+ }
25
+ if (arg.startsWith("--")) {
26
+ const eq = arg.indexOf("=");
27
+ if (eq !== -1) {
28
+ flags[arg.slice(2, eq)] = arg.slice(eq + 1);
29
+ } else {
30
+ const key = arg.slice(2);
31
+ const next = argv[i + 1];
32
+ if (key === "no-zip") {
33
+ flags.zip = false;
34
+ } else if (next !== undefined && !next.startsWith("--")) {
35
+ flags[key] = next;
36
+ i++;
37
+ } else {
38
+ flags[key] = true;
39
+ }
40
+ }
41
+ } else {
42
+ positionals.push(arg);
43
+ }
44
+ }
45
+ return { flags, positionals };
46
+ }
47
+
48
+ async function main() {
49
+ const argv = process.argv.slice(2);
50
+ if (argv.length === 0 || argv[0] === "-h" || argv[0] === "--help") {
51
+ printHelp(commands);
52
+ return;
53
+ }
54
+ if (argv[0] === "help") {
55
+ const target = argv[1];
56
+ if (target && commands.has(target)) printCommandHelp(commands.get(target)!);
57
+ else printHelp(commands);
58
+ return;
59
+ }
60
+
61
+ const name = argv[0];
62
+ const cmd = commands.get(name);
63
+ if (!cmd) {
64
+ console.error(`\n Unknown command: ${name}\n`);
65
+ printHelp(commands);
66
+ process.exit(1);
67
+ }
68
+
69
+ const { flags, positionals } = parseFlags(argv.slice(1));
70
+ if (flags.help || flags.h) {
71
+ printCommandHelp(cmd);
72
+ return;
73
+ }
74
+
75
+ try {
76
+ await cmd.action(flags, positionals);
77
+ } catch (error) {
78
+ console.error(error instanceof Error ? error.message : error);
79
+ process.exit(1);
80
+ }
81
+ }
82
+
83
+ main();
@@ -0,0 +1,112 @@
1
+ import { spawnSync } from "node:child_process";
2
+ import fs from "node:fs";
3
+ import path from "node:path";
4
+ import { fileURLToPath } from "node:url";
5
+ import type { CommandDef } from "../help";
6
+
7
+ const __dirname = path.dirname(fileURLToPath(import.meta.url));
8
+ const ROOT = path.resolve(__dirname, "..", "..", "..", "..");
9
+
10
+ function run(cmd: string, args: string[], opts: { cwd?: string; label?: string } = {}): void {
11
+ console.log(`== ${opts.label ?? cmd} ==`);
12
+ const isWin = process.platform === "win32";
13
+ const r = spawnSync(isWin ? "cmd.exe" : cmd, isWin ? ["/d", "/s", "/c", cmd, ...args] : args, {
14
+ cwd: opts.cwd ?? ROOT,
15
+ stdio: "inherit",
16
+ shell: false,
17
+ env: process.env,
18
+ });
19
+ if (r.error) throw r.error;
20
+ if (r.status !== 0) process.exit(r.status ?? 1);
21
+ }
22
+
23
+ function tsxScript(script: string, label: string): void {
24
+ run("npx", ["--yes", "tsx", "--tsconfig", "tsconfig.json", script], { label });
25
+ }
26
+
27
+ function configSync(): void {
28
+ tsxScript("src/core/maker/sync-config.ts", "config:sync");
29
+ }
30
+
31
+ function schemaAndBindings(): void {
32
+ configSync();
33
+ tsxScript("src/core/database/aggregate.ts", "schema (db:schema)");
34
+ tsxScript("src/core/api/generate.manifest.ts", "bindings (bindings:gen)");
35
+ }
36
+
37
+ export function registerRunCommands(register: (cmd: CommandDef) => void): void {
38
+ register({
39
+ name: "dev",
40
+ group: "Getting started",
41
+ description: "Start Electron + Vite UI (HMR) + esbuild watch for main/preload",
42
+ action: () => {
43
+ schemaAndBindings();
44
+ run("npm", ["run", "dev"], { label: "dev" });
45
+ },
46
+ });
47
+
48
+ register({
49
+ name: "ui",
50
+ group: "Getting started",
51
+ description: "Start Vite dev server for the renderer only (no Electron bindings)",
52
+ action: () => run("npx", ["vite", "--config", "src/ui/vite.config.ts"], { label: "vite dev", cwd: ROOT }),
53
+ });
54
+
55
+ register({
56
+ name: "start",
57
+ group: "Getting started",
58
+ description: "Run the built Electron app (loads src/ui/dist; requires build)",
59
+ action: () => run("npm", ["run", "start"], { label: "start" }),
60
+ });
61
+
62
+ register({
63
+ name: "config:sync",
64
+ group: "Build & codegen",
65
+ description: "Sync src/config/app.ts -> package.json build/identity + scripts/installer.nsh",
66
+ action: () => configSync(),
67
+ });
68
+
69
+ register({
70
+ name: "codegen",
71
+ group: "Build & codegen",
72
+ description: "Sync config + regenerate database schema + bindings manifest",
73
+ action: () => schemaAndBindings(),
74
+ });
75
+
76
+ register({
77
+ name: "bindings:gen",
78
+ group: "Build & codegen",
79
+ description: "Regenerate src/core/api/bindings.generated.ts from controllers",
80
+ action: () => tsxScript("src/core/api/generate.manifest.ts", "bindings:gen"),
81
+ });
82
+
83
+ register({
84
+ name: "build",
85
+ group: "Build & codegen",
86
+ description: "Build renderer UI + Electron main/preload bundles",
87
+ action: () => {
88
+ schemaAndBindings();
89
+ run("npm", ["run", "build"], { label: "build", cwd: ROOT });
90
+ },
91
+ });
92
+
93
+ register({
94
+ name: "package",
95
+ group: "Build & codegen",
96
+ description: "Build and package installers with electron-builder",
97
+ action: (flags) => {
98
+ schemaAndBindings();
99
+ run("npm", ["run", "build"], { label: "build" });
100
+ const ebArgs = ["--yes", "electron-builder"];
101
+ if (typeof flags.platform === "string") ebArgs.push(`--${flags.platform}`);
102
+ if (typeof flags.target === "string") ebArgs.push(`--${flags.target}`);
103
+ run("npx", ebArgs, { label: "electron-builder" });
104
+ },
105
+ });
106
+
107
+ register({ name: "serve", group: "Getting started", description: "Alias for dev (Electron)", action: () => run("npm", ["run", "dev"], { label: "dev" }) });
108
+
109
+ register({ name: "test", group: "Testing", description: "Run Vitest unit tests (node environment)", action: () => run("npx", ["vitest", "run"], { label: "test" }) });
110
+ register({ name: "test:watch", group: "Testing", description: "Run Vitest in watch mode", action: () => run("npx", ["vitest"], { label: "test:watch" }) });
111
+ register({ name: "test:coverage", group: "Testing", description: "Run Vitest with V8 coverage", action: () => run("npx", ["vitest", "run", "--coverage"], { label: "test:coverage" }) });
112
+ }
@@ -0,0 +1,24 @@
1
+ import fs from "node:fs";
2
+ import { dirname, join } from "node:path";
3
+ import { fileURLToPath } from "node:url";
4
+
5
+ export interface StubValues {
6
+ [key: string]: string;
7
+ }
8
+
9
+ const __filename = fileURLToPath(import.meta.url);
10
+ const __dirname = dirname(__filename);
11
+ const STUBS_ROOT = join(__dirname, "stubs");
12
+
13
+ /**
14
+ * Read a stub file and replace {{key}} placeholders, removing any that
15
+ * remain unfilled.
16
+ */
17
+ export function loadStub(name: string, values: StubValues): string {
18
+ const file = join(STUBS_ROOT, name);
19
+ let content = fs.readFileSync(file, "utf8");
20
+ for (const [key, value] of Object.entries(values)) {
21
+ content = content.replaceAll(`{{${key}}}`, value);
22
+ }
23
+ return content.replace(/\{\{[A-Z0-9_]+\}\}/g, "");
24
+ }
@@ -0,0 +1,55 @@
1
+ import { validate } from "@/core/facade";
2
+ import { Create{{ClassName}}Schema,Update{{ClassName}}Schema,{{ClassName}}IdParamsSchema } from "@/modules/{{module}}/controllers/{{controller}}.schema";
3
+
4
+ /**
5
+ * Why: Returns collection response shape for list pages.
6
+ * When: Used by the frontend list view.
7
+ * Where: bound as "{{module}}.{{controller}}.index".
8
+ */
9
+ export const index = async () => {
10
+ return { message: "{{controller}} list fetched successfully", data: [] };
11
+ };
12
+
13
+ /**
14
+ * Why: Returns one resource by validated id.
15
+ * When: Used by detail screens or fetch-by-id calls.
16
+ * Where: bound as "{{module}}.{{controller}}.show".
17
+ */
18
+ export const show = async (params: unknown) => {
19
+ const { id } = await validate.run({{ClassName}}IdParamsSchema, params);
20
+ return { message: "{{controller}} fetched successfully", data: { id, name: "" } };
21
+ };
22
+
23
+ /**
24
+ * Why: Creates a new resource from validated input.
25
+ * When: Used by create form submissions.
26
+ * Where: bound as "{{module}}.{{controller}}.store".
27
+ */
28
+ export const store = async (body: unknown) => {
29
+ await validate.run(Create{{ClassName}}Schema, body);
30
+ return { message: "{{controller}} created successfully" };
31
+ };
32
+
33
+ /**
34
+ * Why: Updates an existing resource using validated id + body.
35
+ * When: Used by edit/update form submissions.
36
+ * Where: bound as "{{module}}.{{controller}}.update".
37
+ */
38
+ export const update = async (input: { params: unknown; body: unknown }) => {
39
+ await validate.run({{ClassName}}IdParamsSchema, input.params);
40
+ await validate.run(Update{{ClassName}}Schema, input.body);
41
+ return { message: "{{controller}} updated successfully" };
42
+ };
43
+
44
+ /**
45
+ * Why: Deletes one resource by validated id.
46
+ * When: Used by delete actions.
47
+ * Where: bound as "{{module}}.{{controller}}.destroy".
48
+ */
49
+ export const destroy = async (params: unknown) => {
50
+ await validate.run({{ClassName}}IdParamsSchema, params);
51
+ return { message: "{{controller}} deleted successfully" };
52
+ };
53
+
54
+ /** Handlers exposed to the frontend via the bindings registry. */
55
+ export const handlers = { index, show, store, update, destroy };
@@ -0,0 +1,13 @@
1
+ import { z } from "zod";
2
+
3
+ export const Create{{ClassName}}Schema = z.object({
4
+ name: z.string().min(1),
5
+ });
6
+
7
+ export const Update{{ClassName}}Schema = z.object({
8
+ name: z.string().min(1),
9
+ });
10
+
11
+ export const {{ClassName}}IdParamsSchema = z.object({
12
+ id: z.coerce.number().int().positive(),
13
+ });
@@ -0,0 +1,8 @@
1
+ import { integer, sqliteTable, text } from "drizzle-orm/sqlite-core";
2
+
3
+ export const {{tableVariable}} = sqliteTable("{{tableName}}", {
4
+ id: integer("id").primaryKey({ autoIncrement: true }),
5
+ name: text("name").notNull(),
6
+ createdAt: text("created_at").notNull().default("current_timestamp"),
7
+ updatedAt: text("updated_at").notNull().default("current_timestamp"),
8
+ });
@@ -0,0 +1,16 @@
1
+ import { db } from "@/core/database/connection";
2
+ import { {{tableVariable}} } from "@/modules/{{module}}/database/models/{{name}}.model";
3
+
4
+ export const table = {{tableVariable}};
5
+
6
+ export default async function {{ClassName}}Seeder() {
7
+ const rows: (typeof {{tableVariable}}.$inferInsert)[] = [
8
+ // Add your seed data here
9
+ ];
10
+
11
+ for (const row of rows) {
12
+ await db.insert({{tableVariable}}).values(row);
13
+ }
14
+
15
+ console.log("{{ClassName}} seeder completed");
16
+ }
@@ -0,0 +1,7 @@
1
+ import { describe, expect, it } from "vitest";
2
+
3
+ describe("{{module}} module{{#name}} - {{name}}{{/name}}", () => {
4
+ it("works", () => {
5
+ expect(true).toBe(true);
6
+ });
7
+ });
@@ -0,0 +1,94 @@
1
+ import fs from "node:fs";
2
+ import path from "node:path";
3
+ import { fileURLToPath } from "node:url";
4
+ import { appConfig } from "@config/app";
5
+
6
+ const __dirname = path.dirname(fileURLToPath(import.meta.url));
7
+ const root = path.resolve(__dirname, "..", "..", "..");
8
+
9
+ function readJson<T = any>(p: string): T {
10
+ return JSON.parse(fs.readFileSync(p, "utf-8")) as T;
11
+ }
12
+
13
+ function writeIfChanged(file: string, content: string): boolean {
14
+ const prev = fs.existsSync(file) ? fs.readFileSync(file, "utf-8") : "";
15
+ if (prev === content) {
16
+ console.log(`[config:sync] unchanged ${path.relative(root, file)}`);
17
+ return false;
18
+ }
19
+ fs.mkdirSync(path.dirname(file), { recursive: true });
20
+ fs.writeFileSync(file, content, "utf-8");
21
+ console.log(`[config:sync] updated ${path.relative(root, file)}`);
22
+ return true;
23
+ }
24
+
25
+ function syncPackageJson(): boolean {
26
+ const pkgPath = path.join(root, "package.json");
27
+ const pkg = readJson<any>(pkgPath);
28
+
29
+ pkg.name = appConfig.name;
30
+ pkg.description = appConfig.description;
31
+
32
+ pkg.build = pkg.build ?? {};
33
+ pkg.build.appId = appConfig.appId;
34
+ pkg.build.productName = appConfig.productName;
35
+
36
+ pkg.build.nsis = pkg.build.nsis ?? {};
37
+ pkg.build.nsis.shortcutName = appConfig.productName;
38
+ pkg.build.nsis.uninstallDisplayName = appConfig.productName;
39
+ pkg.build.nsis.include = "scripts/installer.nsh";
40
+
41
+ // Keep protocols in sync if present; create a minimal one if missing.
42
+ const scheme = appConfig.protocol;
43
+ if (Array.isArray(pkg.build.protocols) && pkg.build.protocols.length > 0) {
44
+ pkg.build.protocols[0].name = appConfig.productName;
45
+ pkg.build.protocols[0].schemes = [scheme];
46
+ } else {
47
+ pkg.build.protocols = [{ name: appConfig.productName, schemes: [scheme] }];
48
+ }
49
+
50
+ return writeIfChanged(pkgPath, JSON.stringify(pkg, null, 2) + "\n");
51
+ }
52
+
53
+ function renderInstallerNsh(): string {
54
+ const product = appConfig.productName;
55
+ const folders = Array.from(new Set(appConfig.uninstallDataFolders.filter(Boolean)));
56
+ const rmLines = folders.flatMap((f) => [
57
+ ` RMDir /r "$APPDATA\\${f}"`,
58
+ ` RMDir /r "$LOCALAPPDATA\\${f}"`,
59
+ ]);
60
+ return [
61
+ "; Custom NSIS include for electron-builder (generated from src/config/app.ts via config:sync)",
62
+ "; Adds an uninstall choice: full uninstall (remove user data) or just uninstall (keep user data).",
63
+ "",
64
+ "!macro customUnInstall",
65
+ ` MessageBox MB_YESNO|MB_ICONQUESTION "Do you want to completely remove all ${product} data and settings as well?$\\r$\\n$\\r$\\nYes = Full uninstall (remove app data)$\\r$\\nNo = Just uninstall (keep your data/settings)" /SD IDNO IDNO keepData`,
66
+ " ; Full uninstall: remove Electron user data and common app data locations",
67
+ ...rmLines,
68
+ " keepData:",
69
+ "!macroend",
70
+ "",
71
+ ].join("\n");
72
+ }
73
+
74
+ function syncInstaller(): boolean {
75
+ const out = path.join(root, "scripts", "installer.nsh");
76
+ return writeIfChanged(out, renderInstallerNsh());
77
+ }
78
+
79
+ function syncUiTitle(): boolean {
80
+ const file = path.join(root, "src", "ui", "index.html");
81
+ if (!fs.existsSync(file)) return false;
82
+ const prev = fs.readFileSync(file, "utf-8");
83
+ const next = prev.replace(/<title>[^<]*<\/title>/i, `<title>${appConfig.productName}</title>`);
84
+ return writeIfChanged(file, next);
85
+ }
86
+
87
+ function main() {
88
+ const a = syncPackageJson();
89
+ const b = syncInstaller();
90
+ const c = syncUiTitle();
91
+ if (!a && !b && !c) console.log("[config:sync] everything up to date");
92
+ }
93
+
94
+ main();
@@ -0,0 +1,27 @@
1
+ import bcrypt from "bcryptjs";
2
+
3
+ /** Number of bcrypt salt rounds. Higher is slower but more secure. */
4
+ const SALT_ROUNDS = 10;
5
+
6
+ /**
7
+ * Password hashing + verification, grouped under one namespace.
8
+ *
9
+ * Consumers import this from the facade:
10
+ * import { pass } from "@/core/facade.ts";
11
+ * await pass.hashPassword("secret");
12
+ */
13
+ export const pass = {
14
+ /**
15
+ * Hash a plaintext password using bcrypt.
16
+ */
17
+ hashPassword(password: string): Promise<string> {
18
+ return bcrypt.hash(password, SALT_ROUNDS);
19
+ },
20
+
21
+ /**
22
+ * Check a plaintext password against a stored bcrypt hash.
23
+ */
24
+ verifyPassword(password: string, hash: string): Promise<boolean> {
25
+ return bcrypt.compare(password, hash);
26
+ },
27
+ };
@@ -0,0 +1,121 @@
1
+ import { dirname, join } from "node:path";
2
+ import { createRequire } from "node:module";
3
+ import { execSync } from "node:child_process";
4
+ import fs from "node:fs";
5
+ import { app } from "electron";
6
+
7
+ function getRequire(): NodeRequire {
8
+ // CJS bundles/runtime have `require`; ESM can derive it when needed.
9
+ if (typeof require !== "undefined") return require as unknown as NodeRequire;
10
+ // Fallback for ESM contexts (not used in the CJS bundle).
11
+ const url = typeof __filename !== "undefined" ? __filename : process.cwd();
12
+ return createRequire(url);
13
+ }
14
+
15
+ export const chromium = {
16
+ exists(path: string): boolean {
17
+ return existsPath(path);
18
+ },
19
+ candidates(overrides?: { env?: string | null; execPath?: string; cwd?: string; }): string[] {
20
+ return chromiumCandidates(overrides);
21
+ },
22
+ resolve(overrides?: { env?: string | null; execPath?: string; cwd?: string; }): string | undefined {
23
+ return resolveChromium(overrides);
24
+ },
25
+ extensions(overrides?: { execPath?: string; cwd?: string; }): string[] {
26
+ return extensionsCandidates(overrides);
27
+ },
28
+ };
29
+
30
+ export function existsPath(path: string): boolean {
31
+ try {
32
+ fs.statSync(path);
33
+ return true;
34
+ } catch {
35
+ return false;
36
+ }
37
+ }
38
+
39
+ export function platformRelPaths(): string[][] {
40
+ if (process.platform === "win32") {
41
+ return [["chrome-win64", "chrome.exe"], ["chrome-win", "chrome.exe"]];
42
+ }
43
+ if (process.platform === "linux") {
44
+ return [["chrome-linux", "chrome"]];
45
+ }
46
+ if (process.platform === "darwin") {
47
+ const app = ["Google Chrome for Testing.app", "Contents", "MacOS", "Google Chrome for Testing"];
48
+ return [["chrome-mac-arm64", ...app], ["chrome-mac", ...app]];
49
+ }
50
+ return [];
51
+ }
52
+
53
+ export function chromiumCandidates(overrides?: { env?: string | null; execPath?: string; cwd?: string; }): string[] {
54
+ const out: string[] = [];
55
+ const env = overrides?.env === undefined ? process.env.DESKAPP_CHROMIUM : overrides.env;
56
+ if (env) out.push(env);
57
+
58
+ const bases = [
59
+ dirname(overrides?.execPath ?? app.getPath("exe")),
60
+ overrides?.cwd ?? process.cwd()
61
+ ];
62
+
63
+ for (const base of bases) {
64
+ for (const rel of platformRelPaths()) {
65
+ out.push(join(base, "chromium", ...rel));
66
+ }
67
+ }
68
+ return out;
69
+ }
70
+
71
+ export function resolveChromium(overrides?: { env?: string | null; execPath?: string; cwd?: string; }): string | undefined {
72
+ return chromiumCandidates(overrides).find(existsPath);
73
+ }
74
+
75
+ export function extensionsCandidates(overrides?: { execPath?: string; cwd?: string; }): string[] {
76
+ const out: string[] = [];
77
+ const bases = [
78
+ dirname(overrides?.execPath ?? app.getPath("exe")),
79
+ overrides?.cwd ?? process.cwd()
80
+ ];
81
+
82
+ for (const base of bases) {
83
+ for (const rel of ["extensions", join("src", "extensions")]) {
84
+ const root = join(base, rel);
85
+ try {
86
+ for (const entry of fs.readdirSync(root, { withFileTypes: true })) {
87
+ if (!entry.isDirectory()) continue;
88
+ const full = join(root, entry.name);
89
+ if (!out.includes(full)) out.push(full);
90
+ }
91
+ } catch {
92
+ // no extensions folder at this base - skip
93
+ }
94
+ }
95
+ }
96
+ return out;
97
+ }
98
+
99
+ export function resolveExtensions(overrides?: { execPath?: string; cwd?: string; }): string[] {
100
+ return extensionsCandidates(overrides);
101
+ }
102
+
103
+ export async function ensurePlaywrightBrowser(browser = "chromium"): Promise<void> {
104
+ try {
105
+ // In Node, resolve playwright's CLI if installed.
106
+ const req = getRequire();
107
+ const playwrightPkg = req.resolve("playwright/package.json");
108
+ const cliFile = join(dirname(playwrightPkg), "cli.js");
109
+
110
+ if (!existsPath(cliFile)) {
111
+ throw new Error(`playwright CLI not found at ${cliFile}; install the browser manually with 'npx playwright install ${browser}'.`);
112
+ }
113
+
114
+ // In Electron, process.execPath is the Electron binary, not Node.
115
+ // We use the system's Node execution to run the playwright CLI.
116
+ execSync(`node "${cliFile}" install ${browser}`, { stdio: "inherit" });
117
+ } catch (error) {
118
+ console.error("[playwright] Failed to ensure browser:", error);
119
+ throw new Error(`playwright install ${browser} failed; retry with 'npx playwright install ${browser}'.`);
120
+ }
121
+ }
@@ -0,0 +1,59 @@
1
+ /**
2
+ * queue.ts - reusable in-process async queue.
3
+ *
4
+ * Bounded concurrency; `add(task)` resolves with the task's own result and
5
+ * rejects only that caller when the task throws (other tasks unaffected).
6
+ * Import via the facade: `import { queue } from "@/core/facade.ts"`.
7
+ */
8
+
9
+ export type QueueTask<T> = () => Promise<T>;
10
+
11
+ interface Pending<T> { task: QueueTask<T>; resolve: (value: T) => void; reject: (reason?: unknown) => void; }
12
+
13
+ export interface Queue<T> {
14
+ add(task: QueueTask<T>): Promise<T>;
15
+ readonly size: number;
16
+ readonly running: number;
17
+ }
18
+
19
+ /**
20
+ * Queue namespace - create bounded-concurrency async queues through the
21
+ * facade: `const q = queue.create({ concurrency: 3 })`.
22
+ */
23
+ export const queue = {
24
+ create<T>(options?: { concurrency?: number; }): Queue<T> {
25
+ return createQueue<T>(options);
26
+ },
27
+ };
28
+
29
+ function createQueue<T>(options?: { concurrency?: number; }): Queue<T> {
30
+ const concurrency = Math.max(1, options?.concurrency ?? 1);
31
+ const pending: Pending<T>[] = [];
32
+ let running = 0;
33
+
34
+ const tick = (): void => {
35
+ while (running < concurrency && pending.length > 0) {
36
+ const entry = pending.shift()!;
37
+ running += 1;
38
+ entry.task().then(entry.resolve, entry.reject).finally(() => {
39
+ running -= 1;
40
+ tick();
41
+ });
42
+ }
43
+ };
44
+
45
+ return {
46
+ add(task: QueueTask<T>): Promise<T> {
47
+ return new Promise<T>((resolve, reject) => {
48
+ pending.push({ task, resolve, reject });
49
+ tick();
50
+ });
51
+ },
52
+ get size() {
53
+ return pending.length;
54
+ },
55
+ get running() {
56
+ return running;
57
+ },
58
+ };
59
+ }