@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,61 +1,63 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
//
|
|
13
|
-
|
|
14
|
-
//
|
|
15
|
-
export {
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
type
|
|
19
|
-
type
|
|
20
|
-
type
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
//
|
|
27
|
-
export {
|
|
28
|
-
//
|
|
29
|
-
export {
|
|
30
|
-
//
|
|
31
|
-
export { type
|
|
32
|
-
//
|
|
33
|
-
|
|
34
|
-
//
|
|
35
|
-
|
|
36
|
-
//
|
|
37
|
-
export {
|
|
38
|
-
//
|
|
39
|
-
export {
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
type
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
type
|
|
59
|
-
type
|
|
60
|
-
type
|
|
61
|
-
|
|
1
|
+
// ./src/core/facade.ts
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* facade - central public API surface for framework consumers.
|
|
5
|
+
*
|
|
6
|
+
* App-layer code (module controllers, jobs, schedules, models) should import
|
|
7
|
+
* its framework utilities from here in one place instead of reaching into core
|
|
8
|
+
* internals. Each service is surfaced as it gets implemented; only what is
|
|
9
|
+
* actually implemented is re-exported so the facade stays truthful.
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
// Configuration
|
|
13
|
+
|
|
14
|
+
// Database (query client + lifecycle: `db.init()` / `db.close()`)
|
|
15
|
+
export { type DrizzleDatabase, db } from "@/core/database/connection";
|
|
16
|
+
// Pagination (nexgen-style envelope); `sql` for where filters
|
|
17
|
+
export {
|
|
18
|
+
type PaginatedResult,
|
|
19
|
+
type PaginateInput,
|
|
20
|
+
type PaginateModelOptions,
|
|
21
|
+
type PaginateQueryOptions,
|
|
22
|
+
type PaginateTableOptions,
|
|
23
|
+
paginate,
|
|
24
|
+
sql
|
|
25
|
+
} from "@/core/database/paginate";
|
|
26
|
+
// Security / hashing utilities
|
|
27
|
+
export { pass } from "@/core/utils/password";
|
|
28
|
+
// Browser automation (Playwright): locate the bundled Chromium + extensions
|
|
29
|
+
export { chromium } from "@/core/utils/playwright";
|
|
30
|
+
// Concurrency / job queue
|
|
31
|
+
export { type Queue, type QueueTask, queue } from "@/core/utils/queue";
|
|
32
|
+
// Cron scheduling (backed by croner)
|
|
33
|
+
export { type CronHandle, cron } from "@/core/utils/scheduler";
|
|
34
|
+
// File / storage utilities
|
|
35
|
+
// 1) User-file layer: operate on ANY path the user picks
|
|
36
|
+
// 2) App-managed layer: the app's own internal state (private + tmp)
|
|
37
|
+
export { type Disk, type FileData, files, storage } from "@/core/utils/storage";
|
|
38
|
+
// Validation (zod schemas + runner: `validate.z`, `validate.run`)
|
|
39
|
+
export { validate } from "@/core/utils/validation";
|
|
40
|
+
// Native Windows file/folder pickers and message dialogs (Explorer-style Open / Save As / folder, confirm/alert)
|
|
41
|
+
export {
|
|
42
|
+
alertDialog,
|
|
43
|
+
confirmDialog,
|
|
44
|
+
type PickFolderOptions,
|
|
45
|
+
type PickOpenOptions,
|
|
46
|
+
type PickSaveOptions,
|
|
47
|
+
pickers
|
|
48
|
+
} from "@/window/dialogs";
|
|
49
|
+
// Desktop window control
|
|
50
|
+
export {
|
|
51
|
+
type BrowserWindowOptions,
|
|
52
|
+
type DesktopWindow,
|
|
53
|
+
win
|
|
54
|
+
} from "@/window/manager";
|
|
55
|
+
// Desktop-native APIs: menu item types, tray, dialogs, and chrome setup
|
|
56
|
+
export {
|
|
57
|
+
chrome,
|
|
58
|
+
type DesktopTray,
|
|
59
|
+
type MenuActionItem,
|
|
60
|
+
type MenuItem,
|
|
61
|
+
type MenuRole,
|
|
62
|
+
type MenuSubmenu
|
|
63
|
+
} from "@/window/native";
|
|
@@ -1,8 +1,10 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
1
|
+
// ./src/core/maker/db/fresh.ts
|
|
2
|
+
|
|
3
|
+
import { runScript } from "@/core/maker/db/helpers";
|
|
4
|
+
import { migrate } from "@/core/maker/db/migrate";
|
|
5
|
+
|
|
6
|
+
/** db:fresh - reset DB, then generate, migrate, hooks; seed only with --seed. */
|
|
7
|
+
export async function fresh(seed = false): Promise<void> {
|
|
8
|
+
await runScript("src/core/database/reset.ts");
|
|
9
|
+
await migrate(seed);
|
|
10
|
+
}
|
|
@@ -1,11 +1,13 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
1
|
+
// ./src/core/maker/db/generate.ts
|
|
2
|
+
|
|
3
|
+
import { generateMigrations, generateSchema } from "@/core/maker/db/helpers";
|
|
4
|
+
|
|
5
|
+
/** db:schema - regenerate src/database/schema.ts from all models. */
|
|
6
|
+
export async function schema(): Promise<void> {
|
|
7
|
+
await generateSchema();
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
/** db:generate - regenerate schema and create migration SQL. */
|
|
11
|
+
export async function generate(): Promise<void> {
|
|
12
|
+
await generateMigrations();
|
|
13
|
+
}
|
|
@@ -1,96 +1,92 @@
|
|
|
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
|
-
|
|
27
|
-
|
|
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
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
const
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
} catch {
|
|
94
|
-
return false;
|
|
95
|
-
}
|
|
96
|
-
}
|
|
1
|
+
// ./src/core/maker/db/helpers.ts
|
|
2
|
+
|
|
3
|
+
import { spawnSync } from "node:child_process";
|
|
4
|
+
import fs from "node:fs";
|
|
5
|
+
import path from "node:path";
|
|
6
|
+
import { DatabaseSync } from "node:sqlite";
|
|
7
|
+
import { fileURLToPath } from "node:url";
|
|
8
|
+
import { sqliteFile } from "@/core/database/config";
|
|
9
|
+
|
|
10
|
+
const __dirname = path.dirname(fileURLToPath(import.meta.url));
|
|
11
|
+
// src/core/maker/db -> project root
|
|
12
|
+
export const PROJECT_ROOT = path.resolve(__dirname, "..", "..", "..", "..");
|
|
13
|
+
|
|
14
|
+
function envFileArgs(): string[] {
|
|
15
|
+
const envPath = path.join(PROJECT_ROOT, ".env");
|
|
16
|
+
return fs.existsSync(envPath) ? ["--env-file=.env"] : [];
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
function run(cmd: string, args: string[], env: Record<string, string> = {}): void {
|
|
20
|
+
const isWin = process.platform === "win32";
|
|
21
|
+
const r = spawnSync(isWin ? "cmd.exe" : cmd, isWin ? ["/d", "/s", "/c", cmd, ...args] : args, {
|
|
22
|
+
cwd: PROJECT_ROOT,
|
|
23
|
+
stdio: "inherit",
|
|
24
|
+
shell: false,
|
|
25
|
+
env: { ...process.env, ...env }
|
|
26
|
+
});
|
|
27
|
+
if (r.error) throw r.error;
|
|
28
|
+
if (r.status !== 0) process.exit(r.status ?? 1);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/** Run a TS script via tsx (supports @/ aliases and TS). */
|
|
32
|
+
export async function runScript(scriptPath: string, extra: string[] = []): Promise<void> {
|
|
33
|
+
run("npx", ["--yes", "tsx", "--tsconfig", "tsconfig.json", ...envFileArgs(), scriptPath, ...extra]);
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/** Run drizzle-kit with the given CLI args. */
|
|
37
|
+
export async function runDrizzle(args: string[], env: Record<string, string> = {}): Promise<void> {
|
|
38
|
+
run("npx", ["--yes", "drizzle-kit", ...args], env);
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
export function migrationCount(): number {
|
|
42
|
+
const dir = path.join(PROJECT_ROOT, "src", "database", "migrations", "sqlite");
|
|
43
|
+
let count = 0;
|
|
44
|
+
try {
|
|
45
|
+
for (const entry of fs.readdirSync(dir, { withFileTypes: true })) {
|
|
46
|
+
if (entry.isFile() && entry.name.endsWith(".sql")) count++;
|
|
47
|
+
}
|
|
48
|
+
} catch {}
|
|
49
|
+
return count;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
export async function generateSchema(): Promise<void> {
|
|
53
|
+
await runScript("src/core/database/aggregate.ts");
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
export async function generateMigrations(): Promise<void> {
|
|
57
|
+
await generateSchema();
|
|
58
|
+
await runDrizzle(["generate", ...(migrationCount() === 0 ? ["--name", "init"] : [])]);
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
export async function runSeedScript(module?: string): Promise<void> {
|
|
62
|
+
await runScript("src/core/database/seed.ts", module ? [`--module=${module}`] : []);
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
export async function ensureMigrationMeta(): Promise<void> {
|
|
66
|
+
const metaRoot = path.join(PROJECT_ROOT, "src", "database", "migrations", "sqlite", "meta");
|
|
67
|
+
const journalPath = path.join(metaRoot, "_journal.json");
|
|
68
|
+
fs.mkdirSync(metaRoot, { recursive: true });
|
|
69
|
+
if (!fs.existsSync(journalPath)) {
|
|
70
|
+
fs.writeFileSync(journalPath, `{\n "version": "7",\n "dialect": "sqlite",\n "entries": []\n}\n`, "utf8");
|
|
71
|
+
console.log(`[db:migrate] created migration journal: ${journalPath}`);
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
export async function hasExistingAppTables(): Promise<boolean> {
|
|
76
|
+
try {
|
|
77
|
+
const raw = sqliteFile();
|
|
78
|
+
const file = path.isAbsolute(raw) ? raw : path.resolve(PROJECT_ROOT, raw);
|
|
79
|
+
if (!fs.existsSync(file)) return false;
|
|
80
|
+
const instance = new DatabaseSync(file);
|
|
81
|
+
try {
|
|
82
|
+
const rows = instance
|
|
83
|
+
.prepare("SELECT name FROM sqlite_master WHERE type='table' AND name NOT LIKE 'sqlite_%' AND name != '__drizzle_migrations'")
|
|
84
|
+
.all() as unknown[];
|
|
85
|
+
return rows.length > 0;
|
|
86
|
+
} finally {
|
|
87
|
+
instance.close();
|
|
88
|
+
}
|
|
89
|
+
} catch {
|
|
90
|
+
return false;
|
|
91
|
+
}
|
|
92
|
+
}
|
|
@@ -1,35 +1,37 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
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
|
-
await
|
|
35
|
-
|
|
1
|
+
// ./src/core/maker/db/migrate.ts
|
|
2
|
+
|
|
3
|
+
import {
|
|
4
|
+
ensureMigrationMeta,
|
|
5
|
+
generateMigrations,
|
|
6
|
+
generateSchema,
|
|
7
|
+
hasExistingAppTables,
|
|
8
|
+
migrationCount,
|
|
9
|
+
runDrizzle,
|
|
10
|
+
runScript,
|
|
11
|
+
runSeedScript
|
|
12
|
+
} from "@/core/maker/db/helpers";
|
|
13
|
+
|
|
14
|
+
/** db:migrate - generate+run migrations, apply hooks, seed only with --seed. */
|
|
15
|
+
export async function migrate(seed = false): Promise<void> {
|
|
16
|
+
await ensureMigrationMeta();
|
|
17
|
+
const hadMigrationsBeforeGenerate = migrationCount() > 0;
|
|
18
|
+
const hadExistingTablesBeforeGenerate = await hasExistingAppTables();
|
|
19
|
+
await generateMigrations();
|
|
20
|
+
if (!hadMigrationsBeforeGenerate && hadExistingTablesBeforeGenerate) {
|
|
21
|
+
throw new Error(
|
|
22
|
+
"Initial migration was generated, but the database already contains tables. " +
|
|
23
|
+
"This usually means migration files were deleted while DB data still exists. " +
|
|
24
|
+
"Use 'db:fresh --seed' to rebuild locally, or restore migration files before running db:migrate."
|
|
25
|
+
);
|
|
26
|
+
}
|
|
27
|
+
await runDrizzle(["migrate"]);
|
|
28
|
+
await runScript("src/core/database/migrate-hooks.ts");
|
|
29
|
+
if (seed) await runSeedScript();
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/** db:migrate:run - run existing migrations + model hooks (no generate, no seed). */
|
|
33
|
+
export async function migrateRun(): Promise<void> {
|
|
34
|
+
await generateSchema();
|
|
35
|
+
await runDrizzle(["migrate"]);
|
|
36
|
+
await runScript("src/core/database/migrate-hooks.ts");
|
|
37
|
+
}
|
|
@@ -1,91 +1,93 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
import {
|
|
4
|
-
import
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
9
|
-
import {
|
|
10
|
-
import {
|
|
11
|
-
import {
|
|
12
|
-
import
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
const
|
|
22
|
-
const
|
|
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
|
-
|
|
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
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
register({ name: "db:
|
|
88
|
-
register({ name: "db:
|
|
89
|
-
register({ name: "db:
|
|
90
|
-
register({ name: "db:
|
|
91
|
-
}
|
|
1
|
+
// ./src/core/maker/db/mod.ts
|
|
2
|
+
|
|
3
|
+
import { spawnSync } from "node:child_process";
|
|
4
|
+
import path from "node:path";
|
|
5
|
+
import { fileURLToPath } from "node:url";
|
|
6
|
+
import { fresh } from "@/core/maker/db/fresh";
|
|
7
|
+
import { generate, schema } from "@/core/maker/db/generate";
|
|
8
|
+
import { migrate, migrateRun } from "@/core/maker/db/migrate";
|
|
9
|
+
import { migrateModule } from "@/core/maker/db/module-migrate";
|
|
10
|
+
import { check, push, studio } from "@/core/maker/db/push";
|
|
11
|
+
import { reset } from "@/core/maker/db/reset";
|
|
12
|
+
import { seed } from "@/core/maker/db/seed";
|
|
13
|
+
import { status } from "@/core/maker/db/status";
|
|
14
|
+
import type { CommandDef } from "@/core/maker/help";
|
|
15
|
+
|
|
16
|
+
const __dirname = path.dirname(fileURLToPath(import.meta.url));
|
|
17
|
+
const ROOT = path.resolve(__dirname, "..", "..", "..", "..");
|
|
18
|
+
|
|
19
|
+
function regenerateBindings(): void {
|
|
20
|
+
console.log(`== bindings:gen (pre-db) ==`);
|
|
21
|
+
const cmd = "npx";
|
|
22
|
+
const args = ["--yes", "tsx", "--tsconfig", "tsconfig.json", "src/core/api/generate.manifest.ts"];
|
|
23
|
+
const isWin = process.platform === "win32";
|
|
24
|
+
const r = spawnSync(isWin ? "cmd.exe" : cmd, isWin ? ["/d", "/s", "/c", cmd, ...args] : args, {
|
|
25
|
+
cwd: ROOT,
|
|
26
|
+
stdio: "inherit",
|
|
27
|
+
shell: false,
|
|
28
|
+
env: process.env
|
|
29
|
+
});
|
|
30
|
+
if (r.status !== 0) process.exit(r.status ?? 1);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
function withBindings(action: () => Promise<void>): () => Promise<void> {
|
|
34
|
+
return async () => {
|
|
35
|
+
regenerateBindings();
|
|
36
|
+
await action();
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
const G = "Database";
|
|
41
|
+
|
|
42
|
+
export function registerDbCommands(register: (cmd: CommandDef) => void): void {
|
|
43
|
+
register({ name: "db:schema", group: G, description: "Regenerate src/database/schema.ts from all models", action: () => schema() });
|
|
44
|
+
register({
|
|
45
|
+
name: "db:generate",
|
|
46
|
+
group: G,
|
|
47
|
+
description: "Regenerate schema and create migration SQL (drizzle-kit)",
|
|
48
|
+
action: () => generate()
|
|
49
|
+
});
|
|
50
|
+
register({
|
|
51
|
+
name: "db:migrate",
|
|
52
|
+
usage: "[--seed]",
|
|
53
|
+
group: G,
|
|
54
|
+
description: "Generate + run migrations, apply hooks (seed with --seed)",
|
|
55
|
+
action: (flags) => withBindings(() => migrate(Boolean(flags.seed)))()
|
|
56
|
+
});
|
|
57
|
+
register({
|
|
58
|
+
name: "db:migrate:run",
|
|
59
|
+
group: G,
|
|
60
|
+
description: "Run existing migrations + model hooks (no seed)",
|
|
61
|
+
action: () => withBindings(migrateRun)()
|
|
62
|
+
});
|
|
63
|
+
register({
|
|
64
|
+
name: "db:migrate:module",
|
|
65
|
+
usage: "<module> [--keep-temp]",
|
|
66
|
+
group: G,
|
|
67
|
+
description: "Generate + run migrations for one module's models",
|
|
68
|
+
action: (flags, args) => {
|
|
69
|
+
if (!args[0]) throw new Error("Module name is required.");
|
|
70
|
+
return withBindings(() => migrateModule(args[0], Boolean(flags["keep-temp"])))();
|
|
71
|
+
}
|
|
72
|
+
});
|
|
73
|
+
register({
|
|
74
|
+
name: "db:fresh",
|
|
75
|
+
usage: "[--seed]",
|
|
76
|
+
group: G,
|
|
77
|
+
description: "Reset DB, then generate, migrate, hooks (seed with --seed)",
|
|
78
|
+
action: (flags) => withBindings(() => fresh(Boolean(flags.seed)))()
|
|
79
|
+
});
|
|
80
|
+
register({
|
|
81
|
+
name: "db:seed",
|
|
82
|
+
usage: "[--module <module>]",
|
|
83
|
+
group: G,
|
|
84
|
+
description: "Run seeders (all, or one module; auto FK-ordered)",
|
|
85
|
+
action: (flags) => withBindings(() => seed(typeof flags.module === "string" ? flags.module : undefined))()
|
|
86
|
+
});
|
|
87
|
+
register({ name: "db:status", group: G, description: "List generated migration files", action: () => status() });
|
|
88
|
+
register({ name: "db:push", group: G, description: "Push schema directly (drizzle-kit push)", action: () => push() });
|
|
89
|
+
register({ name: "db:check", group: G, description: "Run drizzle-kit check", action: () => check() });
|
|
90
|
+
register({ name: "db:studio", group: G, description: "Open Drizzle Studio", action: () => studio() });
|
|
91
|
+
register({ name: "db:reset", group: G, description: "Delete the SQLite database file", action: () => reset() });
|
|
92
|
+
register({ name: "db:wipe", group: G, description: "Delete the SQLite database file", action: () => reset() });
|
|
93
|
+
}
|