@niyamulahsan/create-deskapp 1.2.5 → 1.2.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (104) hide show
  1. package/package.json +1 -1
  2. package/template/.env.example +20 -13
  3. package/template/AGENTS.md +699 -0
  4. package/template/package.json +3 -0
  5. package/template/src/config/app.ts +26 -24
  6. package/template/src/config/winsetup.ts +93 -91
  7. package/template/src/core/api/binding-error.ts +57 -0
  8. package/template/src/core/api/bindings.generated.ts +2 -0
  9. package/template/src/core/api/generate.manifest.ts +84 -80
  10. package/template/src/core/api/registry.ts +58 -48
  11. package/template/src/core/config.ts +101 -99
  12. package/template/src/core/database/aggregate.ts +89 -85
  13. package/template/src/core/database/config.ts +50 -48
  14. package/template/src/core/database/connection.ts +116 -114
  15. package/template/src/core/database/migrate-hooks.ts +86 -84
  16. package/template/src/core/database/paginate.ts +226 -224
  17. package/template/src/core/database/reset.ts +21 -19
  18. package/template/src/core/database/seed.ts +169 -167
  19. package/template/src/core/database/status.ts +37 -35
  20. package/template/src/core/env.ts +108 -106
  21. package/template/src/core/facade.ts +63 -61
  22. package/template/src/core/maker/db/fresh.ts +10 -8
  23. package/template/src/core/maker/db/generate.ts +13 -11
  24. package/template/src/core/maker/db/helpers.ts +92 -96
  25. package/template/src/core/maker/db/migrate.ts +37 -35
  26. package/template/src/core/maker/db/mod.ts +93 -91
  27. package/template/src/core/maker/db/module-migrate.ts +56 -54
  28. package/template/src/core/maker/db/push.ts +23 -21
  29. package/template/src/core/maker/db/reset.ts +8 -6
  30. package/template/src/core/maker/db/seed.ts +9 -7
  31. package/template/src/core/maker/db/status.ts +8 -6
  32. package/template/src/core/maker/help.ts +59 -57
  33. package/template/src/core/maker/make/controller.ts +25 -22
  34. package/template/src/core/maker/make/helpers.ts +97 -91
  35. package/template/src/core/maker/make/mod.ts +69 -67
  36. package/template/src/core/maker/make/model.ts +16 -14
  37. package/template/src/core/maker/make/module.ts +53 -39
  38. package/template/src/core/maker/make/seeder.ts +23 -21
  39. package/template/src/core/maker/make/test.ts +33 -30
  40. package/template/src/core/maker/mod.ts +85 -83
  41. package/template/src/core/maker/run/mod.ts +134 -132
  42. package/template/src/core/maker/stub.ts +26 -24
  43. package/template/src/core/maker/stubs/controller/controller.controller.stub +57 -55
  44. package/template/src/core/maker/stubs/controller/controller.schema.stub +18 -13
  45. package/template/src/core/maker/stubs/facade/facade.stub +21 -0
  46. package/template/src/core/maker/stubs/model/model.stub +10 -8
  47. package/template/src/core/maker/stubs/seeder/seeder.stub +18 -16
  48. package/template/src/core/maker/stubs/test/test.stub +9 -7
  49. package/template/src/core/maker/sync-config.ts +93 -94
  50. package/template/src/core/utils/password.ts +29 -27
  51. package/template/src/core/utils/playwright.ts +123 -121
  52. package/template/src/core/utils/queue.ts +68 -66
  53. package/template/src/core/utils/scheduler.ts +62 -60
  54. package/template/src/core/utils/storage.ts +3 -1
  55. package/template/src/core/utils/validation.ts +37 -35
  56. package/template/src/database/schema.ts +2 -0
  57. package/template/src/main.ts +120 -118
  58. package/template/src/modules/app/__tests__/demo.controller.test.ts +75 -0
  59. package/template/src/modules/app/__tests__/net.controller.test.ts +65 -0
  60. package/template/src/modules/app/__tests__/playwright.controller.test.ts +50 -0
  61. package/template/src/modules/app/__tests__/storage.controller.test.ts +114 -0
  62. package/template/src/modules/app/__tests__/window.controller.test.ts +98 -0
  63. package/template/src/modules/app/controllers/demo.controller.ts +120 -118
  64. package/template/src/modules/app/controllers/net.controller.ts +50 -48
  65. package/template/src/modules/app/controllers/playwright.controller.ts +142 -140
  66. package/template/src/modules/app/controllers/storage.controller.ts +231 -229
  67. package/template/src/modules/app/controllers/window.controller.ts +2 -0
  68. package/template/src/modules/app/facade.ts +21 -0
  69. package/template/src/preload.ts +25 -2
  70. package/template/src/ui/src/App.vue +4 -2
  71. package/template/src/ui/src/app.ts +38 -23
  72. package/template/src/ui/src/bindings.d.ts +18 -16
  73. package/template/src/ui/src/components/Button.vue +34 -32
  74. package/template/src/ui/src/components/Checkbox.vue +26 -29
  75. package/template/src/ui/src/components/Input.vue +221 -227
  76. package/template/src/ui/src/components/InputGroup.vue +141 -0
  77. package/template/src/ui/src/components/InputPasswordToggle.vue +204 -0
  78. package/template/src/ui/src/components/Modal.vue +65 -55
  79. package/template/src/ui/src/components/Spinner.vue +44 -42
  80. package/template/src/ui/src/components/Switch.vue +62 -65
  81. package/template/src/ui/src/components/TextArea.vue +108 -121
  82. package/template/src/ui/src/components/Toast.vue +55 -56
  83. package/template/src/ui/src/components/datatable/DataTableSkeleton.vue +100 -98
  84. package/template/src/ui/src/components/datatable/Pagination.vue +153 -125
  85. package/template/src/ui/src/components/datatable/SelectOpption.vue +36 -35
  86. package/template/src/ui/src/components/datatable/index.vue +336 -258
  87. package/template/src/ui/src/env.d.ts +16 -13
  88. package/template/src/ui/src/global.d.ts +21 -2
  89. package/template/src/ui/src/helpers/nformatter.ts +12 -10
  90. package/template/src/ui/src/pages/dashboard/index.vue +690 -687
  91. package/template/src/ui/src/plugins/browserDetect.ts +57 -0
  92. package/template/src/ui/src/plugins/gum.ts +576 -549
  93. package/template/src/ui/src/plugins/pulse.ts +2 -0
  94. package/template/src/ui/src/plugins/routeProgress.ts +89 -0
  95. package/template/src/ui/src/router/index.ts +44 -25
  96. package/template/src/ui/src/stores/example.ts +2 -0
  97. package/template/src/ui/vite.config.ts +40 -38
  98. package/template/src/window/app-menu.ts +89 -87
  99. package/template/src/window/config.ts +14 -12
  100. package/template/src/window/context-menu.ts +23 -21
  101. package/template/src/window/dialogs.ts +92 -90
  102. package/template/src/window/manager.ts +2 -0
  103. package/template/src/window/native.ts +47 -45
  104. package/template/src/window/tray.ts +132 -130
