@niyamulahsan/create-deskapp 1.2.1 → 1.2.3
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/README.md +6 -0
- package/bin/create.js +1 -1
- package/package.json +1 -1
- package/template/.env +1 -1
- package/template/src/config/winsetup.ts +91 -0
- package/template/src/core/api/generate.manifest.ts +4 -10
- package/template/src/core/api/registry.ts +1 -1
- package/template/src/core/config.ts +2 -2
- package/template/src/core/database/aggregate.ts +1 -1
- package/template/src/core/database/connection.ts +11 -11
- package/template/src/core/database/migrate-hooks.ts +1 -1
- package/template/src/core/database/paginate.ts +9 -9
- package/template/src/core/database/reset.ts +2 -2
- package/template/src/core/database/seed.ts +3 -5
- package/template/src/core/database/status.ts +4 -1
- package/template/src/core/env.ts +1 -1
- package/template/src/core/facade.ts +3 -1
- package/template/src/core/maker/db/fresh.ts +2 -2
- package/template/src/core/maker/db/generate.ts +1 -1
- package/template/src/core/maker/db/migrate.ts +3 -4
- package/template/src/core/maker/db/mod.ts +47 -19
- package/template/src/core/maker/db/module-migrate.ts +7 -6
- package/template/src/core/maker/db/push.ts +1 -1
- package/template/src/core/maker/db/reset.ts +1 -1
- package/template/src/core/maker/db/seed.ts +1 -1
- package/template/src/core/maker/db/status.ts +1 -1
- package/template/src/core/maker/help.ts +6 -15
- package/template/src/core/maker/make/controller.ts +5 -10
- package/template/src/core/maker/make/helpers.ts +6 -8
- package/template/src/core/maker/make/mod.ts +13 -14
- package/template/src/core/maker/make/model.ts +1 -1
- package/template/src/core/maker/make/module.ts +6 -29
- package/template/src/core/maker/make/seeder.ts +2 -2
- package/template/src/core/maker/make/test.ts +3 -3
- package/template/src/core/maker/mod.ts +4 -4
- package/template/src/core/maker/run/mod.ts +34 -14
- package/template/src/core/utils/playwright.ts +25 -25
- package/template/src/core/utils/queue.ts +17 -10
- package/template/src/core/utils/scheduler.ts +7 -17
- package/template/src/core/utils/storage.ts +1 -1
- package/template/src/core/utils/validation.ts +3 -3
- package/template/src/database/migrations/sqlite/meta/_journal.json +5 -1
- package/template/src/main.ts +10 -6
- package/template/src/preload.ts +1 -1
- package/template/src/window/app-menu.ts +81 -0
- package/template/src/window/config.ts +10 -69
- package/template/src/window/context-menu.ts +14 -0
- package/template/src/window/dialogs.ts +23 -0
- package/template/src/window/manager.ts +5 -5
- package/template/src/window/native.ts +40 -215
- package/template/src/window/tray.ts +79 -0
- package/template/src/ui/src/plugins/gum.ts.bak +0 -683
package/README.md
CHANGED
|
@@ -1,3 +1,9 @@
|
|
|
1
|
+
<p align="center">
|
|
2
|
+
<a href="https://github.com/niyamulahsan/deskapp">
|
|
3
|
+
<img alt="deskapp" src="https://raw.githubusercontent.com/niyamulahsan/deskapp/main/logo-favicon/deskapp.png" width="300">
|
|
4
|
+
</a>
|
|
5
|
+
</p>
|
|
6
|
+
|
|
1
7
|
<p align="center">
|
|
2
8
|
<a href="https://niyamulahsan.github.io/deskapp"><img src="https://img.shields.io/badge/docs%20%7C%20deskapp-3b8eed" alt="Documentation"></a>
|
|
3
9
|
<a href="https://www.npmjs.com/package/@niyamulahsan/create-deskapp"><img src="https://img.shields.io/npm/v/@niyamulahsan/create-deskapp" alt="npm version"></a>
|
package/bin/create.js
CHANGED
|
@@ -54,7 +54,7 @@ async function main() {
|
|
|
54
54
|
console.log(`create-deskapp v${pkg.version}`);
|
|
55
55
|
console.log();
|
|
56
56
|
console.log("Usage:");
|
|
57
|
-
console.log(" npm create deskapp@latest <project-name|.> [--force]");
|
|
57
|
+
console.log(" npm create @niyamulahsan/deskapp@latest <project-name|.> [--force]");
|
|
58
58
|
console.log(" npx create-deskapp <project-name|.> [--force]");
|
|
59
59
|
console.log();
|
|
60
60
|
console.log("Options:");
|
package/package.json
CHANGED
package/template/.env
CHANGED
|
@@ -7,7 +7,7 @@ DESKAPP_UI=true
|
|
|
7
7
|
|
|
8
8
|
# Database: defaults to the Electron userData folder.
|
|
9
9
|
# Override only if you want a custom file/path.
|
|
10
|
-
DATABASE_URL=sqlite:./src/storage/
|
|
10
|
+
DATABASE_URL=sqlite:./src/storage/deskapp.sqlite
|
|
11
11
|
|
|
12
12
|
# Runtime base dir for relative DATABASE_URL / storage paths.
|
|
13
13
|
# APP_BASE_DIR=
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Window setup/config — edit this file to configure app windows (0 hassle).
|
|
3
|
+
* Each entry in `windows` becomes a native BrowserWindow at boot.
|
|
4
|
+
* The first entry ("main") is the primary window.
|
|
5
|
+
*
|
|
6
|
+
* For runtime windows (opened on demand), pass a `WindowPreset` to `win.openWindow()`.
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
import { config } from "@/core/config";
|
|
10
|
+
|
|
11
|
+
export type DevToolsMode = "bottom" | "right" | "left" | "undocked" | "detach";
|
|
12
|
+
|
|
13
|
+
export const windowDev = {
|
|
14
|
+
/**
|
|
15
|
+
* Auto-open DevTools in development only (never in production/packaged).
|
|
16
|
+
* Set mode: "bottom" | "right" | "left" | "undocked" | "detach", or "none" to disable.
|
|
17
|
+
*/
|
|
18
|
+
devTools: "bottom" as DevToolsMode | "none"
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
export interface ChromeParts {
|
|
22
|
+
/** Application/window menu. */
|
|
23
|
+
appMenu?: boolean;
|
|
24
|
+
/** Right-click context menu. */
|
|
25
|
+
contextMenu?: boolean;
|
|
26
|
+
/** System tray icon/menu (windowed). */
|
|
27
|
+
tray?: boolean;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export interface WindowPreset {
|
|
31
|
+
/** Window title. Falls back to the app name if unset. */
|
|
32
|
+
title: string;
|
|
33
|
+
/** Initial width in logical pixels. */
|
|
34
|
+
width: number;
|
|
35
|
+
/** Initial height in logical pixels. */
|
|
36
|
+
height: number;
|
|
37
|
+
/** Initial horizontal position; centered if omitted. */
|
|
38
|
+
x?: number;
|
|
39
|
+
/** Initial vertical position; centered if omitted. */
|
|
40
|
+
y?: number;
|
|
41
|
+
/** Whether the user can resize the window. */
|
|
42
|
+
resizable?: boolean;
|
|
43
|
+
/** Keep the window above others. */
|
|
44
|
+
alwaysOnTop?: boolean;
|
|
45
|
+
/** Remove the title bar and window chrome (creation-only). */
|
|
46
|
+
frameless?: boolean;
|
|
47
|
+
/** Floating, non-activating panel that doesn't steal focus (creation-only). */
|
|
48
|
+
noActivate?: boolean;
|
|
49
|
+
/** Blend the title bar into the content (creation-only). */
|
|
50
|
+
transparentTitlebar?: boolean;
|
|
51
|
+
/** In-app path the window loads on startup (frontend route). */
|
|
52
|
+
route?: string;
|
|
53
|
+
/**
|
|
54
|
+
* Desktop chrome for the FIRST (main) boot window only.
|
|
55
|
+
* - `true` / omitted: app menu + context menu + tray (default)
|
|
56
|
+
* - `false`: none
|
|
57
|
+
* - object: granular control, e.g. `{ appMenu: true, contextMenu: true, tray: false }`
|
|
58
|
+
* (omitted parts default to `false` when an object is provided)
|
|
59
|
+
*/
|
|
60
|
+
chrome?: boolean | ChromeParts;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
/** Normalize chrome config to explicit part flags. */
|
|
64
|
+
export function resolveChrome(chrome: WindowPreset["chrome"]): Required<ChromeParts> {
|
|
65
|
+
if (chrome === false) return { appMenu: false, contextMenu: false, tray: false };
|
|
66
|
+
if (chrome === true || chrome === undefined) return { appMenu: true, contextMenu: true, tray: true };
|
|
67
|
+
return {
|
|
68
|
+
appMenu: !!chrome.appMenu,
|
|
69
|
+
contextMenu: !!chrome.contextMenu,
|
|
70
|
+
tray: !!chrome.tray,
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
/**
|
|
75
|
+
* Named window presets. Only these open at boot. The "main" entry is always
|
|
76
|
+
* created first; every extra entry also opens as a fresh window at startup.
|
|
77
|
+
*/
|
|
78
|
+
export const windows: Record<string, WindowPreset> = {
|
|
79
|
+
main: {
|
|
80
|
+
title: config.appName,
|
|
81
|
+
width: 900,
|
|
82
|
+
height: 600,
|
|
83
|
+
resizable: true,
|
|
84
|
+
alwaysOnTop: false,
|
|
85
|
+
route: "/",
|
|
86
|
+
chrome: true
|
|
87
|
+
}
|
|
88
|
+
};
|
|
89
|
+
|
|
90
|
+
/** The main (first-created) window preset. */
|
|
91
|
+
export const windowConfig: WindowPreset = windows.main;
|
|
@@ -32,24 +32,18 @@ function collectControllers(): ControllerEntry[] {
|
|
|
32
32
|
entries.push({
|
|
33
33
|
module: moduleName,
|
|
34
34
|
controller,
|
|
35
|
-
importPath: `@/modules/${moduleName}/controllers/${controller}.controller
|
|
35
|
+
importPath: `@/modules/${moduleName}/controllers/${controller}.controller`
|
|
36
36
|
});
|
|
37
37
|
}
|
|
38
38
|
}
|
|
39
39
|
|
|
40
|
-
return entries.sort((a, b) =>
|
|
41
|
-
`${a.module}.${a.controller}`.localeCompare(`${b.module}.${b.controller}`),
|
|
42
|
-
);
|
|
40
|
+
return entries.sort((a, b) => `${a.module}.${a.controller}`.localeCompare(`${b.module}.${b.controller}`));
|
|
43
41
|
}
|
|
44
42
|
|
|
45
43
|
function generate(): void {
|
|
46
44
|
const controllers = collectControllers();
|
|
47
|
-
const imports = controllers
|
|
48
|
-
|
|
49
|
-
.join("\n");
|
|
50
|
-
const items = controllers
|
|
51
|
-
.map((c, i) => ` { module: "${c.module}", controller: "${c.controller}", mod: mod${i} }`)
|
|
52
|
-
.join(",\n");
|
|
45
|
+
const imports = controllers.map((c, i) => `import * as mod${i} from "${c.importPath}";`).join("\n");
|
|
46
|
+
const items = controllers.map((c, i) => ` { module: "${c.module}", controller: "${c.controller}", mod: mod${i} }`).join(",\n");
|
|
53
47
|
|
|
54
48
|
const content = `// AUTO-GENERATED by \`npm run maker -- bindings:gen\`. Do not edit.
|
|
55
49
|
// Regenerates the controller list so packaged builds don't rely on scanning
|
|
@@ -52,7 +52,7 @@ export function generateSchemaFile(srcPath = SRC_PATH, schemaPath = SCHEMA_PATH)
|
|
|
52
52
|
const rel = path.relative(srcPath, f).replace(/\\/g, "/");
|
|
53
53
|
const ext = rel.endsWith(".tsx") ? ".tsx" : ".ts";
|
|
54
54
|
const base = rel.slice(0, -ext.length);
|
|
55
|
-
return `export * from "../${base}
|
|
55
|
+
return `export * from "../${base}";`;
|
|
56
56
|
})
|
|
57
57
|
.join("\n");
|
|
58
58
|
|
|
@@ -1,28 +1,28 @@
|
|
|
1
|
-
import
|
|
1
|
+
import fsSync from "node:fs";
|
|
2
2
|
import fs from "node:fs/promises";
|
|
3
3
|
import path from "node:path";
|
|
4
|
-
import
|
|
4
|
+
import type { Client as LibSqlClient } from "@libsql/client";
|
|
5
5
|
import { sqliteFile } from "@/core/database/config";
|
|
6
|
+
import * as schema from "@/database/schema";
|
|
6
7
|
|
|
7
8
|
let databaseInstance: DrizzleDatabase | null = null;
|
|
8
9
|
let databaseClient: LibSqlClient | null = null;
|
|
9
10
|
|
|
10
11
|
export type DrizzleDatabase = import("drizzle-orm/libsql").LibSQLDatabase<typeof schema>;
|
|
11
12
|
|
|
12
|
-
function resolveMigrationsDir(): string {
|
|
13
|
+
async function resolveMigrationsDir(): Promise<string> {
|
|
13
14
|
try {
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
if (typeof e?.app?.getAppPath === "function") {
|
|
15
|
+
const e = (await import("electron").catch(() => null)) as any;
|
|
16
|
+
if (e?.app?.getAppPath) {
|
|
17
17
|
const dir = path.join(e.app.getAppPath(), "src", "database", "migrations", "sqlite");
|
|
18
|
-
if (
|
|
18
|
+
if (fsSync.existsSync(dir)) return dir;
|
|
19
19
|
}
|
|
20
20
|
} catch {}
|
|
21
21
|
// CLI/dev fallback: find project root
|
|
22
22
|
let dir = process.cwd();
|
|
23
23
|
for (let i = 0; i < 6; i++) {
|
|
24
24
|
const candidate = path.join(dir, "src", "database", "migrations", "sqlite");
|
|
25
|
-
if (
|
|
25
|
+
if (fsSync.existsSync(path.join(dir, "package.json"))) return candidate;
|
|
26
26
|
const parent = path.dirname(dir);
|
|
27
27
|
if (parent === dir) break;
|
|
28
28
|
dir = parent;
|
|
@@ -43,7 +43,7 @@ export async function initDatabase(): Promise<DrizzleDatabase> {
|
|
|
43
43
|
}
|
|
44
44
|
|
|
45
45
|
async function runBundledMigrations(): Promise<void> {
|
|
46
|
-
const folder = resolveMigrationsDir();
|
|
46
|
+
const folder = await resolveMigrationsDir();
|
|
47
47
|
let journal: { entries?: { tag: string }[] };
|
|
48
48
|
|
|
49
49
|
try {
|
|
@@ -99,7 +99,7 @@ export const db: DrizzleDatabase & {
|
|
|
99
99
|
if (property === "close") return closeDatabase;
|
|
100
100
|
const value = database()[property as keyof DrizzleDatabase];
|
|
101
101
|
return typeof value === "function" ? value.bind(database()) : value;
|
|
102
|
-
}
|
|
102
|
+
}
|
|
103
103
|
});
|
|
104
104
|
|
|
105
105
|
export function closeDatabase(): void {
|
|
@@ -111,4 +111,4 @@ export function closeDatabase(): void {
|
|
|
111
111
|
async function createFolderFor(filePath: string): Promise<void> {
|
|
112
112
|
const dir = path.dirname(filePath);
|
|
113
113
|
await fs.mkdir(dir, { recursive: true });
|
|
114
|
-
}
|
|
114
|
+
}
|
|
@@ -13,7 +13,7 @@
|
|
|
13
13
|
* await paginate.model({ table: schema.users, query: db.query.users });
|
|
14
14
|
*/
|
|
15
15
|
|
|
16
|
-
import { count, getTableColumns,
|
|
16
|
+
import { count, getTableColumns, type SQL, sql } from "drizzle-orm";
|
|
17
17
|
import type { SQLiteTable } from "drizzle-orm/sqlite-core";
|
|
18
18
|
import { db } from "@/core/facade";
|
|
19
19
|
|
|
@@ -51,14 +51,14 @@ export type PaginateTableOptions = PaginateInput & {
|
|
|
51
51
|
|
|
52
52
|
export type PaginateModelOptions<T = unknown> = PaginateInput & {
|
|
53
53
|
table?: SQLiteTable;
|
|
54
|
-
query?: { findMany: (args: Record<string, unknown>) => Promise<T[]
|
|
54
|
+
query?: { findMany: (args: Record<string, unknown>) => Promise<T[]> };
|
|
55
55
|
where?: SQL<unknown>;
|
|
56
56
|
with?: Record<string, unknown>;
|
|
57
57
|
columns?: Record<string, unknown>;
|
|
58
58
|
extras?: Record<string, unknown>;
|
|
59
59
|
orderBy?: unknown;
|
|
60
60
|
total?: () => Promise<number>;
|
|
61
|
-
data?: (params: { limit: number; offset: number
|
|
61
|
+
data?: (params: { limit: number; offset: number }) => Promise<T[]>;
|
|
62
62
|
};
|
|
63
63
|
|
|
64
64
|
function toPositiveInt(value: unknown, fallback: number): number {
|
|
@@ -97,14 +97,14 @@ export const paginate = {
|
|
|
97
97
|
},
|
|
98
98
|
|
|
99
99
|
/**
|
|
100
|
-
* nexgen-style pagination for Drizzle RELATIONAL queries - mirrors nexgen's
|
|
100
|
+
* nexgen-style pagination for Drizzle RELATIONAL queries - mirrors nexgen's
|
|
101
101
|
* paginateModel. Counts via `table` (+ `where`), then pages through
|
|
102
102
|
* `db.query.<table>.findMany({ limit, offset, where, with, columns, extras,
|
|
103
103
|
* orderBy })` for eager-loaded resources.
|
|
104
104
|
*/
|
|
105
105
|
model<T = unknown>(options: PaginateModelOptions<T>): Promise<PaginatedResult<T>> {
|
|
106
106
|
return paginateModel<T>(options);
|
|
107
|
-
}
|
|
107
|
+
}
|
|
108
108
|
};
|
|
109
109
|
|
|
110
110
|
/** Generic paginator for custom `total()`/`data(limit, offset)` callbacks. */
|
|
@@ -139,7 +139,7 @@ async function paginateQuery<T = unknown>(options: PaginateQueryOptions<T>): Pro
|
|
|
139
139
|
per_page: perPage,
|
|
140
140
|
prev_page_url: prevPageUrl,
|
|
141
141
|
to,
|
|
142
|
-
total
|
|
142
|
+
total
|
|
143
143
|
};
|
|
144
144
|
}
|
|
145
145
|
|
|
@@ -163,7 +163,7 @@ function paginateTable<T = unknown>(table: SQLiteTable, options: PaginateTableOp
|
|
|
163
163
|
if (options.where) dataQuery = dataQuery.where(options.where);
|
|
164
164
|
if (options.orderBy?.length) dataQuery = dataQuery.orderBy(...options.orderBy);
|
|
165
165
|
return dataQuery.limit(limit).offset(offset);
|
|
166
|
-
}
|
|
166
|
+
}
|
|
167
167
|
});
|
|
168
168
|
}
|
|
169
169
|
|
|
@@ -215,10 +215,10 @@ function paginateModel<T = unknown>(options: PaginateModelOptions<T>): Promise<P
|
|
|
215
215
|
if (options.extras) args.extras = options.extras;
|
|
216
216
|
if (options.orderBy) args.orderBy = options.orderBy;
|
|
217
217
|
return options.query.findMany(args);
|
|
218
|
-
}
|
|
218
|
+
}
|
|
219
219
|
});
|
|
220
220
|
}
|
|
221
221
|
|
|
222
222
|
// `sql` is re-exported so callers writing `where: sql` filters don't need a
|
|
223
223
|
// second drizzle import: import { paginate, sql } from "@/core/facade.ts".
|
|
224
|
-
export { sql };
|
|
224
|
+
export { sql };
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { sqliteFile } from "@/core/database/config";
|
|
2
1
|
import fs from "node:fs";
|
|
3
2
|
import path from "node:path";
|
|
3
|
+
import { sqliteFile } from "@/core/database/config";
|
|
4
4
|
|
|
5
5
|
const raw = sqliteFile();
|
|
6
6
|
const file = path.resolve(process.cwd(), raw);
|
|
@@ -16,4 +16,4 @@ try {
|
|
|
16
16
|
console.error(error);
|
|
17
17
|
process.exit(1);
|
|
18
18
|
}
|
|
19
|
-
}
|
|
19
|
+
}
|
|
@@ -75,9 +75,7 @@ function moduleNameOf(file: string): string {
|
|
|
75
75
|
const moduleArg = process.argv.find((arg) => arg.startsWith("--module="));
|
|
76
76
|
const moduleName = moduleArg?.split("=")[1]?.trim();
|
|
77
77
|
|
|
78
|
-
const seedFiles = moduleName
|
|
79
|
-
? discoverSeederFiles().filter((f) => moduleNameOf(f) === moduleName)
|
|
80
|
-
: discoverSeederFiles();
|
|
78
|
+
const seedFiles = moduleName ? discoverSeederFiles().filter((f) => moduleNameOf(f) === moduleName) : discoverSeederFiles();
|
|
81
79
|
|
|
82
80
|
await db.init();
|
|
83
81
|
|
|
@@ -94,7 +92,7 @@ try {
|
|
|
94
92
|
module: moduleNameOf(file),
|
|
95
93
|
execute: () => mod.default(),
|
|
96
94
|
tableName: table?.[NAME_SYMBOL] as string | undefined,
|
|
97
|
-
dependsOn: table ? getTableDeps(table) : []
|
|
95
|
+
dependsOn: table ? getTableDeps(table) : []
|
|
98
96
|
});
|
|
99
97
|
}
|
|
100
98
|
|
|
@@ -166,4 +164,4 @@ try {
|
|
|
166
164
|
console.log(`Executed ${sorted.length} seeder file(s)${moduleName ? ` for module ${moduleName}` : ""}`);
|
|
167
165
|
} finally {
|
|
168
166
|
await db.close();
|
|
169
|
-
}
|
|
167
|
+
}
|
|
@@ -6,7 +6,10 @@ const MIGRATION_DIR = path.join(process.cwd(), "src", "database", "migrations",
|
|
|
6
6
|
|
|
7
7
|
export function listMigrations(dir = MIGRATION_DIR): string[] {
|
|
8
8
|
try {
|
|
9
|
-
return fs
|
|
9
|
+
return fs
|
|
10
|
+
.readdirSync(dir)
|
|
11
|
+
.filter((name) => name.endsWith(".sql"))
|
|
12
|
+
.sort();
|
|
10
13
|
} catch {
|
|
11
14
|
return [];
|
|
12
15
|
}
|
package/template/src/core/env.ts
CHANGED
|
@@ -85,7 +85,7 @@ export function loadEnv(): string | null {
|
|
|
85
85
|
electronApp?.isPackaged ? dirname(electronApp.getPath("exe")) : undefined,
|
|
86
86
|
base,
|
|
87
87
|
electronApp?.getAppPath ? electronApp.getAppPath() : undefined,
|
|
88
|
-
resolve(process.cwd())
|
|
88
|
+
resolve(process.cwd())
|
|
89
89
|
].filter((dir): dir is string => Boolean(dir) && dir.length > 0);
|
|
90
90
|
|
|
91
91
|
for (const dir of [...new Set(candidates)]) {
|
|
@@ -35,8 +35,10 @@ export { type CronHandle, cron } from "@/core/utils/scheduler";
|
|
|
35
35
|
export { type Disk, type FileData, files, storage } from "@/core/utils/storage";
|
|
36
36
|
// Validation (zod schemas + runner: `validate.z`, `validate.run`)
|
|
37
37
|
export { validate } from "@/core/utils/validation";
|
|
38
|
-
// Native Windows file/folder pickers (Explorer-style Open / Save As / folder)
|
|
38
|
+
// Native Windows file/folder pickers and message dialogs (Explorer-style Open / Save As / folder, confirm/alert)
|
|
39
39
|
export {
|
|
40
|
+
alertDialog,
|
|
41
|
+
confirmDialog,
|
|
40
42
|
type PickFolderOptions,
|
|
41
43
|
type PickOpenOptions,
|
|
42
44
|
type PickSaveOptions,
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { runScript } from "@/core/maker/db/helpers
|
|
2
|
-
import { migrate } from "@/core/maker/db/migrate
|
|
1
|
+
import { runScript } from "@/core/maker/db/helpers";
|
|
2
|
+
import { migrate } from "@/core/maker/db/migrate";
|
|
3
3
|
|
|
4
4
|
/** db:fresh - reset DB, then generate, migrate, hooks; seed only with --seed. */
|
|
5
5
|
export async function fresh(seed = false): Promise<void> {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { generateMigrations, generateSchema } from "@/core/maker/db/helpers
|
|
1
|
+
import { generateMigrations, generateSchema } from "@/core/maker/db/helpers";
|
|
2
2
|
|
|
3
3
|
/** db:schema - regenerate src/database/schema.ts from all models. */
|
|
4
4
|
export async function schema(): Promise<void> {
|
|
@@ -6,8 +6,8 @@ import {
|
|
|
6
6
|
migrationCount,
|
|
7
7
|
runDrizzle,
|
|
8
8
|
runScript,
|
|
9
|
-
runSeedScript
|
|
10
|
-
} from "@/core/maker/db/helpers
|
|
9
|
+
runSeedScript
|
|
10
|
+
} from "@/core/maker/db/helpers";
|
|
11
11
|
|
|
12
12
|
/** db:migrate - generate+run migrations, apply hooks, seed only with --seed. */
|
|
13
13
|
export async function migrate(seed = false): Promise<void> {
|
|
@@ -19,7 +19,7 @@ export async function migrate(seed = false): Promise<void> {
|
|
|
19
19
|
throw new Error(
|
|
20
20
|
"Initial migration was generated, but the database already contains tables. " +
|
|
21
21
|
"This usually means migration files were deleted while DB data still exists. " +
|
|
22
|
-
"Use 'db:fresh --seed' to rebuild locally, or restore migration files before running db:migrate."
|
|
22
|
+
"Use 'db:fresh --seed' to rebuild locally, or restore migration files before running db:migrate."
|
|
23
23
|
);
|
|
24
24
|
}
|
|
25
25
|
await runDrizzle(["migrate"]);
|
|
@@ -33,4 +33,3 @@ export async function migrateRun(): Promise<void> {
|
|
|
33
33
|
await runDrizzle(["migrate"]);
|
|
34
34
|
await runScript("src/core/database/migrate-hooks.ts");
|
|
35
35
|
}
|
|
36
|
-
|
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
import { spawnSync } from "node:child_process";
|
|
2
2
|
import path from "node:path";
|
|
3
3
|
import { fileURLToPath } from "node:url";
|
|
4
|
-
import
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
9
|
-
import {
|
|
10
|
-
import {
|
|
11
|
-
import {
|
|
12
|
-
import {
|
|
4
|
+
import { fresh } from "@/core/maker/db/fresh";
|
|
5
|
+
import { generate, schema } from "@/core/maker/db/generate";
|
|
6
|
+
import { migrate, migrateRun } from "@/core/maker/db/migrate";
|
|
7
|
+
import { migrateModule } from "@/core/maker/db/module-migrate";
|
|
8
|
+
import { check, push, studio } from "@/core/maker/db/push";
|
|
9
|
+
import { reset } from "@/core/maker/db/reset";
|
|
10
|
+
import { seed } from "@/core/maker/db/seed";
|
|
11
|
+
import { status } from "@/core/maker/db/status";
|
|
12
|
+
import type { CommandDef } from "@/core/maker/help";
|
|
13
13
|
|
|
14
14
|
const __dirname = path.dirname(fileURLToPath(import.meta.url));
|
|
15
15
|
const ROOT = path.resolve(__dirname, "..", "..", "..", "..");
|
|
@@ -20,7 +20,10 @@ function regenerateBindings(): void {
|
|
|
20
20
|
const args = ["--yes", "tsx", "--tsconfig", "tsconfig.json", "src/core/api/generate.manifest.ts"];
|
|
21
21
|
const isWin = process.platform === "win32";
|
|
22
22
|
const r = spawnSync(isWin ? "cmd.exe" : cmd, isWin ? ["/d", "/s", "/c", cmd, ...args] : args, {
|
|
23
|
-
cwd: ROOT,
|
|
23
|
+
cwd: ROOT,
|
|
24
|
+
stdio: "inherit",
|
|
25
|
+
shell: false,
|
|
26
|
+
env: process.env
|
|
24
27
|
});
|
|
25
28
|
if (r.status !== 0) process.exit(r.status ?? 1);
|
|
26
29
|
}
|
|
@@ -36,23 +39,49 @@ const G = "Database";
|
|
|
36
39
|
|
|
37
40
|
export function registerDbCommands(register: (cmd: CommandDef) => void): void {
|
|
38
41
|
register({ name: "db:schema", group: G, description: "Regenerate src/database/schema.ts from all models", action: () => schema() });
|
|
39
|
-
register({ name: "db:generate", group: G, description: "Regenerate schema and create migration SQL (drizzle-kit)", action: () => generate() });
|
|
40
42
|
register({
|
|
41
|
-
name: "db:
|
|
43
|
+
name: "db:generate",
|
|
44
|
+
group: G,
|
|
45
|
+
description: "Regenerate schema and create migration SQL (drizzle-kit)",
|
|
46
|
+
action: () => generate()
|
|
47
|
+
});
|
|
48
|
+
register({
|
|
49
|
+
name: "db:migrate",
|
|
50
|
+
usage: "[--seed]",
|
|
51
|
+
group: G,
|
|
42
52
|
description: "Generate + run migrations, apply hooks (seed with --seed)",
|
|
43
|
-
action: (flags) => withBindings(() => migrate(Boolean(flags.seed)))()
|
|
53
|
+
action: (flags) => withBindings(() => migrate(Boolean(flags.seed)))()
|
|
44
54
|
});
|
|
45
|
-
register({ name: "db:migrate:run", group: G, description: "Run existing migrations + model hooks (no seed)", action: () => withBindings(migrateRun)() });
|
|
46
55
|
register({
|
|
47
|
-
name: "db:migrate:
|
|
56
|
+
name: "db:migrate:run",
|
|
57
|
+
group: G,
|
|
58
|
+
description: "Run existing migrations + model hooks (no seed)",
|
|
59
|
+
action: () => withBindings(migrateRun)()
|
|
60
|
+
});
|
|
61
|
+
register({
|
|
62
|
+
name: "db:migrate:module",
|
|
63
|
+
usage: "<module> [--keep-temp]",
|
|
64
|
+
group: G,
|
|
48
65
|
description: "Generate + run migrations for one module's models",
|
|
49
66
|
action: (flags, args) => {
|
|
50
67
|
if (!args[0]) throw new Error("Module name is required.");
|
|
51
68
|
return withBindings(() => migrateModule(args[0], Boolean(flags["keep-temp"])))();
|
|
52
|
-
}
|
|
69
|
+
}
|
|
70
|
+
});
|
|
71
|
+
register({
|
|
72
|
+
name: "db:fresh",
|
|
73
|
+
usage: "[--seed]",
|
|
74
|
+
group: G,
|
|
75
|
+
description: "Reset DB, then generate, migrate, hooks (seed with --seed)",
|
|
76
|
+
action: (flags) => withBindings(() => fresh(Boolean(flags.seed)))()
|
|
77
|
+
});
|
|
78
|
+
register({
|
|
79
|
+
name: "db:seed",
|
|
80
|
+
usage: "[--module <module>]",
|
|
81
|
+
group: G,
|
|
82
|
+
description: "Run seeders (all, or one module; auto FK-ordered)",
|
|
83
|
+
action: (flags) => withBindings(() => seed(typeof flags.module === "string" ? flags.module : undefined))()
|
|
53
84
|
});
|
|
54
|
-
register({ name: "db:fresh", usage: "[--seed]", group: G, description: "Reset DB, then generate, migrate, hooks (seed with --seed)", action: (flags) => withBindings(() => fresh(Boolean(flags.seed)))() });
|
|
55
|
-
register({ name: "db:seed", usage: "[--module <module>]", group: G, description: "Run seeders (all, or one module; auto FK-ordered)", action: (flags) => withBindings(() => seed(typeof flags.module === "string" ? flags.module : undefined))() });
|
|
56
85
|
register({ name: "db:status", group: G, description: "List generated migration files", action: () => status() });
|
|
57
86
|
register({ name: "db:push", group: G, description: "Push schema directly (drizzle-kit push)", action: () => push() });
|
|
58
87
|
register({ name: "db:check", group: G, description: "Run drizzle-kit check", action: () => check() });
|
|
@@ -60,4 +89,3 @@ export function registerDbCommands(register: (cmd: CommandDef) => void): void {
|
|
|
60
89
|
register({ name: "db:reset", group: G, description: "Delete the SQLite database file", action: () => reset() });
|
|
61
90
|
register({ name: "db:wipe", group: G, description: "Delete the SQLite database file", action: () => reset() });
|
|
62
91
|
}
|
|
63
|
-
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import fs from "node:fs";
|
|
2
2
|
import path from "node:path";
|
|
3
|
-
import { ensureMigrationMeta, migrationCount, PROJECT_ROOT, runDrizzle } from "
|
|
3
|
+
import { ensureMigrationMeta, migrationCount, PROJECT_ROOT, runDrizzle } from "@/core/maker/db/helpers";
|
|
4
4
|
|
|
5
5
|
const MODULES_PATH = path.join(PROJECT_ROOT, "src", "modules");
|
|
6
6
|
|
|
@@ -10,9 +10,7 @@ function moduleModels(moduleName: string): string[] {
|
|
|
10
10
|
try {
|
|
11
11
|
entries = fs.readdirSync(modelsDir, { withFileTypes: true });
|
|
12
12
|
} catch {
|
|
13
|
-
throw new Error(
|
|
14
|
-
`Module does not exist: ${moduleName}. Create it first with: npm run maker -- make:module ${moduleName}`,
|
|
15
|
-
);
|
|
13
|
+
throw new Error(`Module does not exist: ${moduleName}. Create it first with: npm run maker -- make:module ${moduleName}`);
|
|
16
14
|
}
|
|
17
15
|
const files = entries
|
|
18
16
|
.filter((e) => e.isFile() && (e.name.endsWith(".ts") || e.name.endsWith(".tsx")))
|
|
@@ -41,13 +39,16 @@ export async function migrateModule(moduleName: string, keepTemp = false): Promi
|
|
|
41
39
|
await ensureMigrationMeta();
|
|
42
40
|
const tmpPath = await writeModuleSchemaTemp(moduleName);
|
|
43
41
|
const schemaEnv = {
|
|
44
|
-
DRIZZLE_SCHEMA: `./${path.relative(PROJECT_ROOT, tmpPath).replaceAll("\\", "/")}
|
|
42
|
+
DRIZZLE_SCHEMA: `./${path.relative(PROJECT_ROOT, tmpPath).replaceAll("\\", "/")}`
|
|
45
43
|
};
|
|
46
44
|
try {
|
|
47
45
|
await runDrizzle(["generate", ...(migrationCount() === 0 ? ["--name", "init"] : [])], schemaEnv);
|
|
48
46
|
await runDrizzle(["migrate"], schemaEnv);
|
|
49
47
|
console.log(`Module migration complete: ${moduleName}`);
|
|
50
48
|
} finally {
|
|
51
|
-
if (!keepTemp)
|
|
49
|
+
if (!keepTemp)
|
|
50
|
+
try {
|
|
51
|
+
fs.unlinkSync(tmpPath);
|
|
52
|
+
} catch {}
|
|
52
53
|
}
|
|
53
54
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { generateSchema, runSeedScript } from "@/core/maker/db/helpers
|
|
1
|
+
import { generateSchema, runSeedScript } from "@/core/maker/db/helpers";
|
|
2
2
|
|
|
3
3
|
/** db:seed - run all seeders (auto FK-ordered), or one module's seeders. */
|
|
4
4
|
export async function seed(module?: string): Promise<void> {
|