@veloxts/cli 0.4.0 → 0.4.2

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 (140) hide show
  1. package/README.md +23 -144
  2. package/dist/cli.js +2 -0
  3. package/dist/cli.js.map +1 -1
  4. package/dist/commands/generate.d.ts +17 -0
  5. package/dist/commands/generate.d.ts.map +1 -0
  6. package/dist/commands/generate.js +219 -0
  7. package/dist/commands/generate.js.map +1 -0
  8. package/dist/commands/migrate.d.ts +8 -3
  9. package/dist/commands/migrate.d.ts.map +1 -1
  10. package/dist/commands/migrate.js +17 -123
  11. package/dist/commands/migrate.js.map +1 -1
  12. package/dist/generators/base.d.ts +76 -0
  13. package/dist/generators/base.d.ts.map +1 -0
  14. package/dist/generators/base.js +271 -0
  15. package/dist/generators/base.js.map +1 -0
  16. package/dist/generators/generators/index.d.ts +17 -0
  17. package/dist/generators/generators/index.d.ts.map +1 -0
  18. package/dist/generators/generators/index.js +43 -0
  19. package/dist/generators/generators/index.js.map +1 -0
  20. package/dist/generators/generators/migration.d.ts +43 -0
  21. package/dist/generators/generators/migration.d.ts.map +1 -0
  22. package/dist/generators/generators/migration.js +121 -0
  23. package/dist/generators/generators/migration.js.map +1 -0
  24. package/dist/generators/generators/model.d.ts +38 -0
  25. package/dist/generators/generators/model.d.ts.map +1 -0
  26. package/dist/generators/generators/model.js +108 -0
  27. package/dist/generators/generators/model.js.map +1 -0
  28. package/dist/generators/generators/procedure.d.ts +37 -0
  29. package/dist/generators/generators/procedure.d.ts.map +1 -0
  30. package/dist/generators/generators/procedure.js +99 -0
  31. package/dist/generators/generators/procedure.js.map +1 -0
  32. package/dist/generators/generators/resource.d.ts +29 -0
  33. package/dist/generators/generators/resource.d.ts.map +1 -0
  34. package/dist/generators/generators/resource.js +124 -0
  35. package/dist/generators/generators/resource.js.map +1 -0
  36. package/dist/generators/generators/schema.d.ts +28 -0
  37. package/dist/generators/generators/schema.d.ts.map +1 -0
  38. package/dist/generators/generators/schema.js +83 -0
  39. package/dist/generators/generators/schema.js.map +1 -0
  40. package/dist/generators/generators/test.d.ts +28 -0
  41. package/dist/generators/generators/test.d.ts.map +1 -0
  42. package/dist/generators/generators/test.js +96 -0
  43. package/dist/generators/generators/test.js.map +1 -0
  44. package/dist/generators/index.d.ts +16 -0
  45. package/dist/generators/index.d.ts.map +1 -0
  46. package/dist/generators/index.js +16 -0
  47. package/dist/generators/index.js.map +1 -0
  48. package/dist/generators/registry.d.ts +97 -0
  49. package/dist/generators/registry.d.ts.map +1 -0
  50. package/dist/generators/registry.js +253 -0
  51. package/dist/generators/registry.js.map +1 -0
  52. package/dist/generators/templates/migration.d.ts +23 -0
  53. package/dist/generators/templates/migration.d.ts.map +1 -0
  54. package/dist/generators/templates/migration.js +389 -0
  55. package/dist/generators/templates/migration.js.map +1 -0
  56. package/dist/generators/templates/model.d.ts +37 -0
  57. package/dist/generators/templates/model.d.ts.map +1 -0
  58. package/dist/generators/templates/model.js +374 -0
  59. package/dist/generators/templates/model.js.map +1 -0
  60. package/dist/generators/templates/procedure.d.ts +25 -0
  61. package/dist/generators/templates/procedure.d.ts.map +1 -0
  62. package/dist/generators/templates/procedure.js +274 -0
  63. package/dist/generators/templates/procedure.js.map +1 -0
  64. package/dist/generators/templates/resource.d.ts +34 -0
  65. package/dist/generators/templates/resource.d.ts.map +1 -0
  66. package/dist/generators/templates/resource.js +550 -0
  67. package/dist/generators/templates/resource.js.map +1 -0
  68. package/dist/generators/templates/schema.d.ts +33 -0
  69. package/dist/generators/templates/schema.d.ts.map +1 -0
  70. package/dist/generators/templates/schema.js +248 -0
  71. package/dist/generators/templates/schema.js.map +1 -0
  72. package/dist/generators/templates/test.d.ts +31 -0
  73. package/dist/generators/templates/test.d.ts.map +1 -0
  74. package/dist/generators/templates/test.js +882 -0
  75. package/dist/generators/templates/test.js.map +1 -0
  76. package/dist/generators/types.d.ts +211 -0
  77. package/dist/generators/types.d.ts.map +1 -0
  78. package/dist/generators/types.js +54 -0
  79. package/dist/generators/types.js.map +1 -0
  80. package/dist/generators/utils/filesystem.d.ts +68 -0
  81. package/dist/generators/utils/filesystem.d.ts.map +1 -0
  82. package/dist/generators/utils/filesystem.js +217 -0
  83. package/dist/generators/utils/filesystem.js.map +1 -0
  84. package/dist/generators/utils/naming.d.ts +122 -0
  85. package/dist/generators/utils/naming.d.ts.map +1 -0
  86. package/dist/generators/utils/naming.js +198 -0
  87. package/dist/generators/utils/naming.js.map +1 -0
  88. package/dist/index.d.ts +4 -0
  89. package/dist/index.d.ts.map +1 -1
  90. package/dist/index.js +4 -0
  91. package/dist/index.js.map +1 -1
  92. package/dist/migrations/commands/fresh.d.ts +11 -0
  93. package/dist/migrations/commands/fresh.d.ts.map +1 -0
  94. package/dist/migrations/commands/fresh.js +164 -0
  95. package/dist/migrations/commands/fresh.js.map +1 -0
  96. package/dist/migrations/commands/index.d.ts +11 -0
  97. package/dist/migrations/commands/index.d.ts.map +1 -0
  98. package/dist/migrations/commands/index.js +11 -0
  99. package/dist/migrations/commands/index.js.map +1 -0
  100. package/dist/migrations/commands/reset.d.ts +11 -0
  101. package/dist/migrations/commands/reset.d.ts.map +1 -0
  102. package/dist/migrations/commands/reset.js +258 -0
  103. package/dist/migrations/commands/reset.js.map +1 -0
  104. package/dist/migrations/commands/rollback.d.ts +11 -0
  105. package/dist/migrations/commands/rollback.d.ts.map +1 -0
  106. package/dist/migrations/commands/rollback.js +241 -0
  107. package/dist/migrations/commands/rollback.js.map +1 -0
  108. package/dist/migrations/commands/run.d.ts +11 -0
  109. package/dist/migrations/commands/run.d.ts.map +1 -0
  110. package/dist/migrations/commands/run.js +183 -0
  111. package/dist/migrations/commands/run.js.map +1 -0
  112. package/dist/migrations/commands/status.d.ts +11 -0
  113. package/dist/migrations/commands/status.d.ts.map +1 -0
  114. package/dist/migrations/commands/status.js +154 -0
  115. package/dist/migrations/commands/status.js.map +1 -0
  116. package/dist/migrations/errors.d.ts +74 -0
  117. package/dist/migrations/errors.d.ts.map +1 -0
  118. package/dist/migrations/errors.js +155 -0
  119. package/dist/migrations/errors.js.map +1 -0
  120. package/dist/migrations/index.d.ts +13 -0
  121. package/dist/migrations/index.d.ts.map +1 -0
  122. package/dist/migrations/index.js +17 -0
  123. package/dist/migrations/index.js.map +1 -0
  124. package/dist/migrations/loader.d.ts +44 -0
  125. package/dist/migrations/loader.d.ts.map +1 -0
  126. package/dist/migrations/loader.js +181 -0
  127. package/dist/migrations/loader.js.map +1 -0
  128. package/dist/migrations/prisma-wrapper.d.ts +60 -0
  129. package/dist/migrations/prisma-wrapper.d.ts.map +1 -0
  130. package/dist/migrations/prisma-wrapper.js +184 -0
  131. package/dist/migrations/prisma-wrapper.js.map +1 -0
  132. package/dist/migrations/rollback-runner.d.ts +40 -0
  133. package/dist/migrations/rollback-runner.d.ts.map +1 -0
  134. package/dist/migrations/rollback-runner.js +203 -0
  135. package/dist/migrations/rollback-runner.js.map +1 -0
  136. package/dist/migrations/types.d.ts +214 -0
  137. package/dist/migrations/types.d.ts.map +1 -0
  138. package/dist/migrations/types.js +19 -0
  139. package/dist/migrations/types.js.map +1 -0
  140. package/package.json +29 -8
