@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,67 +1,69 @@
1
- import type { CommandDef } from "@/core/maker/help";
2
- import { makeController } from "@/core/maker/make/controller";
3
- import type { MakerOptions } from "@/core/maker/make/helpers";
4
- import { makeModel } from "@/core/maker/make/model";
5
- import { makeModule } from "@/core/maker/make/module";
6
- import { makeSeeder } from "@/core/maker/make/seeder";
7
- import { makeTest } from "@/core/maker/make/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
- }
1
+ // ./src/core/maker/make/mod.ts
2
+
3
+ import type { CommandDef } from "@/core/maker/help";
4
+ import { makeController } from "@/core/maker/make/controller";
5
+ import type { MakerOptions } from "@/core/maker/make/helpers";
6
+ import { makeModel } from "@/core/maker/make/model";
7
+ import { makeModule } from "@/core/maker/make/module";
8
+ import { makeSeeder } from "@/core/maker/make/seeder";
9
+ import { makeTest } from "@/core/maker/make/test";
10
+
11
+ const GROUP = "Generators - modules";
12
+
13
+ function opts(flags: Record<string, string | boolean>): MakerOptions {
14
+ return { force: Boolean(flags.force), dryRun: Boolean(flags["dry-run"] ?? flags.dryRun) };
15
+ }
16
+
17
+ function need(args: string[], i: number, label: string): string {
18
+ const v = args[i];
19
+ if (!v) throw new Error(`${label} is required.`);
20
+ return v;
21
+ }
22
+
23
+ export function registerMakeCommands(register: (cmd: CommandDef) => void): void {
24
+ register({
25
+ name: "make:module",
26
+ usage: "<name> [--force]",
27
+ group: GROUP,
28
+ description: "Create a module with model, seeder, controller + schema + facade",
29
+ action: (flags, args) => makeModule(need(args, 0, "Module name"), opts(flags))
30
+ });
31
+ register({
32
+ name: "make:controller",
33
+ usage: "<module> <name> [--force] [--dry-run]",
34
+ group: GROUP,
35
+ description: "Generate a controller + schema for an existing module",
36
+ action: (flags, args) => makeController(need(args, 0, "Module name"), need(args, 1, "Controller name"), opts(flags))
37
+ });
38
+ register({
39
+ name: "make:model",
40
+ usage: "<module> <name> [--force] [--dry-run]",
41
+ group: GROUP,
42
+ description: "Generate a model file for an existing module",
43
+ action: (flags, args) => makeModel(need(args, 0, "Module name"), need(args, 1, "Model name"), opts(flags))
44
+ });
45
+ register({
46
+ name: "make:seeder",
47
+ usage: "<module> <name> [--force] [--dry-run]",
48
+ group: GROUP,
49
+ description: "Generate a seeder for an existing module model",
50
+ action: (flags, args) => makeSeeder(need(args, 0, "Module name"), need(args, 1, "Seeder name"), opts(flags))
51
+ });
52
+
53
+ const testAction = (flags: Record<string, string | boolean>, args: string[]) =>
54
+ makeTest(need(args, 0, "Module name"), args[1], opts(flags));
55
+ register({
56
+ name: "make:test",
57
+ usage: "<module> [name] [--force] [--dry-run]",
58
+ group: GROUP,
59
+ description: "Generate a Vitest file in src/modules/<module>/__tests__",
60
+ action: testAction
61
+ });
62
+ register({
63
+ name: "module:make-test",
64
+ usage: "<module> [name] [--force] [--dry-run]",
65
+ group: GROUP,
66
+ description: "Alias for make:test (Nexwire-style)",
67
+ action: testAction
68
+ });
69
+ }
@@ -1,14 +1,16 @@
1
- import path from "node:path";
2
- import type { MakerOptions } from "@/core/maker/make/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
- }
1
+ // ./src/core/maker/make/model.ts
2
+
3
+ import path from "node:path";
4
+ import type { MakerOptions } from "@/core/maker/make/helpers";
5
+ import { assertModuleExists, assertName, modelContent, moduleDir, writeFile } from "./helpers";
6
+
7
+ export function makeModel(module: string, name: string, options: MakerOptions = {}): void {
8
+ const moduleName = assertName(module, "Module name");
9
+ const modelName = assertName(name, "Model name");
10
+ assertModuleExists(moduleName);
11
+ const filePath = path.join(moduleDir(moduleName), "database", "models", `${modelName}.model.ts`);
12
+ writeFile(filePath, modelContent(moduleName, modelName), options, "Model file");
13
+ if (!options.dryRun) {
14
+ console.log(`Next: \`npm run maker -- db:generate\` (or \`db:migrate\`) to include '${modelName}' in the schema.`);
15
+ }
16
+ }
@@ -1,39 +1,53 @@
1
- import fs from "node:fs";
2
- import path from "node:path";
3
- import type { MakerOptions } from "@/core/maker/make/helpers";
4
- import { assertName, controllerContent, modelContent, modulesRoot, schemaContent, seederContent, writeFile } from "./helpers";
5
-
6
- export function makeModule(name: string, options: MakerOptions = {}): void {
7
- const moduleName = assertName(name, "Module name");
8
- const root = path.join(modulesRoot(), moduleName);
9
- const exists = fs.existsSync(root) && fs.statSync(root).isDirectory();
10
- if (exists && !options.force) throw new Error(`Module already exists: ${moduleName}.`);
11
-
12
- if (options.dryRun) {
13
- console.log(`[dry-run] would create module: ${path.resolve(root)}`);
14
- console.log(`[dry-run] - database/models/${moduleName}.model.ts`);
15
- console.log(`[dry-run] - database/seeders/${moduleName}.seed.ts`);
16
- console.log(`[dry-run] - controllers/${moduleName}.controller.ts`);
17
- console.log(`[dry-run] - controllers/${moduleName}.schema.ts`);
18
- return;
19
- }
20
-
21
- fs.mkdirSync(path.join(root, "database", "models"), { recursive: true });
22
- fs.mkdirSync(path.join(root, "database", "seeders"), { recursive: true });
23
- fs.mkdirSync(path.join(root, "controllers"), { recursive: true });
24
-
25
- writeFile(path.join(root, "database", "models", `${moduleName}.model.ts`), modelContent(moduleName, moduleName), options, "Model file");
26
- writeFile(path.join(root, "database", "seeders", `${moduleName}.seed.ts`), seederContent(moduleName, moduleName), options, "Seeder file");
27
- writeFile(
28
- path.join(root, "controllers", `${moduleName}.controller.ts`),
29
- controllerContent(moduleName, moduleName),
30
- options,
31
- "Controller file"
32
- );
33
- writeFile(path.join(root, "controllers", `${moduleName}.schema.ts`), schemaContent(moduleName, moduleName), options, "Schema file");
34
-
35
- console.log(`Module ready: ${path.resolve(root)}`);
36
- console.log("Database files: database/models/{name}.model.ts, database/seeders/{name}.seed.ts");
37
- console.log("Controller + schema: controllers/{name}.controller.ts, controllers/{name}.schema.ts");
38
- console.log("Next: `npm run maker -- db:generate` (or `db:migrate`), then `npm run maker -- bindings:gen` and rebuild Electron.");
39
- }
1
+ // ./src/core/maker/make/module.ts
2
+
3
+ import fs from "node:fs";
4
+ import path from "node:path";
5
+ import type { MakerOptions } from "@/core/maker/make/helpers";
6
+ import {
7
+ assertName,
8
+ controllerContent,
9
+ facadeContent,
10
+ modelContent,
11
+ modulesRoot,
12
+ schemaContent,
13
+ seederContent,
14
+ writeFile
15
+ } from "./helpers";
16
+
17
+ export function makeModule(name: string, options: MakerOptions = {}): void {
18
+ const moduleName = assertName(name, "Module name");
19
+ const root = path.join(modulesRoot(), moduleName);
20
+ const exists = fs.existsSync(root) && fs.statSync(root).isDirectory();
21
+ if (exists && !options.force) throw new Error(`Module already exists: ${moduleName}.`);
22
+
23
+ if (options.dryRun) {
24
+ console.log(`[dry-run] would create module: ${path.resolve(root)}`);
25
+ console.log(`[dry-run] - database/models/${moduleName}.model.ts`);
26
+ console.log(`[dry-run] - database/seeders/${moduleName}.seed.ts`);
27
+ console.log(`[dry-run] - controllers/${moduleName}.controller.ts`);
28
+ console.log(`[dry-run] - controllers/${moduleName}.schema.ts`);
29
+ console.log("[dry-run] - facade.ts");
30
+ return;
31
+ }
32
+
33
+ fs.mkdirSync(path.join(root, "database", "models"), { recursive: true });
34
+ fs.mkdirSync(path.join(root, "database", "seeders"), { recursive: true });
35
+ fs.mkdirSync(path.join(root, "controllers"), { recursive: true });
36
+
37
+ writeFile(path.join(root, "database", "models", `${moduleName}.model.ts`), modelContent(moduleName, moduleName), options, "Model file");
38
+ writeFile(path.join(root, "database", "seeders", `${moduleName}.seed.ts`), seederContent(moduleName, moduleName), options, "Seeder file");
39
+ writeFile(
40
+ path.join(root, "controllers", `${moduleName}.controller.ts`),
41
+ controllerContent(moduleName, moduleName),
42
+ options,
43
+ "Controller file"
44
+ );
45
+ writeFile(path.join(root, "controllers", `${moduleName}.schema.ts`), schemaContent(moduleName, moduleName), options, "Schema file");
46
+ writeFile(path.join(root, "facade.ts"), facadeContent(moduleName), options, "Facade file");
47
+
48
+ console.log(`Module ready: ${path.resolve(root)}`);
49
+ console.log("Database files: database/models/{name}.model.ts, database/seeders/{name}.seed.ts");
50
+ console.log("Controller + schema: controllers/{name}.controller.ts, controllers/{name}.schema.ts");
51
+ console.log("Public API: facade.ts (re-exports controllers + models for other modules)");
52
+ console.log("Next: `npm run maker -- db:generate` (or `db:migrate`), then `npm run maker -- bindings:gen` and rebuild Electron.");
53
+ }
@@ -1,21 +1,23 @@
1
- import fs from "node:fs";
2
- import path from "node:path";
3
- import type { MakerOptions } from "@/core/maker/make/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
- }
1
+ // ./src/core/maker/make/seeder.ts
2
+
3
+ import fs from "node:fs";
4
+ import path from "node:path";
5
+ import type { MakerOptions } from "@/core/maker/make/helpers";
6
+ import { assertModuleExists, assertName, moduleDir, seederContent, writeFile } from "./helpers";
7
+
8
+ export function makeSeeder(module: string, name: string, options: MakerOptions = {}): void {
9
+ const moduleName = assertName(module, "Module name");
10
+ const seederName = assertName(name, "Seeder name");
11
+ assertModuleExists(moduleName);
12
+ const modelPath = path.join(moduleDir(moduleName), "database", "models", `${seederName}.model.ts`);
13
+ if (!fs.existsSync(modelPath) || !fs.statSync(modelPath).isFile()) {
14
+ throw new Error(
15
+ `Model not found for seeder: src/modules/${moduleName}/database/models/${seederName}.model.ts. Create it first with: npm run maker -- make:model ${moduleName} ${seederName}`
16
+ );
17
+ }
18
+ const filePath = path.join(moduleDir(moduleName), "database", "seeders", `${seederName}.seed.ts`);
19
+ writeFile(filePath, seederContent(moduleName, seederName), options, "Seeder file");
20
+ if (!options.dryRun) {
21
+ console.log("Fills seed values from parent FKs manually; ordering is resolved automatically by the seeder runner.");
22
+ }
23
+ }
@@ -1,30 +1,33 @@
1
- import path from "node:path";
2
- import type { MakerOptions } from "@/core/maker/make/helpers";
3
- import { loadStub } from "@/core/maker/stub";
4
- import { assertModuleExists, assertName, moduleDir, writeFile } from "./helpers";
5
-
6
- /**
7
- * make:test / module:make-test - create a Vitest file in a module's __tests__ folder.
8
- * Nexwire-style: `module:make-test <module> [name]` -> __tests__/<name|module>.test.ts
9
- */
10
- export function makeTest(module: string, name?: string, options: MakerOptions = {}): void {
11
- const moduleName = assertName(module, "Module name");
12
- assertModuleExists(moduleName);
13
- const rawName = name?.trim() ? assertName(name, "Test name") : moduleName;
14
- // strip trailing .test/.spec if provided
15
- const testName = rawName.replace(/\.(test|spec)$/i, "");
16
-
17
- const filePath = path.join(moduleDir(moduleName), "__tests__", `${testName}.test.ts`);
18
- const content = loadStub("test/test.stub", {
19
- module: moduleName,
20
- name: testName === moduleName ? "" : testName
21
- }).replace(/\{\{#name\}\}[\s\S]*?\{\{\/name\}\}/g, (m) => {
22
- // simple conditional: keep inner text when name is non-empty
23
- return testName === moduleName ? "" : m.replace(/\{\{#name\}\}|\{\{\/name\}\}/g, "");
24
- });
25
-
26
- writeFile(filePath, content, options, "Test file");
27
- if (!options.dryRun) {
28
- console.log(`Run tests with: npm test (or \`npm run maker -- test\`).`);
29
- }
30
- }
1
+ // ./src/core/maker/make/test.ts
2
+
3
+ import path from "node:path";
4
+ import type { MakerOptions } from "@/core/maker/make/helpers";
5
+ import { loadStub } from "@/core/maker/stub";
6
+ import { assertModuleExists, assertName, moduleDir, writeFile } from "./helpers";
7
+
8
+ /**
9
+ * make:test / module:make-test - create a Vitest file in a module's __tests__ folder.
10
+ * Nexwire-style: `module:make-test <module> [name]` -> __tests__/<name|module>.test.ts
11
+ */
12
+ export function makeTest(module: string, name?: string, options: MakerOptions = {}): void {
13
+ const moduleName = assertName(module, "Module name");
14
+ assertModuleExists(moduleName);
15
+ const rawName = name?.trim() ? assertName(name, "Test name") : moduleName;
16
+ // strip trailing .test/.spec if provided
17
+ const testName = rawName.replace(/\.(test|spec)$/i, "");
18
+
19
+ const filePath = path.join(moduleDir(moduleName), "__tests__", `${testName}.test.ts`);
20
+ const content = loadStub("test/test.stub", {
21
+ module: moduleName,
22
+ name: testName === moduleName ? "" : testName,
23
+ file: `${testName}.test.ts`
24
+ }).replace(/\{\{#name\}\}[\s\S]*?\{\{\/name\}\}/g, (m) => {
25
+ // simple conditional: keep inner text when name is non-empty
26
+ return testName === moduleName ? "" : m.replace(/\{\{#name\}\}|\{\{\/name\}\}/g, "");
27
+ });
28
+
29
+ writeFile(filePath, content, options, "Test file");
30
+ if (!options.dryRun) {
31
+ console.log(`Run tests with: npm test (or \`npm run maker -- test\`).`);
32
+ }
33
+ }
@@ -1,83 +1,85 @@
1
- import { registerDbCommands } from "@/core/maker/db/mod";
2
- import { type CommandDef, printCommandHelp, printHelp } from "@/core/maker/help";
3
- import { registerMakeCommands } from "@/core/maker/make/mod";
4
- import { registerRunCommands } from "@/core/maker/run/mod";
5
-
6
- const commands = new Map<string, CommandDef>();
7
-
8
- function register(cmd: CommandDef) {
9
- commands.set(cmd.name, cmd);
10
- }
11
-
12
- registerMakeCommands(register);
13
- registerDbCommands(register);
14
- registerRunCommands(register);
15
-
16
- function parseFlags(argv: string[]): { flags: Record<string, string | boolean>; positionals: string[] } {
17
- const flags: Record<string, string | boolean> = {};
18
- const positionals: string[] = [];
19
- for (let i = 0; i < argv.length; i++) {
20
- const arg = argv[i];
21
- if (arg === "--") {
22
- positionals.push(...argv.slice(i + 1));
23
- break;
24
- }
25
- if (arg.startsWith("--")) {
26
- const eq = arg.indexOf("=");
27
- if (eq !== -1) {
28
- flags[arg.slice(2, eq)] = arg.slice(eq + 1);
29
- } else {
30
- const key = arg.slice(2);
31
- const next = argv[i + 1];
32
- if (key === "no-zip") {
33
- flags.zip = false;
34
- } else if (next !== undefined && !next.startsWith("--")) {
35
- flags[key] = next;
36
- i++;
37
- } else {
38
- flags[key] = true;
39
- }
40
- }
41
- } else {
42
- positionals.push(arg);
43
- }
44
- }
45
- return { flags, positionals };
46
- }
47
-
48
- async function main() {
49
- const argv = process.argv.slice(2);
50
- if (argv.length === 0 || argv[0] === "-h" || argv[0] === "--help") {
51
- printHelp(commands);
52
- return;
53
- }
54
- if (argv[0] === "help") {
55
- const target = argv[1];
56
- if (target && commands.has(target)) printCommandHelp(commands.get(target)!);
57
- else printHelp(commands);
58
- return;
59
- }
60
-
61
- const name = argv[0];
62
- const cmd = commands.get(name);
63
- if (!cmd) {
64
- console.error(`\n Unknown command: ${name}\n`);
65
- printHelp(commands);
66
- process.exit(1);
67
- }
68
-
69
- const { flags, positionals } = parseFlags(argv.slice(1));
70
- if (flags.help || flags.h) {
71
- printCommandHelp(cmd);
72
- return;
73
- }
74
-
75
- try {
76
- await cmd.action(flags, positionals);
77
- } catch (error) {
78
- console.error(error instanceof Error ? error.message : error);
79
- process.exit(1);
80
- }
81
- }
82
-
83
- main();
1
+ // ./src/core/maker/mod.ts
2
+
3
+ import { registerDbCommands } from "@/core/maker/db/mod";
4
+ import { type CommandDef, printCommandHelp, printHelp } from "@/core/maker/help";
5
+ import { registerMakeCommands } from "@/core/maker/make/mod";
6
+ import { registerRunCommands } from "@/core/maker/run/mod";
7
+
8
+ const commands = new Map<string, CommandDef>();
9
+
10
+ function register(cmd: CommandDef) {
11
+ commands.set(cmd.name, cmd);
12
+ }
13
+
14
+ registerMakeCommands(register);
15
+ registerDbCommands(register);
16
+ registerRunCommands(register);
17
+
18
+ function parseFlags(argv: string[]): { flags: Record<string, string | boolean>; positionals: string[] } {
19
+ const flags: Record<string, string | boolean> = {};
20
+ const positionals: string[] = [];
21
+ for (let i = 0; i < argv.length; i++) {
22
+ const arg = argv[i];
23
+ if (arg === "--") {
24
+ positionals.push(...argv.slice(i + 1));
25
+ break;
26
+ }
27
+ if (arg.startsWith("--")) {
28
+ const eq = arg.indexOf("=");
29
+ if (eq !== -1) {
30
+ flags[arg.slice(2, eq)] = arg.slice(eq + 1);
31
+ } else {
32
+ const key = arg.slice(2);
33
+ const next = argv[i + 1];
34
+ if (key === "no-zip") {
35
+ flags.zip = false;
36
+ } else if (next !== undefined && !next.startsWith("--")) {
37
+ flags[key] = next;
38
+ i++;
39
+ } else {
40
+ flags[key] = true;
41
+ }
42
+ }
43
+ } else {
44
+ positionals.push(arg);
45
+ }
46
+ }
47
+ return { flags, positionals };
48
+ }
49
+
50
+ async function main() {
51
+ const argv = process.argv.slice(2);
52
+ if (argv.length === 0 || argv[0] === "-h" || argv[0] === "--help") {
53
+ printHelp(commands);
54
+ return;
55
+ }
56
+ if (argv[0] === "help") {
57
+ const target = argv[1];
58
+ if (target && commands.has(target)) printCommandHelp(commands.get(target)!);
59
+ else printHelp(commands);
60
+ return;
61
+ }
62
+
63
+ const name = argv[0];
64
+ const cmd = commands.get(name);
65
+ if (!cmd) {
66
+ console.error(`\n Unknown command: ${name}\n`);
67
+ printHelp(commands);
68
+ process.exit(1);
69
+ }
70
+
71
+ const { flags, positionals } = parseFlags(argv.slice(1));
72
+ if (flags.help || flags.h) {
73
+ printCommandHelp(cmd);
74
+ return;
75
+ }
76
+
77
+ try {
78
+ await cmd.action(flags, positionals);
79
+ } catch (error) {
80
+ console.error(error instanceof Error ? error.message : error);
81
+ process.exit(1);
82
+ }
83
+ }
84
+
85
+ main();