@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
|
@@ -1,114 +1,116 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
import
|
|
4
|
-
import
|
|
5
|
-
import
|
|
6
|
-
import
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
const
|
|
27
|
-
if (
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
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
|
-
}
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
const
|
|
73
|
-
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
1
|
+
// ./src/core/database/connection.ts
|
|
2
|
+
|
|
3
|
+
import fsSync from "node:fs";
|
|
4
|
+
import fs from "node:fs/promises";
|
|
5
|
+
import path from "node:path";
|
|
6
|
+
import type { Client as LibSqlClient } from "@libsql/client";
|
|
7
|
+
import { sqliteFile } from "@/core/database/config";
|
|
8
|
+
import * as schema from "@/database/schema";
|
|
9
|
+
|
|
10
|
+
let databaseInstance: DrizzleDatabase | null = null;
|
|
11
|
+
let databaseClient: LibSqlClient | null = null;
|
|
12
|
+
|
|
13
|
+
export type DrizzleDatabase = import("drizzle-orm/libsql").LibSQLDatabase<typeof schema>;
|
|
14
|
+
|
|
15
|
+
async function resolveMigrationsDir(): Promise<string> {
|
|
16
|
+
try {
|
|
17
|
+
const e = (await import("electron").catch(() => null)) as any;
|
|
18
|
+
if (e?.app?.getAppPath) {
|
|
19
|
+
const dir = path.join(e.app.getAppPath(), "src", "database", "migrations", "sqlite");
|
|
20
|
+
if (fsSync.existsSync(dir)) return dir;
|
|
21
|
+
}
|
|
22
|
+
} catch {}
|
|
23
|
+
// CLI/dev fallback: find project root
|
|
24
|
+
let dir = process.cwd();
|
|
25
|
+
for (let i = 0; i < 6; i++) {
|
|
26
|
+
const candidate = path.join(dir, "src", "database", "migrations", "sqlite");
|
|
27
|
+
if (fsSync.existsSync(path.join(dir, "package.json"))) return candidate;
|
|
28
|
+
const parent = path.dirname(dir);
|
|
29
|
+
if (parent === dir) break;
|
|
30
|
+
dir = parent;
|
|
31
|
+
}
|
|
32
|
+
return path.join(process.cwd(), "src", "database", "migrations", "sqlite");
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export async function initDatabase(): Promise<DrizzleDatabase> {
|
|
36
|
+
if (databaseInstance) return databaseInstance;
|
|
37
|
+
|
|
38
|
+
const filePath = sqliteFile();
|
|
39
|
+
await createFolderFor(filePath);
|
|
40
|
+
|
|
41
|
+
databaseInstance = await connectWithLibSql(filePath);
|
|
42
|
+
await runBundledMigrations();
|
|
43
|
+
|
|
44
|
+
return databaseInstance;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
async function runBundledMigrations(): Promise<void> {
|
|
48
|
+
const folder = await resolveMigrationsDir();
|
|
49
|
+
let journal: { entries?: { tag: string }[] };
|
|
50
|
+
|
|
51
|
+
try {
|
|
52
|
+
const journalRaw = await fs.readFile(path.join(folder, "meta", "_journal.json"), "utf-8");
|
|
53
|
+
journal = JSON.parse(journalRaw);
|
|
54
|
+
} catch {
|
|
55
|
+
return;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
if (!journal.entries?.length || !databaseClient) return;
|
|
59
|
+
if ((await countTables()) > 0) return;
|
|
60
|
+
|
|
61
|
+
for (const entry of journal.entries) {
|
|
62
|
+
try {
|
|
63
|
+
const step = await fs.readFile(path.join(folder, `${entry.tag}.sql`), "utf-8");
|
|
64
|
+
await databaseClient.executeMultiple(step);
|
|
65
|
+
} catch (err) {
|
|
66
|
+
console.error(`[db] Failed to run migration ${entry.tag}`, err);
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
async function countTables(): Promise<number> {
|
|
72
|
+
const sql = "select count(*) as n from sqlite_master where type='table' and name not like 'sqlite_%' and name not like '__drizzle_%'";
|
|
73
|
+
const result = await databaseClient!.execute(sql);
|
|
74
|
+
const row = result.rows[0] as { n?: bigint | number };
|
|
75
|
+
return Number(row?.n ?? 0);
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
async function connectWithLibSql(filePath: string): Promise<DrizzleDatabase> {
|
|
79
|
+
const { createClient } = await import("@libsql/client");
|
|
80
|
+
const { drizzle } = await import("drizzle-orm/libsql");
|
|
81
|
+
|
|
82
|
+
// libsql requires forward slashes even on Windows
|
|
83
|
+
const normalizedPath = filePath.replace(/\\/g, "/");
|
|
84
|
+
const client = createClient({ url: `file:${normalizedPath}` });
|
|
85
|
+
databaseClient = client;
|
|
86
|
+
|
|
87
|
+
return drizzle(client, { schema }) as unknown as DrizzleDatabase;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
export function database(): DrizzleDatabase {
|
|
91
|
+
if (!databaseInstance) throw new Error("Database is not initialized.");
|
|
92
|
+
return databaseInstance;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
export const db: DrizzleDatabase & {
|
|
96
|
+
init: typeof initDatabase;
|
|
97
|
+
close: typeof closeDatabase;
|
|
98
|
+
} = new Proxy({} as any, {
|
|
99
|
+
get(_target, property) {
|
|
100
|
+
if (property === "init") return initDatabase;
|
|
101
|
+
if (property === "close") return closeDatabase;
|
|
102
|
+
const value = database()[property as keyof DrizzleDatabase];
|
|
103
|
+
return typeof value === "function" ? value.bind(database()) : value;
|
|
104
|
+
}
|
|
105
|
+
});
|
|
106
|
+
|
|
107
|
+
export function closeDatabase(): void {
|
|
108
|
+
if (databaseClient) databaseClient.close();
|
|
109
|
+
databaseClient = null;
|
|
110
|
+
databaseInstance = null;
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
async function createFolderFor(filePath: string): Promise<void> {
|
|
114
|
+
const dir = path.dirname(filePath);
|
|
115
|
+
await fs.mkdir(dir, { recursive: true });
|
|
116
|
+
}
|
|
@@ -1,84 +1,86 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
import
|
|
4
|
-
import
|
|
5
|
-
import {
|
|
6
|
-
|
|
7
|
-
|
|
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
|
-
const
|
|
48
|
-
|
|
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
|
-
}
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
1
|
+
// ./src/core/database/migrate-hooks.ts
|
|
2
|
+
|
|
3
|
+
import fs from "node:fs";
|
|
4
|
+
import path from "node:path";
|
|
5
|
+
import { pathToFileURL } from "node:url";
|
|
6
|
+
import { sql } from "drizzle-orm";
|
|
7
|
+
import { db } from "@/core/database/connection";
|
|
8
|
+
|
|
9
|
+
interface HookMap {
|
|
10
|
+
__migrationSql: true;
|
|
11
|
+
sqlite?: string[];
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
function isHookMap(value: unknown): value is HookMap {
|
|
15
|
+
if (!value || typeof value !== "object") return false;
|
|
16
|
+
return (value as HookMap).__migrationSql === true;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
function collectStatements(exportsObj: Record<string, unknown>): string[] {
|
|
20
|
+
const statements: string[] = [];
|
|
21
|
+
for (const value of Object.values(exportsObj)) {
|
|
22
|
+
if (!isHookMap(value)) continue;
|
|
23
|
+
const list = value.sqlite || [];
|
|
24
|
+
for (const statement of list) {
|
|
25
|
+
if (typeof statement === "string" && statement.trim()) statements.push(statement);
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
return statements;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
const SRC_PATH = path.resolve(process.cwd(), "src");
|
|
32
|
+
|
|
33
|
+
function walkTs(dir: string, out: string[]): void {
|
|
34
|
+
try {
|
|
35
|
+
for (const entry of fs.readdirSync(dir, { withFileTypes: true })) {
|
|
36
|
+
const full = path.join(dir, entry.name);
|
|
37
|
+
if (entry.isDirectory()) {
|
|
38
|
+
walkTs(full, out);
|
|
39
|
+
} else if (entry.isFile() && entry.name.endsWith(".ts")) {
|
|
40
|
+
out.push(full);
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
} catch {}
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
function discoverModelFiles(): string[] {
|
|
47
|
+
const files: string[] = [];
|
|
48
|
+
const modulesDir = path.join(SRC_PATH, "modules");
|
|
49
|
+
const coreDir = path.join(SRC_PATH, "core");
|
|
50
|
+
|
|
51
|
+
if (fs.existsSync(modulesDir)) {
|
|
52
|
+
for (const moduleDir of fs.readdirSync(modulesDir, { withFileTypes: true })) {
|
|
53
|
+
if (!moduleDir.isDirectory()) continue;
|
|
54
|
+
walkTs(path.join(modulesDir, moduleDir.name, "database", "models"), files);
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
if (fs.existsSync(coreDir)) {
|
|
58
|
+
for (const areaDir of fs.readdirSync(coreDir, { withFileTypes: true })) {
|
|
59
|
+
if (!areaDir.isDirectory()) continue;
|
|
60
|
+
walkTs(path.join(coreDir, areaDir.name, "database", "models"), files);
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
return files.sort();
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
const modelFiles = discoverModelFiles();
|
|
67
|
+
await db.init();
|
|
68
|
+
|
|
69
|
+
let applied = 0;
|
|
70
|
+
try {
|
|
71
|
+
for (const file of modelFiles) {
|
|
72
|
+
const mod = await import(pathToFileURL(file).href);
|
|
73
|
+
const statements = collectStatements(mod as Record<string, unknown>);
|
|
74
|
+
if (!statements.length) continue;
|
|
75
|
+
for (const statement of statements) {
|
|
76
|
+
await db.run(sql.raw(statement));
|
|
77
|
+
}
|
|
78
|
+
applied += statements.length;
|
|
79
|
+
}
|
|
80
|
+
} finally {
|
|
81
|
+
await db.close();
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
if (applied > 0) {
|
|
85
|
+
console.log(`Applied ${applied} model migration SQL statement(s) for sqlite.`);
|
|
86
|
+
}
|