@niyamulahsan/create-deskapp 0.0.0-stage → 1.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +49 -2
- package/bin/create.js +136 -0
- package/package.json +14 -4
- package/template/.env +13 -0
- package/template/.env.example +13 -0
- package/template/.vscode/extensions.json +6 -0
- package/template/.vscode/settings.json +37 -0
- package/template/LICENSE +21 -0
- package/template/README.md +29 -0
- package/template/biome.json +99 -0
- package/template/drizzle.config.ts +32 -0
- package/template/gitignore-stub +19 -0
- package/template/package.json +111 -0
- package/template/scripts/build-electron.mjs +55 -0
- package/template/scripts/dev-electron.mjs +53 -0
- package/template/scripts/installer.nsh +14 -0
- package/template/src/config/app.ts +24 -0
- package/template/src/core/api/bindings.generated.ts +23 -0
- package/template/src/core/api/generate.manifest.ts +86 -0
- package/template/src/core/api/registry.ts +48 -0
- package/template/src/core/config.ts +99 -0
- package/template/src/core/database/aggregate.ts +85 -0
- package/template/src/core/database/config.ts +48 -0
- package/template/src/core/database/connection.ts +114 -0
- package/template/src/core/database/migrate-hooks.ts +84 -0
- package/template/src/core/database/paginate.ts +224 -0
- package/template/src/core/database/reset.ts +19 -0
- package/template/src/core/database/seed.ts +169 -0
- package/template/src/core/database/status.ts +32 -0
- package/template/src/core/env.ts +106 -0
- package/template/src/core/facade.ts +59 -0
- package/template/src/core/maker/db/fresh.ts +8 -0
- package/template/src/core/maker/db/generate.ts +11 -0
- package/template/src/core/maker/db/helpers.ts +96 -0
- package/template/src/core/maker/db/migrate.ts +36 -0
- package/template/src/core/maker/db/mod.ts +63 -0
- package/template/src/core/maker/db/module-migrate.ts +53 -0
- package/template/src/core/maker/db/push.ts +21 -0
- package/template/src/core/maker/db/reset.ts +6 -0
- package/template/src/core/maker/db/seed.ts +7 -0
- package/template/src/core/maker/db/status.ts +6 -0
- package/template/src/core/maker/help.ts +66 -0
- package/template/src/core/maker/make/controller.ts +27 -0
- package/template/src/core/maker/make/helpers.ts +93 -0
- package/template/src/core/maker/make/mod.ts +68 -0
- package/template/src/core/maker/make/model.ts +14 -0
- package/template/src/core/maker/make/module.ts +62 -0
- package/template/src/core/maker/make/seeder.ts +21 -0
- package/template/src/core/maker/make/test.ts +30 -0
- package/template/src/core/maker/mod.ts +83 -0
- package/template/src/core/maker/run/mod.ts +112 -0
- package/template/src/core/maker/stub.ts +24 -0
- package/template/src/core/maker/stubs/controller/controller.controller.stub +55 -0
- package/template/src/core/maker/stubs/controller/controller.schema.stub +13 -0
- package/template/src/core/maker/stubs/model/model.stub +8 -0
- package/template/src/core/maker/stubs/seeder/seeder.stub +16 -0
- package/template/src/core/maker/stubs/test/test.stub +7 -0
- package/template/src/core/maker/sync-config.ts +94 -0
- package/template/src/core/utils/password.ts +27 -0
- package/template/src/core/utils/playwright.ts +121 -0
- package/template/src/core/utils/queue.ts +59 -0
- package/template/src/core/utils/scheduler.ts +70 -0
- package/template/src/core/utils/storage.ts +599 -0
- package/template/src/core/utils/validation.ts +35 -0
- package/template/src/database/migrations/sqlite/meta/_journal.json +1 -0
- package/template/src/database/schema.ts +6 -0
- package/template/src/icons/apple-touch-icon.png +0 -0
- package/template/src/icons/deskapp.png +0 -0
- package/template/src/icons/favicon-96x96.png +0 -0
- package/template/src/icons/favicon.ico +0 -0
- package/template/src/icons/favicon.svg +1 -0
- package/template/src/icons/site.webmanifest +21 -0
- package/template/src/icons/tray.png +0 -0
- package/template/src/icons/web-app-manifest-192x192.png +0 -0
- package/template/src/icons/web-app-manifest-512x512.png +0 -0
- package/template/src/main.ts +116 -0
- package/template/src/modules/app/controllers/demo.controller.ts +118 -0
- package/template/src/modules/app/controllers/net.controller.ts +48 -0
- package/template/src/modules/app/controllers/playwright.controller.ts +140 -0
- package/template/src/modules/app/controllers/storage.controller.ts +229 -0
- package/template/src/modules/app/controllers/window.controller.ts +107 -0
- package/template/src/preload.ts +35 -0
- package/template/src/storage/.gitkeep +1 -0
- package/template/src/storage/app/private/.gitkeep +1 -0
- package/template/src/storage/app/private/samples/.gitkeep +1 -0
- package/template/src/storage/app/private/samples/state.json +5 -0
- package/template/src/storage/app/private/uploads/.gitkeep +1 -0
- package/template/src/storage/app/public/.gitkeep +1 -0
- package/template/src/storage/app/tmp/generated/.gitkeep +1 -0
- package/template/src/storage/logs/.gitkeep +0 -0
- package/template/src/storage/logs/app.log +0 -0
- package/template/src/storage/logs/fatal.log +0 -0
- package/template/src/ui/.vscode/extensions.json +3 -0
- package/template/src/ui/index.html +14 -0
- package/template/src/ui/public/icons.svg +24 -0
- package/template/src/ui/src/App.vue +3 -0
- package/template/src/ui/src/app.ts +23 -0
- package/template/src/ui/src/assets/fonts/public-sans/public-sans-latin-ext.woff2 +0 -0
- package/template/src/ui/src/assets/fonts/public-sans/public-sans-latin.woff2 +0 -0
- package/template/src/ui/src/assets/images/deskapp.png +0 -0
- package/template/src/ui/src/assets/images/favicon/favicon.ico +0 -0
- package/template/src/ui/src/assets/scss/custom.scss +186 -0
- package/template/src/ui/src/bindings.d.ts +16 -0
- package/template/src/ui/src/components/Button.vue +32 -0
- package/template/src/ui/src/components/Checkbox.vue +29 -0
- package/template/src/ui/src/components/Input.vue +227 -0
- package/template/src/ui/src/components/Modal.vue +55 -0
- package/template/src/ui/src/components/Spinner.vue +42 -0
- package/template/src/ui/src/components/Switch.vue +65 -0
- package/template/src/ui/src/components/TextArea.vue +121 -0
- package/template/src/ui/src/components/Toast.vue +56 -0
- package/template/src/ui/src/components/datatable/DataTableSkeleton.vue +98 -0
- package/template/src/ui/src/components/datatable/Pagination.vue +125 -0
- package/template/src/ui/src/components/datatable/SelectOpption.vue +35 -0
- package/template/src/ui/src/components/datatable/index.vue +258 -0
- package/template/src/ui/src/env.d.ts +13 -0
- package/template/src/ui/src/global.d.ts +35 -0
- package/template/src/ui/src/helpers/nformatter.ts +10 -0
- package/template/src/ui/src/pages/dashboard/index.vue +687 -0
- package/template/src/ui/src/plugins/gum.ts +549 -0
- package/template/src/ui/src/plugins/gum.ts.bak +683 -0
- package/template/src/ui/src/plugins/pulse.ts +148 -0
- package/template/src/ui/src/router/index.ts +25 -0
- package/template/src/ui/src/stores/example.ts +27 -0
- package/template/src/ui/tsconfig.json +15 -0
- package/template/src/ui/vite.config.ts +38 -0
- package/template/src/window/config.ts +71 -0
- package/template/src/window/dialogs.ts +67 -0
- package/template/src/window/manager.ts +139 -0
- package/template/src/window/native.ts +215 -0
- package/template/tsconfig.json +22 -0
- package/template/vitest.config.ts +34 -0
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
import { spawnSync } from "node:child_process";
|
|
2
|
+
import fs from "node:fs";
|
|
3
|
+
import path from "node:path";
|
|
4
|
+
import { DatabaseSync } from "node:sqlite";
|
|
5
|
+
import { fileURLToPath } from "node:url";
|
|
6
|
+
import { sqliteFile } from "@/core/database/config";
|
|
7
|
+
|
|
8
|
+
const __dirname = path.dirname(fileURLToPath(import.meta.url));
|
|
9
|
+
// src/core/maker/db -> project root
|
|
10
|
+
export const PROJECT_ROOT = path.resolve(__dirname, "..", "..", "..", "..");
|
|
11
|
+
|
|
12
|
+
function envFileArgs(): string[] {
|
|
13
|
+
const envPath = path.join(PROJECT_ROOT, ".env");
|
|
14
|
+
return fs.existsSync(envPath) ? ["--env-file=.env"] : [];
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
function run(cmd: string, args: string[], env: Record<string, string> = {}): void {
|
|
18
|
+
const isWin = process.platform === "win32";
|
|
19
|
+
const r = spawnSync(isWin ? "cmd.exe" : cmd, isWin ? ["/d", "/s", "/c", cmd, ...args] : args, {
|
|
20
|
+
cwd: PROJECT_ROOT,
|
|
21
|
+
stdio: "inherit",
|
|
22
|
+
shell: false,
|
|
23
|
+
env: { ...process.env, ...env },
|
|
24
|
+
});
|
|
25
|
+
if (r.error) throw r.error;
|
|
26
|
+
if (r.status !== 0) process.exit(r.status ?? 1);
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/** Run a TS script via tsx (supports @/ aliases and TS). */
|
|
30
|
+
export async function runScript(scriptPath: string, extra: string[] = []): Promise<void> {
|
|
31
|
+
run("npx", ["--yes", "tsx", "--tsconfig", "tsconfig.json", ...envFileArgs(), scriptPath, ...extra]);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/** Run drizzle-kit with the given CLI args. */
|
|
35
|
+
export async function runDrizzle(args: string[], env: Record<string, string> = {}): Promise<void> {
|
|
36
|
+
run("npx", ["--yes", "drizzle-kit", ...args], env);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export function migrationCount(): number {
|
|
40
|
+
const dir = path.join(PROJECT_ROOT, "src", "database", "migrations", "sqlite");
|
|
41
|
+
let count = 0;
|
|
42
|
+
try {
|
|
43
|
+
for (const entry of fs.readdirSync(dir, { withFileTypes: true })) {
|
|
44
|
+
if (entry.isFile() && entry.name.endsWith(".sql")) count++;
|
|
45
|
+
}
|
|
46
|
+
} catch {}
|
|
47
|
+
return count;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
export async function generateSchema(): Promise<void> {
|
|
51
|
+
await runScript("src/core/database/aggregate.ts");
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
export async function generateMigrations(): Promise<void> {
|
|
55
|
+
await generateSchema();
|
|
56
|
+
await runDrizzle(["generate", ...(migrationCount() === 0 ? ["--name", "init"] : [])]);
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
export async function runSeedScript(module?: string): Promise<void> {
|
|
60
|
+
await runScript("src/core/database/seed.ts", module ? [`--module=${module}`] : []);
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
export async function ensureMigrationMeta(): Promise<void> {
|
|
64
|
+
const metaRoot = path.join(PROJECT_ROOT, "src", "database", "migrations", "sqlite", "meta");
|
|
65
|
+
const journalPath = path.join(metaRoot, "_journal.json");
|
|
66
|
+
fs.mkdirSync(metaRoot, { recursive: true });
|
|
67
|
+
if (!fs.existsSync(journalPath)) {
|
|
68
|
+
fs.writeFileSync(
|
|
69
|
+
journalPath,
|
|
70
|
+
`{\n "version": "7",\n "dialect": "sqlite",\n "entries": []\n}\n`,
|
|
71
|
+
"utf8",
|
|
72
|
+
);
|
|
73
|
+
console.log(`[db:migrate] created migration journal: ${journalPath}`);
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
export async function hasExistingAppTables(): Promise<boolean> {
|
|
78
|
+
try {
|
|
79
|
+
const raw = sqliteFile();
|
|
80
|
+
const file = path.isAbsolute(raw) ? raw : path.resolve(PROJECT_ROOT, raw);
|
|
81
|
+
if (!fs.existsSync(file)) return false;
|
|
82
|
+
const instance = new DatabaseSync(file);
|
|
83
|
+
try {
|
|
84
|
+
const rows = instance
|
|
85
|
+
.prepare(
|
|
86
|
+
"SELECT name FROM sqlite_master WHERE type='table' AND name NOT LIKE 'sqlite_%' AND name != '__drizzle_migrations'",
|
|
87
|
+
)
|
|
88
|
+
.all() as unknown[];
|
|
89
|
+
return rows.length > 0;
|
|
90
|
+
} finally {
|
|
91
|
+
instance.close();
|
|
92
|
+
}
|
|
93
|
+
} catch {
|
|
94
|
+
return false;
|
|
95
|
+
}
|
|
96
|
+
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import {
|
|
2
|
+
ensureMigrationMeta,
|
|
3
|
+
generateMigrations,
|
|
4
|
+
generateSchema,
|
|
5
|
+
hasExistingAppTables,
|
|
6
|
+
migrationCount,
|
|
7
|
+
runDrizzle,
|
|
8
|
+
runScript,
|
|
9
|
+
runSeedScript,
|
|
10
|
+
} from "@/core/maker/db/helpers.ts";
|
|
11
|
+
|
|
12
|
+
/** db:migrate - generate+run migrations, apply hooks, seed only with --seed. */
|
|
13
|
+
export async function migrate(seed = false): Promise<void> {
|
|
14
|
+
await ensureMigrationMeta();
|
|
15
|
+
const hadMigrationsBeforeGenerate = migrationCount() > 0;
|
|
16
|
+
const hadExistingTablesBeforeGenerate = await hasExistingAppTables();
|
|
17
|
+
await generateMigrations();
|
|
18
|
+
if (!hadMigrationsBeforeGenerate && hadExistingTablesBeforeGenerate) {
|
|
19
|
+
throw new Error(
|
|
20
|
+
"Initial migration was generated, but the database already contains tables. " +
|
|
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.",
|
|
23
|
+
);
|
|
24
|
+
}
|
|
25
|
+
await runDrizzle(["migrate"]);
|
|
26
|
+
await runScript("src/core/database/migrate-hooks.ts");
|
|
27
|
+
if (seed) await runSeedScript();
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/** db:migrate:run - run existing migrations + model hooks (no generate, no seed). */
|
|
31
|
+
export async function migrateRun(): Promise<void> {
|
|
32
|
+
await generateSchema();
|
|
33
|
+
await runDrizzle(["migrate"]);
|
|
34
|
+
await runScript("src/core/database/migrate-hooks.ts");
|
|
35
|
+
}
|
|
36
|
+
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import { spawnSync } from "node:child_process";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
import { fileURLToPath } from "node:url";
|
|
4
|
+
import type { CommandDef } from "../help";
|
|
5
|
+
import { check, push, studio } from "./push";
|
|
6
|
+
import { fresh } from "./fresh";
|
|
7
|
+
import { generate, schema } from "./generate";
|
|
8
|
+
import { migrate, migrateRun } from "./migrate";
|
|
9
|
+
import { migrateModule } from "./module-migrate";
|
|
10
|
+
import { reset } from "./reset";
|
|
11
|
+
import { seed } from "./seed";
|
|
12
|
+
import { status } from "./status";
|
|
13
|
+
|
|
14
|
+
const __dirname = path.dirname(fileURLToPath(import.meta.url));
|
|
15
|
+
const ROOT = path.resolve(__dirname, "..", "..", "..", "..");
|
|
16
|
+
|
|
17
|
+
function regenerateBindings(): void {
|
|
18
|
+
console.log(`== bindings:gen (pre-db) ==`);
|
|
19
|
+
const cmd = "npx";
|
|
20
|
+
const args = ["--yes", "tsx", "--tsconfig", "tsconfig.json", "src/core/api/generate.manifest.ts"];
|
|
21
|
+
const isWin = process.platform === "win32";
|
|
22
|
+
const r = spawnSync(isWin ? "cmd.exe" : cmd, isWin ? ["/d", "/s", "/c", cmd, ...args] : args, {
|
|
23
|
+
cwd: ROOT, stdio: "inherit", shell: false, env: process.env,
|
|
24
|
+
});
|
|
25
|
+
if (r.status !== 0) process.exit(r.status ?? 1);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
function withBindings(action: () => Promise<void>): () => Promise<void> {
|
|
29
|
+
return async () => {
|
|
30
|
+
regenerateBindings();
|
|
31
|
+
await action();
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
const G = "Database";
|
|
36
|
+
|
|
37
|
+
export function registerDbCommands(register: (cmd: CommandDef) => void): void {
|
|
38
|
+
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
|
+
register({
|
|
41
|
+
name: "db:migrate", usage: "[--seed]", group: G,
|
|
42
|
+
description: "Generate + run migrations, apply hooks (seed with --seed)",
|
|
43
|
+
action: (flags) => withBindings(() => migrate(Boolean(flags.seed)))(),
|
|
44
|
+
});
|
|
45
|
+
register({ name: "db:migrate:run", group: G, description: "Run existing migrations + model hooks (no seed)", action: () => withBindings(migrateRun)() });
|
|
46
|
+
register({
|
|
47
|
+
name: "db:migrate:module", usage: "<module> [--keep-temp]", group: G,
|
|
48
|
+
description: "Generate + run migrations for one module's models",
|
|
49
|
+
action: (flags, args) => {
|
|
50
|
+
if (!args[0]) throw new Error("Module name is required.");
|
|
51
|
+
return withBindings(() => migrateModule(args[0], Boolean(flags["keep-temp"])))();
|
|
52
|
+
},
|
|
53
|
+
});
|
|
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
|
+
register({ name: "db:status", group: G, description: "List generated migration files", action: () => status() });
|
|
57
|
+
register({ name: "db:push", group: G, description: "Push schema directly (drizzle-kit push)", action: () => push() });
|
|
58
|
+
register({ name: "db:check", group: G, description: "Run drizzle-kit check", action: () => check() });
|
|
59
|
+
register({ name: "db:studio", group: G, description: "Open Drizzle Studio", action: () => studio() });
|
|
60
|
+
register({ name: "db:reset", group: G, description: "Delete the SQLite database file", action: () => reset() });
|
|
61
|
+
register({ name: "db:wipe", group: G, description: "Delete the SQLite database file", action: () => reset() });
|
|
62
|
+
}
|
|
63
|
+
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import fs from "node:fs";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
import { ensureMigrationMeta, migrationCount, PROJECT_ROOT, runDrizzle } from "./helpers";
|
|
4
|
+
|
|
5
|
+
const MODULES_PATH = path.join(PROJECT_ROOT, "src", "modules");
|
|
6
|
+
|
|
7
|
+
function moduleModels(moduleName: string): string[] {
|
|
8
|
+
const modelsDir = path.join(MODULES_PATH, moduleName, "database", "models");
|
|
9
|
+
let entries: fs.Dirent[];
|
|
10
|
+
try {
|
|
11
|
+
entries = fs.readdirSync(modelsDir, { withFileTypes: true });
|
|
12
|
+
} catch {
|
|
13
|
+
throw new Error(
|
|
14
|
+
`Module does not exist: ${moduleName}. Create it first with: npm run maker -- make:module ${moduleName}`,
|
|
15
|
+
);
|
|
16
|
+
}
|
|
17
|
+
const files = entries
|
|
18
|
+
.filter((e) => e.isFile() && (e.name.endsWith(".ts") || e.name.endsWith(".tsx")))
|
|
19
|
+
.map((e) => path.join(modelsDir, e.name))
|
|
20
|
+
.sort();
|
|
21
|
+
if (!files.length) throw new Error(`No model files found for module '${moduleName}'.`);
|
|
22
|
+
return files;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
async function writeModuleSchemaTemp(moduleName: string): Promise<string> {
|
|
26
|
+
const tmpDir = path.join(PROJECT_ROOT, "src", "storage", "tmp");
|
|
27
|
+
fs.mkdirSync(tmpDir, { recursive: true });
|
|
28
|
+
const tmpPath = path.join(tmpDir, `schema.${moduleName}.${Date.now()}.ts`);
|
|
29
|
+
const exports = moduleModels(moduleName)
|
|
30
|
+
.map((file) => {
|
|
31
|
+
const rel = path.relative(tmpDir, file).replaceAll("\\", "/");
|
|
32
|
+
const importPath = rel.startsWith(".") ? rel : `./${rel}`;
|
|
33
|
+
return `export * from "${importPath}";`;
|
|
34
|
+
})
|
|
35
|
+
.join("\n");
|
|
36
|
+
fs.writeFileSync(tmpPath, `${exports}\n`, "utf8");
|
|
37
|
+
return tmpPath;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
export async function migrateModule(moduleName: string, keepTemp = false): Promise<void> {
|
|
41
|
+
await ensureMigrationMeta();
|
|
42
|
+
const tmpPath = await writeModuleSchemaTemp(moduleName);
|
|
43
|
+
const schemaEnv = {
|
|
44
|
+
DRIZZLE_SCHEMA: `./${path.relative(PROJECT_ROOT, tmpPath).replaceAll("\\", "/")}`,
|
|
45
|
+
};
|
|
46
|
+
try {
|
|
47
|
+
await runDrizzle(["generate", ...(migrationCount() === 0 ? ["--name", "init"] : [])], schemaEnv);
|
|
48
|
+
await runDrizzle(["migrate"], schemaEnv);
|
|
49
|
+
console.log(`Module migration complete: ${moduleName}`);
|
|
50
|
+
} finally {
|
|
51
|
+
if (!keepTemp) try { fs.unlinkSync(tmpPath); } catch {}
|
|
52
|
+
}
|
|
53
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { generateSchema, runDrizzle } from "@/core/maker/db/helpers.ts";
|
|
2
|
+
|
|
3
|
+
async function withSchema(args: string[]): Promise<void> {
|
|
4
|
+
await generateSchema();
|
|
5
|
+
await runDrizzle(args);
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
/** db:push - push schema directly to the database. */
|
|
9
|
+
export async function push(): Promise<void> {
|
|
10
|
+
await withSchema(["push"]);
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
/** db:check - run drizzle-kit check. */
|
|
14
|
+
export async function check(): Promise<void> {
|
|
15
|
+
await withSchema(["check"]);
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
/** db:studio - open Drizzle Studio. */
|
|
19
|
+
export async function studio(): Promise<void> {
|
|
20
|
+
await withSchema(["studio"]);
|
|
21
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { generateSchema, runSeedScript } from "@/core/maker/db/helpers.ts";
|
|
2
|
+
|
|
3
|
+
/** db:seed - run all seeders (auto FK-ordered), or one module's seeders. */
|
|
4
|
+
export async function seed(module?: string): Promise<void> {
|
|
5
|
+
await generateSchema();
|
|
6
|
+
await runSeedScript(module);
|
|
7
|
+
}
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
export interface CommandDef {
|
|
2
|
+
name: string;
|
|
3
|
+
usage?: string;
|
|
4
|
+
description: string;
|
|
5
|
+
group: string;
|
|
6
|
+
action: (flags: Record<string, string | boolean>, args: string[]) => void | Promise<void>;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
const WORDMARK = [
|
|
10
|
+
" ____ _____ ____ _ __ _ ____ ____ ",
|
|
11
|
+
" | _ \\| ____/ ___|| |/ / / \\ | _ \\| _ \\ ",
|
|
12
|
+
" | | | | _| \\___ \\| ' / / _ \\ | |_) | |_) |",
|
|
13
|
+
" | |_| | |___ ___) | . \\ / ___ \\| __/| __/ ",
|
|
14
|
+
" |____/|_____|____/|_|\\_\\/_/ \\_\\_| |_| ",
|
|
15
|
+
];
|
|
16
|
+
|
|
17
|
+
const LOGO = "\n" + WORDMARK.join("\n") + "\n";
|
|
18
|
+
|
|
19
|
+
const GROUP_ORDER = [
|
|
20
|
+
"Getting started",
|
|
21
|
+
"Generators - modules",
|
|
22
|
+
"Database",
|
|
23
|
+
"Build & codegen",
|
|
24
|
+
"Testing",
|
|
25
|
+
];
|
|
26
|
+
|
|
27
|
+
function padRows(rows: Array<{ left: string; desc: string }>): string[] {
|
|
28
|
+
if (!rows.length) return [];
|
|
29
|
+
const w = Math.max(...rows.map((r) => r.left.length));
|
|
30
|
+
return rows.map((r) => ` ${r.left.padEnd(w)} ${r.desc}`);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export function printCommandHelp(cmd: CommandDef): void {
|
|
34
|
+
console.log(LOGO);
|
|
35
|
+
console.log(`Usage: npm run maker -- ${cmd.name}${cmd.usage ? " " + cmd.usage : ""} [options]\n`);
|
|
36
|
+
console.log(cmd.description + "\n");
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export function printHelp(commands: Map<string, CommandDef>): void {
|
|
40
|
+
console.log(LOGO);
|
|
41
|
+
console.log("Usage: npm run maker -- [options] [command]\n");
|
|
42
|
+
console.log("Options:");
|
|
43
|
+
console.log(" -h, --help display help for command\n");
|
|
44
|
+
|
|
45
|
+
const byGroup = new Map<string, CommandDef[]>();
|
|
46
|
+
for (const cmd of commands.values()) {
|
|
47
|
+
const g = cmd.group || "Other";
|
|
48
|
+
if (!byGroup.has(g)) byGroup.set(g, []);
|
|
49
|
+
byGroup.get(g)!.push(cmd);
|
|
50
|
+
}
|
|
51
|
+
for (const arr of byGroup.values()) arr.sort((a, b) => a.name.localeCompare(b.name));
|
|
52
|
+
|
|
53
|
+
const groups = [
|
|
54
|
+
...GROUP_ORDER.filter((g) => byGroup.has(g)),
|
|
55
|
+
...[...byGroup.keys()].filter((g) => !GROUP_ORDER.includes(g)),
|
|
56
|
+
];
|
|
57
|
+
for (const group of groups) {
|
|
58
|
+
const rows = (byGroup.get(group) || []).map((c) => ({ left: c.name, desc: c.description }));
|
|
59
|
+
if (!rows.length) continue;
|
|
60
|
+
console.log(`${group}:`);
|
|
61
|
+
for (const line of padRows(rows)) console.log(line);
|
|
62
|
+
console.log("");
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
console.log("Run `npm run maker -- <command> --help` for command details.");
|
|
66
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import path from "node:path";
|
|
2
|
+
import type { MakerOptions } from "./helpers";
|
|
3
|
+
import { assertModuleExists, assertName, controllerContent, moduleDir, schemaContent, writeFile } from "./helpers";
|
|
4
|
+
|
|
5
|
+
export function makeController(module: string, name: string, options: MakerOptions = {}): void {
|
|
6
|
+
const moduleName = assertName(module, "Module name");
|
|
7
|
+
const controllerName = assertName(name, "Controller name");
|
|
8
|
+
assertModuleExists(moduleName);
|
|
9
|
+
const controllersDir = path.join(moduleDir(moduleName), "controllers");
|
|
10
|
+
writeFile(
|
|
11
|
+
path.join(controllersDir, `${controllerName}.controller.ts`),
|
|
12
|
+
controllerContent(moduleName, controllerName),
|
|
13
|
+
options,
|
|
14
|
+
"Controller file",
|
|
15
|
+
);
|
|
16
|
+
writeFile(
|
|
17
|
+
path.join(controllersDir, `${controllerName}.schema.ts`),
|
|
18
|
+
schemaContent(moduleName, controllerName),
|
|
19
|
+
options,
|
|
20
|
+
"Schema file",
|
|
21
|
+
);
|
|
22
|
+
if (!options.dryRun) {
|
|
23
|
+
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.",
|
|
25
|
+
);
|
|
26
|
+
}
|
|
27
|
+
}
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
import fs from "node:fs";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
import { fileURLToPath } from "node:url";
|
|
4
|
+
import { loadStub } from "../stub";
|
|
5
|
+
|
|
6
|
+
export interface MakerOptions {
|
|
7
|
+
force?: boolean;
|
|
8
|
+
dryRun?: boolean;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
const __dirname = path.dirname(fileURLToPath(import.meta.url));
|
|
12
|
+
// src/core/maker/make -> project root
|
|
13
|
+
export const PROJECT_ROOT = path.resolve(__dirname, "..", "..", "..", "..");
|
|
14
|
+
|
|
15
|
+
export function assertName(value: string, label: string): string {
|
|
16
|
+
if (!value) throw new Error(`${label} is required.`);
|
|
17
|
+
return value.trim().toLowerCase();
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export function pascal(input: string): string {
|
|
21
|
+
return input.replace(/(^\w|[-_]\w)/g, (part) => part.replace(/[-_]/g, "").toUpperCase());
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export function modulesRoot(): string {
|
|
25
|
+
return path.join(PROJECT_ROOT, "src", "modules");
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export function moduleDir(moduleName: string): string {
|
|
29
|
+
return path.join(modulesRoot(), moduleName);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export function assertModuleExists(moduleName: string): void {
|
|
33
|
+
const dir = moduleDir(moduleName);
|
|
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
|
+
);
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
export function writeFile(filePath: string, content: string, options: MakerOptions, label: string): void {
|
|
42
|
+
const target = path.resolve(filePath);
|
|
43
|
+
if (options.dryRun) {
|
|
44
|
+
console.log(`[dry-run] would write ${label}: ${target}`);
|
|
45
|
+
return;
|
|
46
|
+
}
|
|
47
|
+
if (fs.existsSync(target) && !options.force) {
|
|
48
|
+
throw new Error(`${label} already exists: ${target}. Re-run with --force to overwrite.`);
|
|
49
|
+
}
|
|
50
|
+
fs.mkdirSync(path.dirname(target), { recursive: true });
|
|
51
|
+
fs.writeFileSync(target, content, "utf8");
|
|
52
|
+
console.log(`${label} ready: ${target}`);
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
export function modelContent(module: string, name: string): string {
|
|
56
|
+
const ClassName = pascal(name);
|
|
57
|
+
return loadStub("model/model.stub", {
|
|
58
|
+
tableName: `${name}s`,
|
|
59
|
+
tableVariable: `${name}s`,
|
|
60
|
+
ClassName,
|
|
61
|
+
name,
|
|
62
|
+
module,
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
export function seederContent(module: string, name: string): string {
|
|
67
|
+
const ClassName = pascal(name);
|
|
68
|
+
return loadStub("seeder/seeder.stub", {
|
|
69
|
+
module,
|
|
70
|
+
name,
|
|
71
|
+
ClassName,
|
|
72
|
+
tableName: `${name}s`,
|
|
73
|
+
tableVariable: `${name}s`,
|
|
74
|
+
});
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
export function controllerContent(module: string, name: string): string {
|
|
78
|
+
const ClassName = pascal(name);
|
|
79
|
+
return loadStub("controller/controller.controller.stub", {
|
|
80
|
+
module,
|
|
81
|
+
controller: name,
|
|
82
|
+
ClassName,
|
|
83
|
+
});
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
export function schemaContent(module: string, name: string): string {
|
|
87
|
+
const ClassName = pascal(name);
|
|
88
|
+
return loadStub("controller/controller.schema.stub", {
|
|
89
|
+
module,
|
|
90
|
+
controller: name,
|
|
91
|
+
ClassName,
|
|
92
|
+
});
|
|
93
|
+
}
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import type { CommandDef } from "../help";
|
|
2
|
+
import type { MakerOptions } from "./helpers";
|
|
3
|
+
import { makeController } from "./controller";
|
|
4
|
+
import { makeModule } from "./module";
|
|
5
|
+
import { makeModel } from "./model";
|
|
6
|
+
import { makeSeeder } from "./seeder";
|
|
7
|
+
import { makeTest } from "./test";
|
|
8
|
+
|
|
9
|
+
const GROUP = "Generators - modules";
|
|
10
|
+
|
|
11
|
+
function opts(flags: Record<string, string | boolean>): MakerOptions {
|
|
12
|
+
return { force: Boolean(flags.force), dryRun: Boolean(flags["dry-run"] ?? flags.dryRun) };
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
function need(args: string[], i: number, label: string): string {
|
|
16
|
+
const v = args[i];
|
|
17
|
+
if (!v) throw new Error(`${label} is required.`);
|
|
18
|
+
return v;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export function registerMakeCommands(register: (cmd: CommandDef) => void): void {
|
|
22
|
+
register({
|
|
23
|
+
name: "make:module",
|
|
24
|
+
usage: "<name> [--force]",
|
|
25
|
+
group: GROUP,
|
|
26
|
+
description: "Create a module with model, seeder, controller + schema",
|
|
27
|
+
action: (flags, args) => makeModule(need(args, 0, "Module name"), opts(flags)),
|
|
28
|
+
});
|
|
29
|
+
register({
|
|
30
|
+
name: "make:controller",
|
|
31
|
+
usage: "<module> <name> [--force] [--dry-run]",
|
|
32
|
+
group: GROUP,
|
|
33
|
+
description: "Generate a controller + schema for an existing module",
|
|
34
|
+
action: (flags, args) => makeController(need(args, 0, "Module name"), need(args, 1, "Controller name"), opts(flags)),
|
|
35
|
+
});
|
|
36
|
+
register({
|
|
37
|
+
name: "make:model",
|
|
38
|
+
usage: "<module> <name> [--force] [--dry-run]",
|
|
39
|
+
group: GROUP,
|
|
40
|
+
description: "Generate a model file for an existing module",
|
|
41
|
+
action: (flags, args) => makeModel(need(args, 0, "Module name"), need(args, 1, "Model name"), opts(flags)),
|
|
42
|
+
});
|
|
43
|
+
register({
|
|
44
|
+
name: "make:seeder",
|
|
45
|
+
usage: "<module> <name> [--force] [--dry-run]",
|
|
46
|
+
group: GROUP,
|
|
47
|
+
description: "Generate a seeder for an existing module model",
|
|
48
|
+
action: (flags, args) => makeSeeder(need(args, 0, "Module name"), need(args, 1, "Seeder name"), opts(flags)),
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
const testAction = (flags: Record<string, string | boolean>, args: string[]) =>
|
|
52
|
+
makeTest(need(args, 0, "Module name"), args[1], opts(flags));
|
|
53
|
+
register({
|
|
54
|
+
name: "make:test",
|
|
55
|
+
usage: "<module> [name] [--force] [--dry-run]",
|
|
56
|
+
group: GROUP,
|
|
57
|
+
description: "Generate a Vitest file in src/modules/<module>/__tests__",
|
|
58
|
+
action: testAction,
|
|
59
|
+
});
|
|
60
|
+
register({
|
|
61
|
+
name: "module:make-test",
|
|
62
|
+
usage: "<module> [name] [--force] [--dry-run]",
|
|
63
|
+
group: GROUP,
|
|
64
|
+
description: "Alias for make:test (Nexwire-style)",
|
|
65
|
+
action: testAction,
|
|
66
|
+
});
|
|
67
|
+
}
|
|
68
|
+
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import path from "node:path";
|
|
2
|
+
import type { MakerOptions } from "./helpers";
|
|
3
|
+
import { assertModuleExists, assertName, modelContent, moduleDir, writeFile } from "./helpers";
|
|
4
|
+
|
|
5
|
+
export function makeModel(module: string, name: string, options: MakerOptions = {}): void {
|
|
6
|
+
const moduleName = assertName(module, "Module name");
|
|
7
|
+
const modelName = assertName(name, "Model name");
|
|
8
|
+
assertModuleExists(moduleName);
|
|
9
|
+
const filePath = path.join(moduleDir(moduleName), "database", "models", `${modelName}.model.ts`);
|
|
10
|
+
writeFile(filePath, modelContent(moduleName, modelName), options, "Model file");
|
|
11
|
+
if (!options.dryRun) {
|
|
12
|
+
console.log(`Next: \`npm run maker -- db:generate\` (or \`db:migrate\`) to include '${modelName}' in the schema.`);
|
|
13
|
+
}
|
|
14
|
+
}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import fs from "node:fs";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
import type { MakerOptions } from "./helpers";
|
|
4
|
+
import {
|
|
5
|
+
assertName,
|
|
6
|
+
controllerContent,
|
|
7
|
+
modelContent,
|
|
8
|
+
modulesRoot,
|
|
9
|
+
schemaContent,
|
|
10
|
+
seederContent,
|
|
11
|
+
writeFile,
|
|
12
|
+
} from "./helpers";
|
|
13
|
+
|
|
14
|
+
export function makeModule(name: string, options: MakerOptions = {}): void {
|
|
15
|
+
const moduleName = assertName(name, "Module name");
|
|
16
|
+
const root = path.join(modulesRoot(), moduleName);
|
|
17
|
+
const exists = fs.existsSync(root) && fs.statSync(root).isDirectory();
|
|
18
|
+
if (exists && !options.force) throw new Error(`Module already exists: ${moduleName}.`);
|
|
19
|
+
|
|
20
|
+
if (options.dryRun) {
|
|
21
|
+
console.log(`[dry-run] would create module: ${path.resolve(root)}`);
|
|
22
|
+
console.log(`[dry-run] - database/models/${moduleName}.model.ts`);
|
|
23
|
+
console.log(`[dry-run] - database/seeders/${moduleName}.seed.ts`);
|
|
24
|
+
console.log(`[dry-run] - controllers/${moduleName}.controller.ts`);
|
|
25
|
+
console.log(`[dry-run] - controllers/${moduleName}.schema.ts`);
|
|
26
|
+
return;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
fs.mkdirSync(path.join(root, "database", "models"), { recursive: true });
|
|
30
|
+
fs.mkdirSync(path.join(root, "database", "seeders"), { recursive: true });
|
|
31
|
+
fs.mkdirSync(path.join(root, "controllers"), { recursive: true });
|
|
32
|
+
|
|
33
|
+
writeFile(
|
|
34
|
+
path.join(root, "database", "models", `${moduleName}.model.ts`),
|
|
35
|
+
modelContent(moduleName, moduleName),
|
|
36
|
+
options,
|
|
37
|
+
"Model file",
|
|
38
|
+
);
|
|
39
|
+
writeFile(
|
|
40
|
+
path.join(root, "database", "seeders", `${moduleName}.seed.ts`),
|
|
41
|
+
seederContent(moduleName, moduleName),
|
|
42
|
+
options,
|
|
43
|
+
"Seeder file",
|
|
44
|
+
);
|
|
45
|
+
writeFile(
|
|
46
|
+
path.join(root, "controllers", `${moduleName}.controller.ts`),
|
|
47
|
+
controllerContent(moduleName, moduleName),
|
|
48
|
+
options,
|
|
49
|
+
"Controller file",
|
|
50
|
+
);
|
|
51
|
+
writeFile(
|
|
52
|
+
path.join(root, "controllers", `${moduleName}.schema.ts`),
|
|
53
|
+
schemaContent(moduleName, moduleName),
|
|
54
|
+
options,
|
|
55
|
+
"Schema file",
|
|
56
|
+
);
|
|
57
|
+
|
|
58
|
+
console.log(`Module ready: ${path.resolve(root)}`);
|
|
59
|
+
console.log("Database files: database/models/{name}.model.ts, database/seeders/{name}.seed.ts");
|
|
60
|
+
console.log("Controller + schema: controllers/{name}.controller.ts, controllers/{name}.schema.ts");
|
|
61
|
+
console.log("Next: `npm run maker -- db:generate` (or `db:migrate`), then `npm run maker -- bindings:gen` and rebuild Electron.");
|
|
62
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import fs from "node:fs";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
import type { MakerOptions } from "./helpers";
|
|
4
|
+
import { assertModuleExists, assertName, moduleDir, seederContent, writeFile } from "./helpers";
|
|
5
|
+
|
|
6
|
+
export function makeSeeder(module: string, name: string, options: MakerOptions = {}): void {
|
|
7
|
+
const moduleName = assertName(module, "Module name");
|
|
8
|
+
const seederName = assertName(name, "Seeder name");
|
|
9
|
+
assertModuleExists(moduleName);
|
|
10
|
+
const modelPath = path.join(moduleDir(moduleName), "database", "models", `${seederName}.model.ts`);
|
|
11
|
+
if (!fs.existsSync(modelPath) || !fs.statSync(modelPath).isFile()) {
|
|
12
|
+
throw new Error(
|
|
13
|
+
`Model not found for seeder: src/modules/${moduleName}/database/models/${seederName}.model.ts. Create it first with: npm run maker -- make:model ${moduleName} ${seederName}`,
|
|
14
|
+
);
|
|
15
|
+
}
|
|
16
|
+
const filePath = path.join(moduleDir(moduleName), "database", "seeders", `${seederName}.seed.ts`);
|
|
17
|
+
writeFile(filePath, seederContent(moduleName, seederName), options, "Seeder file");
|
|
18
|
+
if (!options.dryRun) {
|
|
19
|
+
console.log("Fills seed values from parent FKs manually; ordering is resolved automatically by the seeder runner.");
|
|
20
|
+
}
|
|
21
|
+
}
|