@@ -1,54 +1,56 @@
1
- import fs from "node:fs";
2
- import path from "node:path";
3
- import { ensureMigrationMeta, migrationCount, PROJECT_ROOT, runDrizzle } from "@/core/maker/db/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(`Module does not exist: ${moduleName}. Create it first with: npm run maker -- make:module ${moduleName}`);
14
- }
15
- const files = entries
16
- .filter((e) => e.isFile() && (e.name.endsWith(".ts") || e.name.endsWith(".tsx")))
17
- .map((e) => path.join(modelsDir, e.name))
18
- .sort();
19
- if (!files.length) throw new Error(`No model files found for module '${moduleName}'.`);
20
- return files;
21
- }
22
-
23
- async function writeModuleSchemaTemp(moduleName: string): Promise<string> {
24
- const tmpDir = path.join(PROJECT_ROOT, "src", "storage", "tmp");
25
- fs.mkdirSync(tmpDir, { recursive: true });
26
- const tmpPath = path.join(tmpDir, `schema.${moduleName}.${Date.now()}.ts`);
27
- const exports = moduleModels(moduleName)
28
- .map((file) => {
29
- const rel = path.relative(tmpDir, file).replaceAll("\\", "/");
30
- const importPath = rel.startsWith(".") ? rel : `./${rel}`;
31
- return `export * from "${importPath}";`;
32
- })
33
- .join("\n");
34
- fs.writeFileSync(tmpPath, `${exports}\n`, "utf8");
35
- return tmpPath;
36
- }
37
-
38
- export async function migrateModule(moduleName: string, keepTemp = false): Promise<void> {
39
- await ensureMigrationMeta();
40
- const tmpPath = await writeModuleSchemaTemp(moduleName);
41
- const schemaEnv = {
42
- DRIZZLE_SCHEMA: `./${path.relative(PROJECT_ROOT, tmpPath).replaceAll("\\", "/")}`
43
- };
44
- try {
45
- await runDrizzle(["generate", ...(migrationCount() === 0 ? ["--name", "init"] : [])], schemaEnv);
46
- await runDrizzle(["migrate"], schemaEnv);
47
- console.log(`Module migration complete: ${moduleName}`);
48
- } finally {
49
- if (!keepTemp)
50
- try {
51
- fs.unlinkSync(tmpPath);
52
- } catch {}
53
- }
54
- }
1
+ // ./src/core/maker/db/module-migrate.ts
2
+
3
+ import fs from "node:fs";
4
+ import path from "node:path";
5
+ import { ensureMigrationMeta, migrationCount, PROJECT_ROOT, runDrizzle } from "@/core/maker/db/helpers";
6
+
7
+ const MODULES_PATH = path.join(PROJECT_ROOT, "src", "modules");
8
+
9
+ function moduleModels(moduleName: string): string[] {
10
+ const modelsDir = path.join(MODULES_PATH, moduleName, "database", "models");
11
+ let entries: fs.Dirent[];
12
+ try {
13
+ entries = fs.readdirSync(modelsDir, { withFileTypes: true });
14
+ } catch {
15
+ throw new Error(`Module does not exist: ${moduleName}. Create it first with: npm run maker -- make:module ${moduleName}`);
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)
52
+ try {
53
+ fs.unlinkSync(tmpPath);
54
+ } catch {}
55
+ }
56
+ }
@@ -1,21 +1,23 @@
1
- import { generateSchema, runDrizzle } from "@/core/maker/db/helpers";
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
- }
1
+ // ./src/core/maker/db/push.ts
2
+
3
+ import { generateSchema, runDrizzle } from "@/core/maker/db/helpers";
4
+
5
+ async function withSchema(args: string[]): Promise<void> {
6
+ await generateSchema();
7
+ await runDrizzle(args);
8
+ }
9
+
10
+ /** db:push - push schema directly to the database. */
11
+ export async function push(): Promise<void> {
12
+ await withSchema(["push"]);
13
+ }
14
+
15
+ /** db:check - run drizzle-kit check. */
16
+ export async function check(): Promise<void> {
17
+ await withSchema(["check"]);
18
+ }
19
+
20
+ /** db:studio - open Drizzle Studio. */
21
+ export async function studio(): Promise<void> {
22
+ await withSchema(["studio"]);
23
+ }
@@ -1,6 +1,8 @@
1
- import { runScript } from "@/core/maker/db/helpers";
2
-
3
- /** db:reset / db:wipe - delete the SQLite database file only. */
4
- export async function reset(): Promise<void> {
5
- await runScript("src/core/database/reset.ts");
6
- }
1
+ // ./src/core/maker/db/reset.ts
2
+
3
+ import { runScript } from "@/core/maker/db/helpers";
4
+
5
+ /** db:reset / db:wipe - delete the SQLite database file only. */
6
+ export async function reset(): Promise<void> {
7
+ await runScript("src/core/database/reset.ts");
8
+ }
@@ -1,7 +1,9 @@
1
- import { generateSchema, runSeedScript } from "@/core/maker/db/helpers";
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
- }
1
+ // ./src/core/maker/db/seed.ts
2
+
3
+ import { generateSchema, runSeedScript } from "@/core/maker/db/helpers";
4
+
5
+ /** db:seed - run all seeders (auto FK-ordered), or one module's seeders. */
6
+ export async function seed(module?: string): Promise<void> {
7
+ await generateSchema();
8
+ await runSeedScript(module);
9
+ }
@@ -1,6 +1,8 @@
1
- import { runScript } from "@/core/maker/db/helpers";
2
-
3
- /** db:status - list generated migration files. */
4
- export async function status(): Promise<void> {
5
- await runScript("src/core/database/status.ts");
6
- }
1
+ // ./src/core/maker/db/status.ts
2
+
3
+ import { runScript } from "@/core/maker/db/helpers";
4
+
5
+ /** db:status - list generated migration files. */
6
+ export async function status(): Promise<void> {
7
+ await runScript("src/core/database/status.ts");
8
+ }
@@ -1,57 +1,59 @@
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 = ["Getting started", "Generators - modules", "Database", "Build & codegen", "Testing"];
20
-
21
- function padRows(rows: Array<{ left: string; desc: string }>): string[] {
22
- if (!rows.length) return [];
23
- const w = Math.max(...rows.map((r) => r.left.length));
24
- return rows.map((r) => ` ${r.left.padEnd(w)} ${r.desc}`);
25
- }
26
-
27
- export function printCommandHelp(cmd: CommandDef): void {
28
- console.log(LOGO);
29
- console.log(`Usage: npm run maker -- ${cmd.name}${cmd.usage ? ` ${cmd.usage}` : ""} [options]\n`);
30
- console.log(`${cmd.description}\n`);
31
- }
32
-
33
- export function printHelp(commands: Map<string, CommandDef>): void {
34
- console.log(LOGO);
35
- console.log("Usage: npm run maker -- [options] [command]\n");
36
- console.log("Options:");
37
- console.log(" -h, --help display help for command\n");
38
-
39
- const byGroup = new Map<string, CommandDef[]>();
40
- for (const cmd of commands.values()) {
41
- const g = cmd.group || "Other";
42
- if (!byGroup.has(g)) byGroup.set(g, []);
43
- byGroup.get(g)!.push(cmd);
44
- }
45
- for (const arr of byGroup.values()) arr.sort((a, b) => a.name.localeCompare(b.name));
46
-
47
- const groups = [...GROUP_ORDER.filter((g) => byGroup.has(g)), ...[...byGroup.keys()].filter((g) => !GROUP_ORDER.includes(g))];
48
- for (const group of groups) {
49
- const rows = (byGroup.get(group) || []).map((c) => ({ left: c.name, desc: c.description }));
50
- if (!rows.length) continue;
51
- console.log(`${group}:`);
52
- for (const line of padRows(rows)) console.log(line);
53
- console.log("");
54
- }
55
-
56
- console.log("Run `npm run maker -- <command> --help` for command details.");
57
- }
1
+ // ./src/core/maker/help.ts
2
+
3
+ export interface CommandDef {
4
+ name: string;
5
+ usage?: string;
6
+ description: string;
7
+ group: string;
8
+ action: (flags: Record<string, string | boolean>, args: string[]) => void | Promise<void>;
9
+ }
10
+
11
+ const WORDMARK = [
12
+ " ____ _____ ____ _ __ _ ____ ____ ",
13
+ " | _ \\| ____/ ___|| |/ / / \\ | _ \\| _ \\ ",
14
+ " | | | | _| \\___ \\| ' / / _ \\ | |_) | |_) |",
15
+ " | |_| | |___ ___) | . \\ / ___ \\| __/| __/ ",
16
+ " |____/|_____|____/|_|\\_\\/_/ \\_\\_| |_| "
17
+ ];
18
+
19
+ const LOGO = `\n${WORDMARK.join("\n")}\n`;
20
+
21
+ const GROUP_ORDER = ["Getting started", "Generators - modules", "Database", "Build & codegen", "Testing"];
22
+
23
+ function padRows(rows: Array<{ left: string; desc: string }>): string[] {
24
+ if (!rows.length) return [];
25
+ const w = Math.max(...rows.map((r) => r.left.length));
26
+ return rows.map((r) => ` ${r.left.padEnd(w)} ${r.desc}`);
27
+ }
28
+
29
+ export function printCommandHelp(cmd: CommandDef): void {
30
+ console.log(LOGO);
31
+ console.log(`Usage: npm run maker -- ${cmd.name}${cmd.usage ? ` ${cmd.usage}` : ""} [options]\n`);
32
+ console.log(`${cmd.description}\n`);
33
+ }
34
+
35
+ export function printHelp(commands: Map<string, CommandDef>): void {
36
+ console.log(LOGO);
37
+ console.log("Usage: npm run maker -- [options] [command]\n");
38
+ console.log("Options:");
39
+ console.log(" -h, --help display help for command\n");
40
+
41
+ const byGroup = new Map<string, CommandDef[]>();
42
+ for (const cmd of commands.values()) {
43
+ const g = cmd.group || "Other";
44
+ if (!byGroup.has(g)) byGroup.set(g, []);
45
+ byGroup.get(g)!.push(cmd);
46
+ }
47
+ for (const arr of byGroup.values()) arr.sort((a, b) => a.name.localeCompare(b.name));
48
+
49
+ const groups = [...GROUP_ORDER.filter((g) => byGroup.has(g)), ...[...byGroup.keys()].filter((g) => !GROUP_ORDER.includes(g))];
50
+ for (const group of groups) {
51
+ const rows = (byGroup.get(group) || []).map((c) => ({ left: c.name, desc: c.description }));
52
+ if (!rows.length) continue;
53
+ console.log(`${group}:`);
54
+ for (const line of padRows(rows)) console.log(line);
55
+ console.log("");
56
+ }
57
+
58
+ console.log("Run `npm run maker -- <command> --help` for command details.");
59
+ }
@@ -1,22 +1,25 @@
1
- import path from "node:path";
2
- import type { MakerOptions } from "@/core/maker/make/helpers";
3
- import { assertModuleExists, assertName, controllerContent, moduleDir, schemaContent, writeFile } from "@/core/maker/make/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(path.join(controllersDir, `${controllerName}.schema.ts`), schemaContent(moduleName, controllerName), options, "Schema file");
17
- if (!options.dryRun) {
18
- console.log(
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."
20
- );
21
- }
22
- }
1
+ // ./src/core/maker/make/controller.ts
2
+
3
+ import path from "node:path";
4
+ import type { MakerOptions } from "@/core/maker/make/helpers";
5
+ import { assertModuleExists, assertName, controllerContent, moduleDir, schemaContent, writeFile } from "@/core/maker/make/helpers";
6
+
7
+ export function makeController(module: string, name: string, options: MakerOptions = {}): void {
8
+ const moduleName = assertName(module, "Module name");
9
+ const controllerName = assertName(name, "Controller name");
10
+ assertModuleExists(moduleName);
11
+ const controllersDir = path.join(moduleDir(moduleName), "controllers");
12
+ writeFile(
13
+ path.join(controllersDir, `${controllerName}.controller.ts`),
14
+ controllerContent(moduleName, controllerName),
15
+ options,
16
+ "Controller file"
17
+ );
18
+ writeFile(path.join(controllersDir, `${controllerName}.schema.ts`), schemaContent(moduleName, controllerName), options, "Schema file");
19
+ if (!options.dryRun) {
20
+ console.log(
21
+ "Handlers are registered as `<module>.<name>.<handler>` via src/core/api/bindings.generated.ts. Run `npm run maker -- bindings:gen` then rebuild/restart Electron."
22
+ );
23
+ console.log(`If other modules need this controller, re-export it from src/modules/${moduleName}/facade.ts.`);
24
+ }
25
+ }
@@ -1,91 +1,97 @@
1
- import fs from "node:fs";
2
- import path from "node:path";
3
- import { fileURLToPath } from "node:url";
4
- import { loadStub } from "@/core/maker/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(`Module does not exist: ${moduleName}. Create it first with: npm run maker -- make:module ${moduleName}`);
36
- }
37
- }
38
-
39
- export function writeFile(filePath: string, content: string, options: MakerOptions, label: string): void {
40
- const target = path.resolve(filePath);
41
- if (options.dryRun) {
42
- console.log(`[dry-run] would write ${label}: ${target}`);
43
- return;
44
- }
45
- if (fs.existsSync(target) && !options.force) {
46
- throw new Error(`${label} already exists: ${target}. Re-run with --force to overwrite.`);
47
- }
48
- fs.mkdirSync(path.dirname(target), { recursive: true });
49
- fs.writeFileSync(target, content, "utf8");
50
- console.log(`${label} ready: ${target}`);
51
- }
52
-
53
- export function modelContent(module: string, name: string): string {
54
- const ClassName = pascal(name);
55
- return loadStub("model/model.stub", {
56
- tableName: `${name}s`,
57
- tableVariable: `${name}s`,
58
- ClassName,
59
- name,
60
- module
61
- });
62
- }
63
-
64
- export function seederContent(module: string, name: string): string {
65
- const ClassName = pascal(name);
66
- return loadStub("seeder/seeder.stub", {
67
- module,
68
- name,
69
- ClassName,
70
- tableName: `${name}s`,
71
- tableVariable: `${name}s`
72
- });
73
- }
74
-
75
- export function controllerContent(module: string, name: string): string {
76
- const ClassName = pascal(name);
77
- return loadStub("controller/controller.controller.stub", {
78
- module,
79
- controller: name,
80
- ClassName
81
- });
82
- }
83
-
84
- export function schemaContent(module: string, name: string): string {
85
- const ClassName = pascal(name);
86
- return loadStub("controller/controller.schema.stub", {
87
- module,
88
- controller: name,
89
- ClassName
90
- });
91
- }
1
+ // ./src/core/maker/make/helpers.ts
2
+
3
+ import fs from "node:fs";
4
+ import path from "node:path";
5
+ import { fileURLToPath } from "node:url";
6
+ import { loadStub } from "@/core/maker/stub";
7
+
8
+ export interface MakerOptions {
9
+ force?: boolean;
10
+ dryRun?: boolean;
11
+ }
12
+
13
+ const __dirname = path.dirname(fileURLToPath(import.meta.url));
14
+ // src/core/maker/make -> project root
15
+ export const PROJECT_ROOT = path.resolve(__dirname, "..", "..", "..", "..");
16
+
17
+ export function assertName(value: string, label: string): string {
18
+ if (!value) throw new Error(`${label} is required.`);
19
+ return value.trim().toLowerCase();
20
+ }
21
+
22
+ export function pascal(input: string): string {
23
+ return input.replace(/(^\w|[-_]\w)/g, (part) => part.replace(/[-_]/g, "").toUpperCase());
24
+ }
25
+
26
+ export function modulesRoot(): string {
27
+ return path.join(PROJECT_ROOT, "src", "modules");
28
+ }
29
+
30
+ export function moduleDir(moduleName: string): string {
31
+ return path.join(modulesRoot(), moduleName);
32
+ }
33
+
34
+ export function assertModuleExists(moduleName: string): void {
35
+ const dir = moduleDir(moduleName);
36
+ if (!fs.existsSync(dir) || !fs.statSync(dir).isDirectory()) {
37
+ throw new Error(`Module does not exist: ${moduleName}. Create it first with: npm run maker -- make:module ${moduleName}`);
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
+ }
94
+
95
+ export function facadeContent(module: string): string {
96
+ return loadStub("facade/facade.stub", { module });
97
+ }