package/README.md CHANGED
@@ -1,175 +1,54 @@
1
1
  # @veloxts/cli
2
2
 
3
- > **Alpha Release** - This framework is in early development. APIs may change between versions. Not recommended for production use yet.
3
+ **Pre-Alpha Notice:** This framework is in early development (v0.4.x). APIs are subject to change. Not recommended for production use.
4
4
 
5
- Command-line interface for the VeloxTS Framework.
5
+ ## What is this?
6
6
 
7
- ## Installation
8
-
9
- The CLI is installed automatically when you create a new VeloxTS project:
10
-
11
- ```bash
12
- npx create-velox-app my-app
13
- cd my-app
14
- ```
15
-
16
- Or add it to an existing project:
17
-
18
- ```bash
19
- npm install -D @veloxts/cli
20
- # or
21
- pnpm add -D @veloxts/cli
22
- ```
23
-
24
- ## Commands
25
-
26
- ### `velox dev`
27
-
28
- Start the development server with hot reload.
29
-
30
- ```bash
31
- velox dev
32
- ```
33
-
34
- **Options:**
35
-
36
- - `-p, --port <port>` - Port to listen on (default: 3210)
37
- - `-H, --host <host>` - Host to bind to (default: localhost)
38
- - `-e, --entry <file>` - Entry point file (auto-detected if not specified)
39
-
40
- **Examples:**
41
-
42
- ```bash
43
- # Start on default port 3210
44
- velox dev
45
-
46
- # Start on custom port
47
- velox dev --port 8080
48
-
49
- # Specify custom entry point
50
- velox dev --entry src/main.ts
51
- ```
52
-
53
- ### `velox migrate`
54
-
55
- Run database migrations using Prisma.
56
-
57
- ```bash
58
- velox migrate
59
- ```
7
+ Command-line interface for the VeloxTS Framework, providing development server, migration commands, and code generators.
60
8
 
