@veloxts/cli 0.4.0 → 0.4.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/dist/cli.js +2 -0
- package/dist/cli.js.map +1 -1
- package/dist/commands/generate.d.ts +17 -0
- package/dist/commands/generate.d.ts.map +1 -0
- package/dist/commands/generate.js +219 -0
- package/dist/commands/generate.js.map +1 -0
- package/dist/commands/migrate.d.ts +8 -3
- package/dist/commands/migrate.d.ts.map +1 -1
- package/dist/commands/migrate.js +17 -123
- package/dist/commands/migrate.js.map +1 -1
- package/dist/generators/base.d.ts +76 -0
- package/dist/generators/base.d.ts.map +1 -0
- package/dist/generators/base.js +271 -0
- package/dist/generators/base.js.map +1 -0
- package/dist/generators/generators/index.d.ts +17 -0
- package/dist/generators/generators/index.d.ts.map +1 -0
- package/dist/generators/generators/index.js +43 -0
- package/dist/generators/generators/index.js.map +1 -0
- package/dist/generators/generators/migration.d.ts +43 -0
- package/dist/generators/generators/migration.d.ts.map +1 -0
- package/dist/generators/generators/migration.js +121 -0
- package/dist/generators/generators/migration.js.map +1 -0
- package/dist/generators/generators/model.d.ts +38 -0
- package/dist/generators/generators/model.d.ts.map +1 -0
- package/dist/generators/generators/model.js +108 -0
- package/dist/generators/generators/model.js.map +1 -0
- package/dist/generators/generators/procedure.d.ts +37 -0
- package/dist/generators/generators/procedure.d.ts.map +1 -0
- package/dist/generators/generators/procedure.js +99 -0
- package/dist/generators/generators/procedure.js.map +1 -0
- package/dist/generators/generators/resource.d.ts +29 -0
- package/dist/generators/generators/resource.d.ts.map +1 -0
- package/dist/generators/generators/resource.js +124 -0
- package/dist/generators/generators/resource.js.map +1 -0
- package/dist/generators/generators/schema.d.ts +28 -0
- package/dist/generators/generators/schema.d.ts.map +1 -0
- package/dist/generators/generators/schema.js +83 -0
- package/dist/generators/generators/schema.js.map +1 -0
- package/dist/generators/generators/test.d.ts +28 -0
- package/dist/generators/generators/test.d.ts.map +1 -0
- package/dist/generators/generators/test.js +96 -0
- package/dist/generators/generators/test.js.map +1 -0
- package/dist/generators/index.d.ts +16 -0
- package/dist/generators/index.d.ts.map +1 -0
- package/dist/generators/index.js +16 -0
- package/dist/generators/index.js.map +1 -0
- package/dist/generators/registry.d.ts +97 -0
- package/dist/generators/registry.d.ts.map +1 -0
- package/dist/generators/registry.js +253 -0
- package/dist/generators/registry.js.map +1 -0
- package/dist/generators/templates/migration.d.ts +23 -0
- package/dist/generators/templates/migration.d.ts.map +1 -0
- package/dist/generators/templates/migration.js +389 -0
- package/dist/generators/templates/migration.js.map +1 -0
- package/dist/generators/templates/model.d.ts +37 -0
- package/dist/generators/templates/model.d.ts.map +1 -0
- package/dist/generators/templates/model.js +374 -0
- package/dist/generators/templates/model.js.map +1 -0
- package/dist/generators/templates/procedure.d.ts +25 -0
- package/dist/generators/templates/procedure.d.ts.map +1 -0
- package/dist/generators/templates/procedure.js +274 -0
- package/dist/generators/templates/procedure.js.map +1 -0
- package/dist/generators/templates/resource.d.ts +34 -0
- package/dist/generators/templates/resource.d.ts.map +1 -0
- package/dist/generators/templates/resource.js +550 -0
- package/dist/generators/templates/resource.js.map +1 -0
- package/dist/generators/templates/schema.d.ts +33 -0
- package/dist/generators/templates/schema.d.ts.map +1 -0
- package/dist/generators/templates/schema.js +248 -0
- package/dist/generators/templates/schema.js.map +1 -0
- package/dist/generators/templates/test.d.ts +31 -0
- package/dist/generators/templates/test.d.ts.map +1 -0
- package/dist/generators/templates/test.js +882 -0
- package/dist/generators/templates/test.js.map +1 -0
- package/dist/generators/types.d.ts +211 -0
- package/dist/generators/types.d.ts.map +1 -0
- package/dist/generators/types.js +54 -0
- package/dist/generators/types.js.map +1 -0
- package/dist/generators/utils/filesystem.d.ts +68 -0
- package/dist/generators/utils/filesystem.d.ts.map +1 -0
- package/dist/generators/utils/filesystem.js +217 -0
- package/dist/generators/utils/filesystem.js.map +1 -0
- package/dist/generators/utils/naming.d.ts +122 -0
- package/dist/generators/utils/naming.d.ts.map +1 -0
- package/dist/generators/utils/naming.js +198 -0
- package/dist/generators/utils/naming.js.map +1 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +4 -0
- package/dist/index.js.map +1 -1
- package/dist/migrations/commands/fresh.d.ts +11 -0
- package/dist/migrations/commands/fresh.d.ts.map +1 -0
- package/dist/migrations/commands/fresh.js +164 -0
- package/dist/migrations/commands/fresh.js.map +1 -0
- package/dist/migrations/commands/index.d.ts +11 -0
- package/dist/migrations/commands/index.d.ts.map +1 -0
- package/dist/migrations/commands/index.js +11 -0
- package/dist/migrations/commands/index.js.map +1 -0
- package/dist/migrations/commands/reset.d.ts +11 -0
- package/dist/migrations/commands/reset.d.ts.map +1 -0
- package/dist/migrations/commands/reset.js +258 -0
- package/dist/migrations/commands/reset.js.map +1 -0
- package/dist/migrations/commands/rollback.d.ts +11 -0
- package/dist/migrations/commands/rollback.d.ts.map +1 -0
- package/dist/migrations/commands/rollback.js +241 -0
- package/dist/migrations/commands/rollback.js.map +1 -0
- package/dist/migrations/commands/run.d.ts +11 -0
- package/dist/migrations/commands/run.d.ts.map +1 -0
- package/dist/migrations/commands/run.js +183 -0
- package/dist/migrations/commands/run.js.map +1 -0
- package/dist/migrations/commands/status.d.ts +11 -0
- package/dist/migrations/commands/status.d.ts.map +1 -0
- package/dist/migrations/commands/status.js +154 -0
- package/dist/migrations/commands/status.js.map +1 -0
- package/dist/migrations/errors.d.ts +74 -0
- package/dist/migrations/errors.d.ts.map +1 -0
- package/dist/migrations/errors.js +155 -0
- package/dist/migrations/errors.js.map +1 -0
- package/dist/migrations/index.d.ts +13 -0
- package/dist/migrations/index.d.ts.map +1 -0
- package/dist/migrations/index.js +17 -0
- package/dist/migrations/index.js.map +1 -0
- package/dist/migrations/loader.d.ts +44 -0
- package/dist/migrations/loader.d.ts.map +1 -0
- package/dist/migrations/loader.js +181 -0
- package/dist/migrations/loader.js.map +1 -0
- package/dist/migrations/prisma-wrapper.d.ts +60 -0
- package/dist/migrations/prisma-wrapper.d.ts.map +1 -0
- package/dist/migrations/prisma-wrapper.js +184 -0
- package/dist/migrations/prisma-wrapper.js.map +1 -0
- package/dist/migrations/rollback-runner.d.ts +40 -0
- package/dist/migrations/rollback-runner.d.ts.map +1 -0
- package/dist/migrations/rollback-runner.js +191 -0
- package/dist/migrations/rollback-runner.js.map +1 -0
- package/dist/migrations/types.d.ts +214 -0
- package/dist/migrations/types.d.ts.map +1 -0
- package/dist/migrations/types.js +19 -0
- package/dist/migrations/types.js.map +1 -0
- package/package.json +29 -8
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,EA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;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,qBAAqB,EAAE,CAAC,CAAC;IAC5C,OAAO,CAAC,UAAU,CAAC,oBAAoB,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,yBAAyB,EAAE,CAAC;IAE5B,MAAM,GAAG,GAAG,IAAI,OAAO,CAAC,UAAU,CAAC;SAChC,KAAK,CAAC,GAAG,CAAC;SACV,WAAW,CAAC,wCAAwC,CAAC;SACrD,QAAQ,CAAC,QAAQ,EAAE,iDAAiD,CAAC;SACrE,QAAQ,CAAC,QAAQ,EAAE,+BAA+B,CAAC;SACnD,MAAM,CAAC,eAAe,EAAE,uCAAuC,EAAE,KAAK,CAAC;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,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 -
|
|
2
|
+
* Migrate command - Database migration commands
|
|
3
3
|
*
|
|
4
|
-
*
|
|
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
|
|
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"}
|
package/dist/commands/migrate.js
CHANGED
|
@@ -1,132 +1,26 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Migrate command -
|
|
2
|
+
* Migrate command - Database migration commands
|
|
3
3
|
*
|
|
4
|
-
*
|
|
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
|
|
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
|
-
|
|
18
|
-
.description('
|
|
19
|
-
.
|
|
20
|
-
.
|
|
21
|
-
.
|
|
22
|
-
|
|
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
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"migrate.js","sourceRoot":"","sources":["../../src/commands/migrate.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"migrate.js","sourceRoot":"","sources":["../../src/commands/migrate.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAEpC,OAAO,EACL,yBAAyB,EACzB,yBAAyB,EACzB,4BAA4B,EAC5B,uBAAuB,EACvB,0BAA0B,GAC3B,MAAM,iCAAiC,CAAC;AAEzC;;GAEG;AACH,MAAM,UAAU,oBAAoB;IAClC,MAAM,OAAO,GAAG,IAAI,OAAO,CAAC,SAAS,CAAC;SACnC,WAAW,CAAC,6BAA6B,CAAC;SAC1C,UAAU,CAAC,0BAA0B,EAAE,CAAC;SACxC,UAAU,CAAC,uBAAuB,EAAE,CAAC;SACrC,UAAU,CAAC,4BAA4B,EAAE,CAAC;SAC1C,UAAU,CAAC,yBAAyB,EAAE,CAAC;SACvC,UAAU,CAAC,yBAAyB,EAAE,CAAC,CAAC;IAE3C,OAAO,OAAO,CAAC;AACjB,CAAC"}
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Base Generator Infrastructure
|
|
3
|
+
*
|
|
4
|
+
* Core utilities and base class for all VeloxTS code generators.
|
|
5
|
+
*/
|
|
6
|
+
import type { ConflictStrategy, Generator, GeneratorConfig, GeneratorMetadata, GeneratorOption, GeneratorOutput, ProjectContext, TemplateContext } from './types.js';
|
|
7
|
+
/**
|
|
8
|
+
* Ensure the current directory is a VeloxTS project
|
|
9
|
+
*
|
|
10
|
+
* @throws GeneratorError if not in a VeloxTS project
|
|
11
|
+
*/
|
|
12
|
+
export declare function ensureVeloxProject(cwd: string): Promise<void>;
|
|
13
|
+
/**
|
|
14
|
+
* Detect project configuration from package.json and velox config
|
|
15
|
+
*/
|
|
16
|
+
export declare function detectProjectContext(cwd: string): Promise<ProjectContext>;
|
|
17
|
+
/**
|
|
18
|
+
* Validate entity name format
|
|
19
|
+
*
|
|
20
|
+
* @returns Error message if invalid, undefined if valid
|
|
21
|
+
*/
|
|
22
|
+
export declare function validateEntityNameDefault(name: string): string | undefined;
|
|
23
|
+
/**
|
|
24
|
+
* Abstract base class for all generators.
|
|
25
|
+
* Provides common functionality and enforces the generator contract.
|
|
26
|
+
*/
|
|
27
|
+
export declare abstract class BaseGenerator<TOptions = Record<string, unknown>> implements Generator<TOptions> {
|
|
28
|
+
abstract readonly metadata: GeneratorMetadata;
|
|
29
|
+
abstract readonly options: ReadonlyArray<GeneratorOption>;
|
|
30
|
+
/**
|
|
31
|
+
* Default entity name validation.
|
|
32
|
+
* Override in subclasses for custom validation.
|
|
33
|
+
*/
|
|
34
|
+
validateEntityName(name: string): string | undefined;
|
|
35
|
+
/**
|
|
36
|
+
* Validate and transform raw CLI options to typed options.
|
|
37
|
+
* Override in subclasses to implement option validation.
|
|
38
|
+
*/
|
|
39
|
+
abstract validateOptions(raw: Record<string, unknown>): TOptions;
|
|
40
|
+
/**
|
|
41
|
+
* Generate files based on configuration.
|
|
42
|
+
* Must be implemented by subclasses.
|
|
43
|
+
*/
|
|
44
|
+
abstract generate(config: GeneratorConfig<TOptions>): Promise<GeneratorOutput>;
|
|
45
|
+
/**
|
|
46
|
+
* Create a template context for generation
|
|
47
|
+
*/
|
|
48
|
+
protected createContext(config: GeneratorConfig<TOptions>): TemplateContext<TOptions>;
|
|
49
|
+
/**
|
|
50
|
+
* Resolve output path relative to project root
|
|
51
|
+
*/
|
|
52
|
+
protected resolvePath(cwd: string, relativePath: string): string;
|
|
53
|
+
/**
|
|
54
|
+
* Check if a file would conflict (exists and shouldn't be overwritten)
|
|
55
|
+
*/
|
|
56
|
+
protected wouldConflict(filePath: string, strategy: ConflictStrategy, force: boolean): boolean;
|
|
57
|
+
/**
|
|
58
|
+
* Format a success message for generated files
|
|
59
|
+
*/
|
|
60
|
+
protected formatSuccessMessage(files: ReadonlyArray<{
|
|
61
|
+
path: string;
|
|
62
|
+
}>, dryRun: boolean): string;
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* Default generator configuration
|
|
66
|
+
*/
|
|
67
|
+
export declare function createDefaultConfig<TOptions>(entityName: string, options: TOptions, project: ProjectContext): Omit<GeneratorConfig<TOptions>, 'cwd'>;
|
|
68
|
+
/**
|
|
69
|
+
* Apply CLI flags to generator config
|
|
70
|
+
*/
|
|
71
|
+
export declare function applyCliFlags<TOptions>(config: GeneratorConfig<TOptions>, flags: {
|
|
72
|
+
dryRun?: boolean;
|
|
73
|
+
force?: boolean;
|
|
74
|
+
json?: boolean;
|
|
75
|
+
}): GeneratorConfig<TOptions>;
|
|
76
|
+
//# sourceMappingURL=base.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"base.d.ts","sourceRoot":"","sources":["../../src/generators/base.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAKH,OAAO,KAAK,EACV,gBAAgB,EAChB,SAAS,EACT,eAAe,EACf,iBAAiB,EACjB,eAAe,EACf,eAAe,EACf,cAAc,EACd,eAAe,EAChB,MAAM,YAAY,CAAC;AAapB;;;;GAIG;AACH,wBAAsB,kBAAkB,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CA0BnE;AAED;;GAEG;AACH,wBAAsB,oBAAoB,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,cAAc,CAAC,CA4B/E;AA2GD;;;;GAIG;AACH,wBAAgB,yBAAyB,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CA4B1E;AAMD;;;GAGG;AACH,8BAAsB,aAAa,CAAC,QAAQ,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CACpE,YAAW,SAAS,CAAC,QAAQ,CAAC;IAE9B,QAAQ,CAAC,QAAQ,CAAC,QAAQ,EAAE,iBAAiB,CAAC;IAC9C,QAAQ,CAAC,QAAQ,CAAC,OAAO,EAAE,aAAa,CAAC,eAAe,CAAC,CAAC;IAE1D;;;OAGG;IACH,kBAAkB,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS;IAIpD;;;OAGG;IACH,QAAQ,CAAC,eAAe,CAAC,GAAG,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,QAAQ;IAEhE;;;OAGG;IACH,QAAQ,CAAC,QAAQ,CAAC,MAAM,EAAE,eAAe,CAAC,QAAQ,CAAC,GAAG,OAAO,CAAC,eAAe,CAAC;IAM9E;;OAEG;IACH,SAAS,CAAC,aAAa,CAAC,MAA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