@niyamulahsan/create-deskapp 1.2.2 → 1.2.4
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 +1 -1
- package/template/.env +1 -1
- package/template/package.json +1 -2
- package/template/src/config/winsetup.ts +1 -1
- 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/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 +1 -3
- package/template/src/preload.ts +1 -1
- package/template/src/window/app-menu.ts +6 -0
- package/template/src/window/context-menu.ts +7 -0
- package/template/src/window/manager.ts +31 -3
- package/template/src/window/native.ts +8 -3
- package/template/src/window/tray.ts +64 -13
- package/template/src/ui/src/plugins/gum.ts.bak +0 -683
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=
|
package/template/package.json
CHANGED
|
@@ -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)]) {
|
|
@@ -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> {
|
|
@@ -11,18 +11,12 @@ const WORDMARK = [
|
|
|
11
11
|
" | _ \\| ____/ ___|| |/ / / \\ | _ \\| _ \\ ",
|
|
12
12
|
" | | | | _| \\___ \\| ' / / _ \\ | |_) | |_) |",
|
|
13
13
|
" | |_| | |___ ___) | . \\ / ___ \\| __/| __/ ",
|
|
14
|
-
" |____/|_____|____/|_|\\_\\/_/ \\_\\_| |_| "
|
|
14
|
+
" |____/|_____|____/|_|\\_\\/_/ \\_\\_| |_| "
|
|
15
15
|
];
|
|
16
16
|
|
|
17
|
-
const LOGO =
|
|
17
|
+
const LOGO = `\n${WORDMARK.join("\n")}\n`;
|
|
18
18
|
|
|
19
|
-
const GROUP_ORDER = [
|
|
20
|
-
"Getting started",
|
|
21
|
-
"Generators - modules",
|
|
22
|
-
"Database",
|
|
23
|
-
"Build & codegen",
|
|
24
|
-
"Testing",
|
|
25
|
-
];
|
|
19
|
+
const GROUP_ORDER = ["Getting started", "Generators - modules", "Database", "Build & codegen", "Testing"];
|
|
26
20
|
|
|
27
21
|
function padRows(rows: Array<{ left: string; desc: string }>): string[] {
|
|
28
22
|
if (!rows.length) return [];
|
|
@@ -32,8 +26,8 @@ function padRows(rows: Array<{ left: string; desc: string }>): string[] {
|
|
|
32
26
|
|
|
33
27
|
export function printCommandHelp(cmd: CommandDef): void {
|
|
34
28
|
console.log(LOGO);
|
|
35
|
-
console.log(`Usage: npm run maker -- ${cmd.name}${cmd.usage ?
|
|
36
|
-
console.log(cmd.description
|
|
29
|
+
console.log(`Usage: npm run maker -- ${cmd.name}${cmd.usage ? ` ${cmd.usage}` : ""} [options]\n`);
|
|
30
|
+
console.log(`${cmd.description}\n`);
|
|
37
31
|
}
|
|
38
32
|
|
|
39
33
|
export function printHelp(commands: Map<string, CommandDef>): void {
|
|
@@ -50,10 +44,7 @@ export function printHelp(commands: Map<string, CommandDef>): void {
|
|
|
50
44
|
}
|
|
51
45
|
for (const arr of byGroup.values()) arr.sort((a, b) => a.name.localeCompare(b.name));
|
|
52
46
|
|
|
53
|
-
const groups = [
|
|
54
|
-
...GROUP_ORDER.filter((g) => byGroup.has(g)),
|
|
55
|
-
...[...byGroup.keys()].filter((g) => !GROUP_ORDER.includes(g)),
|
|
56
|
-
];
|
|
47
|
+
const groups = [...GROUP_ORDER.filter((g) => byGroup.has(g)), ...[...byGroup.keys()].filter((g) => !GROUP_ORDER.includes(g))];
|
|
57
48
|
for (const group of groups) {
|
|
58
49
|
const rows = (byGroup.get(group) || []).map((c) => ({ left: c.name, desc: c.description }));
|
|
59
50
|
if (!rows.length) continue;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import path from "node:path";
|
|
2
|
-
import type { MakerOptions } from "
|
|
3
|
-
import { assertModuleExists, assertName, controllerContent, moduleDir, schemaContent, writeFile } from "
|
|
2
|
+
import type { MakerOptions } from "@/core/maker/make/helpers";
|
|
3
|
+
import { assertModuleExists, assertName, controllerContent, moduleDir, schemaContent, writeFile } from "@/core/maker/make/helpers";
|
|
4
4
|
|
|
5
5
|
export function makeController(module: string, name: string, options: MakerOptions = {}): void {
|
|
6
6
|
const moduleName = assertName(module, "Module name");
|
|
@@ -11,17 +11,12 @@ export function makeController(module: string, name: string, options: MakerOptio
|
|
|
11
11
|
path.join(controllersDir, `${controllerName}.controller.ts`),
|
|
12
12
|
controllerContent(moduleName, controllerName),
|
|
13
13
|
options,
|
|
14
|
-
"Controller file"
|
|
15
|
-
);
|
|
16
|
-
writeFile(
|
|
17
|
-
path.join(controllersDir, `${controllerName}.schema.ts`),
|
|
18
|
-
schemaContent(moduleName, controllerName),
|
|
19
|
-
options,
|
|
20
|
-
"Schema file",
|
|
14
|
+
"Controller file"
|
|
21
15
|
);
|
|
16
|
+
writeFile(path.join(controllersDir, `${controllerName}.schema.ts`), schemaContent(moduleName, controllerName), options, "Schema file");
|
|
22
17
|
if (!options.dryRun) {
|
|
23
18
|
console.log(
|
|
24
|
-
"Handlers are registered as `<module>.<name>.<handler>` via src/core/api/bindings.generated.ts. Run `npm run maker -- bindings:gen` then rebuild/restart Electron."
|
|
19
|
+
"Handlers are registered as `<module>.<name>.<handler>` via src/core/api/bindings.generated.ts. Run `npm run maker -- bindings:gen` then rebuild/restart Electron."
|
|
25
20
|
);
|
|
26
21
|
}
|
|
27
22
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import fs from "node:fs";
|
|
2
2
|
import path from "node:path";
|
|
3
3
|
import { fileURLToPath } from "node:url";
|
|
4
|
-
import { loadStub } from "
|
|
4
|
+
import { loadStub } from "@/core/maker/stub";
|
|
5
5
|
|
|
6
6
|
export interface MakerOptions {
|
|
7
7
|
force?: boolean;
|
|
@@ -32,9 +32,7 @@ export function moduleDir(moduleName: string): string {
|
|
|
32
32
|
export function assertModuleExists(moduleName: string): void {
|
|
33
33
|
const dir = moduleDir(moduleName);
|
|
34
34
|
if (!fs.existsSync(dir) || !fs.statSync(dir).isDirectory()) {
|
|
35
|
-
throw new Error(
|
|
36
|
-
`Module does not exist: ${moduleName}. Create it first with: npm run maker -- make:module ${moduleName}`,
|
|
37
|
-
);
|
|
35
|
+
throw new Error(`Module does not exist: ${moduleName}. Create it first with: npm run maker -- make:module ${moduleName}`);
|
|
38
36
|
}
|
|
39
37
|
}
|
|
40
38
|
|
|
@@ -59,7 +57,7 @@ export function modelContent(module: string, name: string): string {
|
|
|
59
57
|
tableVariable: `${name}s`,
|
|
60
58
|
ClassName,
|
|
61
59
|
name,
|
|
62
|
-
module
|
|
60
|
+
module
|
|
63
61
|
});
|
|
64
62
|
}
|
|
65
63
|
|
|
@@ -70,7 +68,7 @@ export function seederContent(module: string, name: string): string {
|
|
|
70
68
|
name,
|
|
71
69
|
ClassName,
|
|
72
70
|
tableName: `${name}s`,
|
|
73
|
-
tableVariable: `${name}s
|
|
71
|
+
tableVariable: `${name}s`
|
|
74
72
|
});
|
|
75
73
|
}
|
|
76
74
|
|
|
@@ -79,7 +77,7 @@ export function controllerContent(module: string, name: string): string {
|
|
|
79
77
|
return loadStub("controller/controller.controller.stub", {
|
|
80
78
|
module,
|
|
81
79
|
controller: name,
|
|
82
|
-
ClassName
|
|
80
|
+
ClassName
|
|
83
81
|
});
|
|
84
82
|
}
|
|
85
83
|
|
|
@@ -88,6 +86,6 @@ export function schemaContent(module: string, name: string): string {
|
|
|
88
86
|
return loadStub("controller/controller.schema.stub", {
|
|
89
87
|
module,
|
|
90
88
|
controller: name,
|
|
91
|
-
ClassName
|
|
89
|
+
ClassName
|
|
92
90
|
});
|
|
93
91
|
}
|