61
- **Options:**
9
+ ## Part of @veloxts/velox
62
10
 
63
- - `--deploy` - Run migrations in production mode (prisma migrate deploy)
64
- - `--force` - Force push schema without migration (development only)
65
-
66
- **Examples:**
11
+ This package is part of the VeloxTS Framework. For the complete framework experience, install:
67
12
 
68
13
  ```bash
69
- # Development: Sync schema with database
70
- velox migrate
71
-
72
- # Production: Apply pending migrations
73
- velox migrate --deploy
74
-
75
- # Force push schema changes (dev only)
76
- velox migrate --force
14
+ npm install @veloxts/velox
77
15
  ```
78
16
 
79
- ## Development
80
-
81
- ### Building
17
+ Visit [@veloxts/velox](https://www.npmjs.com/package/@veloxts/velox) for the complete framework documentation.
82
18
 
83
- ```bash
84
- pnpm build
85
- ```
19
+ ## Installation
86
20
 
87
- ### Type Checking
21
+ The CLI is installed automatically when you create a new VeloxTS project:
88
22
 
89
23
  ```bash
90
- pnpm type-check
24
+ npx create-velox-app my-app
91
25
  ```
92
26
 
93
- ## Features
94
-
95
- - Beautiful terminal output with colors and spinners
96
- - Automatic entry point detection
97
- - Graceful shutdown handling (Ctrl+C)
98
- - Helpful error messages with suggestions
99
- - Intuitive command design
100
- - Built with Commander.js and Clack
101
-
102
- ## Architecture
103
-
104
- The CLI is built with:
105
-
106
- - **Commander.js** - Command-line parsing and routing
107
- - **Clack** - Beautiful interactive prompts
108
- - **picocolors** - Terminal colors without dependencies
109
- - **tsx** - TypeScript execution with hot reload
110
-
111
- ## Troubleshooting
112
-
113
- ### Entry Point Not Found
114
-
115
- If the CLI can't find your entry point:
27
+ Or add it to an existing project:
116
28
 
117
29
  ```bash
118
- velox dev --entry src/index.ts
30
+ npm install -D @veloxts/cli
119
31
  ```
120
32
 
121
- Or ensure your project has one of these files:
122
- - `src/index.ts`
123
- - `src/main.ts`
124
- - `index.ts`
33
+ ## Documentation
125
34
 
126
- ### Port Already in Use
35
+ For detailed documentation, usage examples, and API reference, see [GUIDE.md](./GUIDE.md).
127
36
 
128
- ```
129
- Error: Port 3210 is already in use
130
- ```
131
-
132
- **Solution:** Use a different port:
37
+ ## Quick Example
133
38
 
134
39
  ```bash
135
- velox dev --port 8080
136
- ```
137
-
138
- ### Module Resolution Errors
139
-
140
- Ensure all dependencies are installed:
40
+ # Start development server
41
+ velox dev
141
42
 
142
- ```bash
143
- npm install
43
+ # Run database migrations
44
+ velox migrate
144
45
  ```
145
46
 
146
- And that your `tsconfig.json` has correct module resolution settings.
147
-
148
- ## MVP Limitations
149
-
150
- The current v0.1.0 release includes:
151
-
152
- **Included:**
153
- - `velox dev` - Development server with hot reload
154
- - `velox migrate` - Database migrations (wraps Prisma)
155
-
156
- **Deferred to v1.1+:**
157
- - Code generators (`velox generate controller`, etc.)
158
- - Database seeding command (`velox db:seed`)
159
- - Migration rollback command
160
- - Interactive project scaffolding
161
- - Custom command plugins
162
-
163
- ## Related Packages
164
-
165
- - [@veloxts/core](/packages/core) - Core framework
166
- - [@veloxts/router](/packages/router) - Procedure-based routing
167
- - [@veloxts/orm](/packages/orm) - Prisma integration
168
- - [create-velox-app](/packages/create) - Project scaffolder
169
-
170
- ## TypeScript Support
47
+ ## Learn More
171
48
 
172
- All exports are fully typed with comprehensive JSDoc documentation. The package includes type definitions and declaration maps for excellent IDE support.
49
+ - [Full Documentation](./GUIDE.md)
50
+ - [VeloxTS Framework](https://www.npmjs.com/package/@veloxts/velox)
51
+ - [GitHub Repository](https://github.com/veloxts/velox-ts-framework)
173
52
 
174
53
  ## License
175
54
 
package/dist/cli.js CHANGED
@@ -6,6 +6,7 @@
6
6
  */
7
7
  import { Command } from 'commander';
8
8
  import { createDevCommand } from './commands/dev.js';
9
+ import { createGenerateCommand } from './commands/generate.js';
9
10
  import { createMigrateCommand } from './commands/migrate.js';
10
11
  import { CLI_VERSION } from './index.js';
11
12
  /**
@@ -20,6 +21,7 @@ function createCLI() {
20
21
  .helpOption('-h, --help', 'Display help for command');
21
22
  // Register commands
22
23
  program.addCommand(createDevCommand(CLI_VERSION));
24
+ program.addCommand(createGenerateCommand());
23
25
  program.addCommand(createMigrateCommand());
24
26
  return program;
25
27
  }
package/dist/cli.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"cli.js","sourceRoot":"","sources":["../src/cli.ts"],"names":[],"mappings":";AAEA;;;;GAIG;AAEH,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAEpC,OAAO,EAAE,gBAAgB,EAAE,MAAM,mBAAmB,CAAC;AACrD,OAAO,EAAE,oBAAoB,EAAE,MAAM,uBAAuB,CAAC;AAC7D,OAAO,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAEzC;;GAEG;AACH,SAAS,SAAS;IAChB,MAAM,OAAO,GAAG,IAAI,OAAO,EAAE,CAAC;IAE9B,OAAO;SACJ,IAAI,CAAC,OAAO,CAAC;SACb,WAAW,CAAC,sEAAsE,CAAC;SACnF,OAAO,CAAC,WAAW,EAAE,eAAe,EAAE,4BAA4B,CAAC;SACnE,UAAU,CAAC,YAAY,EAAE,0BAA0B,CAAC,CAAC;IAExD,oBAAoB;IACpB,OAAO,CAAC,UAAU,CAAC,gBAAgB,CAAC,WAAW,CAAC,CAAC,CAAC;IAClD,OAAO,CAAC,UAAU,CAAC,oBAAoB,EAAE,CAAC,CAAC;IAE3C,OAAO,OAAO,CAAC;AACjB,CAAC;AAED;;GAEG;AACH,KAAK,UAAU,IAAI;IACjB,MAAM,OAAO,GAAG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EAAE,CAAC,CAAC;IAE3C,OAAO,OAAO,CAAC;AACjB,CAAC;AAED;;GAEG;AACH,KAAK,UAAU,IAAI;IACjB,MAAM,OAAO,GAAG,SAAS,EAAE,CAAC;IAE5B,IAAI,CAAC;QACH,MAAM,OAAO,CAAC,UAAU,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;IACzC,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,IAAI,KAAK,YAAY,KAAK,EAAE,CAAC;YAC3B,OAAO,CAAC,KAAK,CAAC,UAAU,KAAK,CAAC,OAAO,EAAE,CAAC,CAAC;QAC3C,CAAC;aAAM,CAAC;YACN,OAAO,CAAC,KAAK,CAAC,2BAA2B,CAAC,CAAC;QAC7C,CAAC;QACD,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IAClB,CAAC;AACH,CAAC;AAED,cAAc;AACd,IAAI,EAAE,CAAC"}
@@ -0,0 +1,17 @@
1
+ /**
2
+ * Generate command - Code generation for VeloxTS projects
3
+ *
4
+ * Usage:
5
+ * velox generate <type> <name> [options]
6
+ * velox g <type> <name> [options]
7
+ *
8
+ * Examples:
9
+ * velox generate procedure users --crud
10
+ * velox g p User
11
+ */
12
+ import { Command } from 'commander';
13
+ /**
14
+ * Create the generate command
15
+ */
16
+ export declare function createGenerateCommand(): Command;
17
+ //# sourceMappingURL=generate.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"generate.d.ts","sourceRoot":"","sources":["../../src/commands/generate.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAGH,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAqCpC;;GAEG;AACH,wBAAgB,qBAAqB,IAAI,OAAO,CAqD/C"}
@@ -0,0 +1,219 @@
1
+ /**
2
+ * Generate command - Code generation for VeloxTS projects
3
+ *
4
+ * Usage:
5
+ * velox generate <type> <name> [options]
6
+ * velox g <type> <name> [options]
7
+ *
8
+ * Examples:
9
+ * velox generate procedure users --crud
10
+ * velox g p User
11
+ */
12
+ import * as p from '@clack/prompts';
13
+ import { Command } from 'commander';
14
+ import pc from 'picocolors';
15
+ import { applyCliFlags, detectProjectContext, ensureVeloxProject, findSimilarGenerators, formatGeneratorList, formatWriteResults, formatWriteResultsJson, GeneratorError, GeneratorErrorCode, getAllGenerators, getGenerator, registerBuiltinGenerators, writeFiles, } from '../generators/index.js';
16
+ import { error, formatCommand, info, success } from '../utils/output.js';
17
+ // ============================================================================
18
+ // Command Creation
19
+ // ============================================================================
20
+ /**
21
+ * Create the generate command
22
+ */
23
+ export function createGenerateCommand() {
24
+ // Register built-in generators
25
+ registerBuiltinGenerators();
26
+ const cmd = new Command('generate')
27
+ .alias('g')
28
+ .description('Generate code for your VeloxTS project')
29
+ .argument('[type]', 'Generator type (procedure, schema, model, etc.)')
30
+ .argument('[name]', 'Name for the generated entity')
31
+ .option('-d, --dry-run', 'Preview changes without writing files', false)
32
+ .option('-f, --force', 'Overwrite existing files without prompting', false)
33
+ .option('--json', 'Output results as JSON', false)
34
+ // Generator-specific options (passed through to generators)
35
+ .option('-c, --crud', 'Generate full CRUD operations', false)
36
+ .option('-P, --paginated', 'Include pagination for list operation', false)
37
+ .option('-s, --soft-delete', 'Add soft delete support (model generator)', false)
38
+ .option('-t, --timestamps', 'Include timestamps (model generator)', true)
39
+ .option('-D, --database <type>', 'Database type: sqlite, postgresql, mysql', 'sqlite')
40
+ // Test generator options
41
+ .option('-T, --type <type>', 'Test type: unit, integration, e2e', 'unit')
42
+ .option('-G, --target <target>', 'Test target: procedure, schema, model, service, generic', 'generic')
43
+ // Resource generator options
44
+ .option('-W, --with-tests', 'Include test files (resource generator)', true)
45
+ .option('--skip-model', 'Skip Prisma model generation', false)
46
+ .option('--skip-schema', 'Skip Zod schema generation', false)
47
+ .option('--skip-procedure', 'Skip procedure generation', false)
48
+ .action(async (type, name, options) => {
49
+ await runGenerate(type, name, options);
50
+ });
51
+ // Add help showing available generators
52
+ cmd.addHelpText('after', `
53
+ Available generators:${formatGeneratorList()}
54
+
55
+ Examples:
56
+ ${formatCommand('velox generate resource Post')} Generate complete Post resource
57
+ ${formatCommand('velox g r User --soft-delete')} Resource with soft delete support
58
+ ${formatCommand('velox g p User --crud')} Generate CRUD procedures only
59
+ ${formatCommand('velox g s User --crud')} Generate Zod schemas only
60
+ ${formatCommand('velox g t User -G procedure')} Generate procedure unit tests
61
+ ${formatCommand('velox generate --dry-run r Post')} Preview resource generation
62
+ `);
63
+ return cmd;
64
+ }
65
+ // ============================================================================
66
+ // Command Execution
67
+ // ============================================================================
68
+ /**
69
+ * Run the generate command
70
+ */
71
+ async function runGenerate(type, name, options) {
72
+ const { json, dryRun, force } = options;
73
+ // JSON mode: suppress interactive output
74
+ const isInteractive = !json;
75
+ try {
76
+ // List generators if no type specified
77
+ if (!type) {
78
+ if (json) {
79
+ const generators = getAllGenerators().map((g) => ({
80
+ name: g.name,
81
+ aliases: g.generator.metadata.aliases ?? [],
82
+ description: g.generator.metadata.description,
83
+ category: g.generator.metadata.category,
84
+ }));
85
+ console.log(JSON.stringify({ generators }, null, 2));
86
+ return;
87
+ }
88
+ p.intro(pc.bgCyan(pc.black(' VeloxTS Generate ')));
89
+ console.log(formatGeneratorList());
90
+ console.log('');
91
+ info(`Run ${formatCommand('velox generate <type> <name>')} to generate code.`);
92
+ return;
93
+ }
94
+ // Find the generator
95
+ const generator = getGenerator(type);
96
+ if (!generator) {
97
+ const similar = findSimilarGenerators(type);
98
+ const suggestion = similar.length > 0
99
+ ? `Did you mean: ${similar.map((s) => pc.cyan(s)).join(', ')}?`
100
+ : `Run ${formatCommand('velox generate')} to see available generators.`;
101
+ throw new GeneratorError(GeneratorErrorCode.INVALID_OPTION, `Unknown generator: ${type}`, suggestion);
102
+ }
103
+ // Check for entity name
104
+ if (!name) {
105
+ throw new GeneratorError(GeneratorErrorCode.INVALID_ENTITY_NAME, 'Entity name is required', `Usage: ${formatCommand(`velox generate ${type} <name>`)}`);
106
+ }
107
+ // Validate entity name
108
+ const nameError = generator.validateEntityName(name);
109
+ if (nameError) {
110
+ throw new GeneratorError(GeneratorErrorCode.INVALID_ENTITY_NAME, nameError, 'Entity names must start with a letter and contain only letters, numbers, hyphens, or underscores.');
111
+ }
112
+ // Ensure we're in a VeloxTS project
113
+ const cwd = process.cwd();
114
+ await ensureVeloxProject(cwd);
115
+ // Detect project context
116
+ const project = await detectProjectContext(cwd);
117
+ // Extract generator-specific options (remove global flags)
118
+ const { dryRun: _d, force: _f, json: _j, ...generatorOptions } = options;
119
+ // Validate generator options
120
+ const validatedOptions = generator.validateOptions(generatorOptions);
121
+ // Build generator config
122
+ const config = applyCliFlags({
123
+ entityName: name,
124
+ options: validatedOptions,
125
+ conflictStrategy: 'prompt',
126
+ dryRun: false,
127
+ force: false,
128
+ cwd,
129
+ project,
130
+ }, { dryRun, force, json });
131
+ // Show spinner for generation
132
+ let output;
133
+ if (isInteractive) {
134
+ const s = p.spinner();
135
+ s.start(`Generating ${generator.metadata.name}...`);
136
+ try {
137
+ output = await generator.generate(config);
138
+ s.stop(`Generated ${output.files.length} file(s)`);
139
+ }
140
+ catch (err) {
141
+ s.stop('Generation failed');
142
+ throw err;
143
+ }
144
+ }
145
+ else {
146
+ output = await generator.generate(config);
147
+ }
148
+ // Write files
149
+ const writeResults = await writeFiles(output.files, {
150
+ conflictStrategy: config.conflictStrategy,
151
+ dryRun: config.dryRun,
152
+ force: config.force,
153
+ cwd,
154
+ silent: json,
155
+ });
156
+ // Output results
157
+ if (json) {
158
+ console.log(formatWriteResultsJson(writeResults));
159
+ }
160
+ else {
161
+ console.log('');
162
+ console.log(formatWriteResults(writeResults, dryRun));
163
+ // Show post-generation instructions
164
+ if (output.postInstructions && !dryRun) {
165
+ console.log('');
166
+ info('Next steps:');
167
+ console.log(output.postInstructions);
168
+ }
169
+ console.log('');
170
+ success(dryRun ? 'Dry run complete.' : 'Generation complete!');
171
+ }
172
+ }
173
+ catch (err) {
174
+ handleError(err, json);
175
+ process.exit(1);
176
+ }
177
+ }
178
+ // ============================================================================
179
+ // Error Handling
180
+ // ============================================================================
181
+ /**
182
+ * Handle errors with appropriate formatting
183
+ */
184
+ function handleError(err, json) {
185
+ if (err instanceof GeneratorError) {
186
+ if (json) {
187
+ console.log(JSON.stringify(err.toJSON(), null, 2));
188
+ }
189
+ else {
190
+ error(err.message);
191
+ if (err.fix) {
192
+ info(`Fix: ${err.fix}`);
193
+ }
194
+ }
195
+ return;
196
+ }
197
+ if (err instanceof Error) {
198
+ if (json) {
199
+ console.log(JSON.stringify({
200
+ code: 'E2005',
201
+ message: err.message,
202
+ }, null, 2));
203
+ }
204
+ else {
205
+ error(err.message);
206
+ }
207
+ return;
208
+ }
209
+ if (json) {
210
+ console.log(JSON.stringify({
211
+ code: 'E2005',
212
+ message: 'An unknown error occurred',
213
+ }, null, 2));
214
+ }
215
+ else {
216
+ error('An unknown error occurred');
217
+ }
218
+ }
219
+ //# sourceMappingURL=generate.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"generate.js","sourceRoot":"","sources":["../../src/commands/generate.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH,OAAO,KAAK,CAAC,MAAM,gBAAgB,CAAC;AACpC,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,OAAO,EAAE,MAAM,YAAY,CAAC;AAG5B,OAAO,EACL,aAAa,EACb,oBAAoB,EACpB,kBAAkB,EAClB,qBAAqB,EACrB,mBAAmB,EACnB,kBAAkB,EAClB,sBAAsB,EACtB,cAAc,EACd,kBAAkB,EAClB,gBAAgB,EAChB,YAAY,EACZ,yBAAyB,EACzB,UAAU,GACX,MAAM,wBAAwB,CAAC;AAChC,OAAO,EAAE,KAAK,EAAE,aAAa,EAAE,IAAI,EAAE,OAAO,EAAE,MAAM,oBAAoB,CAAC;AAczE,+EAA+E;AAC/E,mBAAmB;AACnB,+EAA+E;AAE/E;;GAEG;AACH,MAAM,UAAU,qBAAqB;IACnC,+BAA+B;IAC/B,yB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AAa;IAC9C,IAAI,GAAG,YAAY,cAAc,EAAE,CAAC;QAClC,IAAI,IAAI,EAAE,CAAC;YACT,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,MAAM,EAAE,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC,CAAC;QACrD,CAAC;aAAM,CAAC;YACN,KAAK,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC;YACnB,IAAI,GAAG,CAAC,GAAG,EAAE,CAAC;gBACZ,IAAI,CAAC,QAAQ,GAAG,CAAC,GAAG,EAAE,CAAC,CAAC;YAC1B,CAAC;QACH,CAAC;QACD,OAAO;IACT,CAAC;IAED,IAAI,GAAG,YAAY,KAAK,EAAE,CAAC;QACzB,IAAI,IAAI,EAAE,CAAC;YACT,OAAO,CAAC,GAAG,CACT,IAAI,CAAC,SAAS,CACZ;gBACE,IAAI,EAAE,OAAO;gBACb,OAAO,EAAE,GAAG,CAAC,OAAO;aACrB,EACD,IAAI,EACJ,CAAC,CACF,CACF,CAAC;QACJ,CAAC;aAAM,CAAC;YACN,KAAK,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC;QACrB,CAAC;QACD,OAAO;IACT,CAAC;IAED,IAAI,IAAI,EAAE,CAAC;QACT,OAAO,CAAC,GAAG,CACT,IAAI,CAAC,SAAS,CACZ;YACE,IAAI,EAAE,OAAO;YACb,OAAO,EAAE,2BAA2B;SACrC,EACD,IAAI,EACJ,CAAC,CACF,CACF,CAAC;IACJ,CAAC;SAAM,CAAC;QACN,KAAK,CAAC,2BAA2B,CAAC,CAAC;IACrC,CAAC;AACH,CAAC"}
@@ -1,11 +1,16 @@
1
1
  /**
2
- * Migrate command - Run database migrations
2
+ * Migrate command - Database migration commands
3
3
  *
4
- * Wrapper around Prisma migrations with beautiful Laravel-inspired output
4
+ * Provides subcommands for managing database migrations:
5
+ * - migrate:status - Show migration status
6
+ * - migrate:run - Run pending migrations
7
+ * - migrate:rollback - Rollback migrations
8
+ * - migrate:fresh - Drop all tables and re-run
9
+ * - migrate:reset - Rollback all then re-run
5
10
  */
6
11
  import { Command } from 'commander';
7
12
  /**
8
- * Create the migrate command
13
+ * Create the migrate command with subcommands
9
14
  */
10
15
  export declare function createMigrateCommand(): Command;
11
16
  //# sourceMappingURL=migrate.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"migrate.d.ts","sourceRoot":"","sources":["../../src/commands/migrate.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAMH,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAWpC;;GAEG;AACH,wBAAgB,oBAAoB,IAAI,OAAO,CAQ9C"}
1
+ {"version":3,"file":"migrate.d.ts","sourceRoot":"","sources":["../../src/commands/migrate.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAUpC;;GAEG;AACH,wBAAgB,oBAAoB,IAAI,OAAO,CAU9C"}
@@ -1,132 +1,26 @@
1
1
  /**
2
- * Migrate command - Run database migrations
2
+ * Migrate command - Database migration commands
3
3
  *
4
- * Wrapper around Prisma migrations with beautiful Laravel-inspired output
4
+ * Provides subcommands for managing database migrations:
5
+ * - migrate:status - Show migration status
6
+ * - migrate:run - Run pending migrations
7
+ * - migrate:rollback - Rollback migrations
8
+ * - migrate:fresh - Drop all tables and re-run
9
+ * - migrate:reset - Rollback all then re-run
5
10
  */
6
- import { spawn } from 'node:child_process';
7
- import path from 'node:path';
8
- import * as p from '@clack/prompts';
9
11
  import { Command } from 'commander';
10
- import pc from 'picocolors';
11
- import { error, formatCommand, info, instruction, success } from '../utils/output.js';
12
- import { fileExists } from '../utils/paths.js';
12
+ import { createMigrateFreshCommand, createMigrateResetCommand, createMigrateRollbackCommand, createMigrateRunCommand, createMigrateStatusCommand, } from '../migrations/commands/index.js';
13
13
  /**
14
- * Create the migrate command
14
+ * Create the migrate command with subcommands
15
15
  */
16
16
  export function createMigrateCommand() {
17
- return new Command('migrate')
18
- .description('Run database migrations')
19
- .option('--deploy', 'Run migrations in production mode (prisma migrate deploy)')
20
- .option('--force', 'Force push schema without migration (development only)')
21
- .action(async (options) => {
22
- await runMigrations(options);
23
- });
24
- }
25
- /**
26
- * Run database migrations
27
- */
28
- async function runMigrations(options) {
29
- const s = p.spinner();
30
- try {
31
- // Check if Prisma schema exists
32
- const schemaPath = path.join(process.cwd(), 'prisma', 'schema.prisma');
33
- if (!fileExists(schemaPath)) {
34
- error('Prisma schema not found.');
35
- instruction('Expected to find prisma/schema.prisma in the current directory.');
36
- instruction(`Initialize Prisma with: ${formatCommand('npx prisma init')}`);
37
- process.exit(1);
38
- }
39
- // Determine which command to run
40
- let command;
41
- let description;
42
- if (options.deploy) {
43
- // Production: Apply pending migrations
44
- command = ['prisma', 'migrate', 'deploy'];
45
- description = 'Applying production migrations';
46
- }
47
- else if (options.force) {
48
- // Development: Force push schema
49
- command = ['prisma', 'db', 'push', '--skip-generate'];
50
- description = 'Pushing database schema (development mode)';
51
- }
52
- else {
53
- // Development: Push with generate
54
- command = ['prisma', 'db', 'push'];
55
- description = 'Synchronizing database schema';
56
- }
57
- info(description);
58
- console.log('');
59
- s.start('Running Prisma...');
60
- // Run the Prisma command
61
- await new Promise((resolve, reject) => {
62
- const prismaProcess = spawn('npx', command, {
63
- stdio: 'inherit',
64
- shell: true,
65
- env: process.env,
66
- });
67
- prismaProcess.on('error', (err) => {
68
- reject(new Error(`Failed to run Prisma: ${err.message}`));
69
- });
70
- prismaProcess.on('exit', (code) => {
71
- if (code === 0) {
72
- resolve();
73
- }
74
- else {
75
- reject(new Error(`Prisma exited with code ${code}`));
76
- }
77
- });
78
- });
79
- s.stop('Migration completed');
80
- console.log('');
81
- success('Database schema synchronized successfully!');
82
- // Show next steps for production migrations
83
- if (options.deploy) {
84
- instruction('Your database is now up to date with the latest migrations.');
85
- }
86
- else {
87
- console.log('');
88
- info('Development tips:');
89
- console.log(` ${pc.dim('•')} Use ${formatCommand('velox migrate')} to sync schema changes during development`);
90
- console.log(` ${pc.dim('•')} Use ${formatCommand('velox migrate --deploy')} in production to apply migrations`);
91
- console.log(` ${pc.dim('•')} Use ${formatCommand('npx prisma studio')} to explore your database`);
92
- console.log('');
93
- }
94
- }
95
- catch (err) {
96
- s.stop('Migration failed');
97
- console.log('');
98
- if (err instanceof Error) {
99
- error(err.message);
100
- // Provide helpful suggestions based on error
101
- if (err.message.includes('P1001')) {
102
- instruction('Cannot reach database server. Check your connection:');
103
- console.log(` ${pc.dim('1.')} Verify DATABASE_URL in .env file`);
104
- console.log(` ${pc.dim('2.')} Ensure database server is running`);
105
- console.log(` ${pc.dim('3.')} Check network connectivity`);
106
- }
107
- else if (err.message.includes('P3009')) {
108
- instruction('Migration failed. Your changes may conflict with existing data.');
109
- console.log(` ${pc.dim('•')} Review the Prisma error above`);
110
- console.log(` ${pc.dim('•')} Consider creating a manual migration`);
111
- }
112
- else if (err.message.includes('P1003')) {
113
- instruction('Database does not exist. Create it first:');
114
- console.log(` ${pc.dim('•')} Check your DATABASE_URL`);
115
- console.log(` ${pc.dim('•')} Create the database manually if needed`);
116
- }
117
- else {
118
- instruction('Common solutions:');
119
- console.log(` ${pc.dim('1.')} Check your DATABASE_URL in .env`);
120
- console.log(` ${pc.dim('2.')} Ensure Prisma schema is valid: ${formatCommand('npx prisma validate')}`);
121
- console.log(` ${pc.dim('3.')} Review Prisma logs above for specific errors`);
122
- }
123
- console.log('');
124
- instruction(`For more help, see: ${pc.cyan('https://www.prisma.io/docs/reference/api-reference/command-reference')}`);
125
- }
126
- else {
127
- error('An unknown error occurred');
128
- }
129
- process.exit(1);
130
- }
17
+ const migrate = new Command('migrate')
18
+ .description('Database migration commands')
19
+ .addCommand(createMigrateStatusCommand())
20
+ .addCommand(createMigrateRunCommand())
21
+ .addCommand(createMigrateRollbackCommand())
22
+ .addCommand(createMigrateFreshCommand())
23
+ .addCommand(createMigrateResetCommand());
24
+ return migrate;
131
25
  }
132
26
  //# sourceMappingURL=migrate.js.map