-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathdeploy.command.ts
More file actions
582 lines (523 loc) · 19.8 KB
/
Copy pathdeploy.command.ts
File metadata and controls
582 lines (523 loc) · 19.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
import { Injectable } from '@nestjs/common';
import { Command, CommandRunner, Option } from 'nest-commander';
import { ComponentType } from '../interfaces/component-types.interface';
import {
SupportedPlatform,
ConflictStrategy,
} from '../interfaces/deploy-options.interface';
import { DeploymentResult } from '../interfaces/deployment-result.interface';
import { DeploymentReporterService } from '../services/deployment-reporter.service';
import { DeploymentService } from '../services/deployment.service';
import { ErrorMessageHelperService } from '../services/error-message-helper.service';
import { HelpDocumentationService } from '../services/help-documentation.service';
import { ImportService } from '../services/import.service';
interface DeployCommandOptions {
platform?: SupportedPlatform;
contextId?: string;
dryRun?: boolean;
validateOnly?: boolean;
conflictStrategy?: ConflictStrategy;
components?: string[];
skipComponents?: string[];
force?: boolean;
// Task 7.2: Cursor-specific options
cursorPath?: string;
workspacePath?: string;
skipAiConfig?: boolean;
skipExtensions?: boolean;
skipDebugConfig?: boolean;
skipTasks?: boolean;
skipSnippets?: boolean;
// Task 12.1: Help and documentation options
help?: boolean;
helpPlatform?: string;
helpComponent?: string;
listComponents?: boolean;
// Task 12.2: Reporting options
generateReport?: boolean;
reportFormat?: 'console' | 'json' | 'html' | 'markdown';
reportVerbose?: boolean;
saveReport?: boolean;
reportPath?: string;
}
@Command({
name: 'deploy',
description: 'Deploy Taptik context to target platform (Claude Code, Kiro IDE, Cursor IDE)',
})
@Injectable()
export class DeployCommand extends CommandRunner {
constructor(
private readonly importService: ImportService,
private readonly deploymentService: DeploymentService,
private readonly helpService: HelpDocumentationService,
private readonly errorHelper: ErrorMessageHelperService,
private readonly reporterService: DeploymentReporterService,
) {
super();
}
async run(
passedParameters: string[],
options: DeployCommandOptions,
): Promise<void> {
try {
// Task 12.1: Handle help and documentation requests
if (options.help) {
const helpContent = this.helpService.getDeployCommandHelp();
console.log(this.helpService.formatHelpForConsole(helpContent));
return;
}
if (options.helpPlatform) {
try {
const platformHelp = this.helpService.getPlatformHelp(options.helpPlatform as SupportedPlatform);
console.log(this.helpService.formatHelpForConsole(platformHelp));
return;
} catch (error) {
console.error(`❌ Unknown platform: ${options.helpPlatform}`);
console.log('📋 Available platforms: claude-code, kiro-ide, cursor-ide');
return;
}
}
if (options.helpComponent) {
const platform = options.platform || 'claude-code';
const componentHelp = this.helpService.getComponentHelp(options.helpComponent, platform);
if (componentHelp) {
console.log(this.helpService.formatComponentHelpForConsole(componentHelp));
return;
} else {
console.error(`❌ Component "${options.helpComponent}" not found for platform ${platform}`);
const suggestions = this.helpService.getComponentSuggestions(platform);
console.log(`📋 Available components for ${platform}: ${suggestions.join(', ')}`);
return;
}
}
if (options.listComponents) {
const platform = options.platform || 'claude-code';
const components = this.helpService.getComponentSuggestions(platform);
console.log(`📋 Available components for ${platform}:`);
components.forEach(component => {
const help = this.helpService.getComponentHelp(component, platform);
const description = help ? help.description : 'No description available';
console.log(` • ${component}: ${description}`);
});
return;
}
// Set default platform
const platform = options.platform || 'claude-code';
if (platform !== 'claude-code' && platform !== 'kiro-ide' && platform !== 'cursor-ide') {
console.error(
`❌ Platform '${platform}' is not supported. Supported platforms: 'claude-code', 'kiro-ide', 'cursor-ide'`,
);
process.exit(1);
}
// Task 7.2: Platform-specific deployment notes
if (platform === 'kiro-ide') {
// Note: Kiro deployment will show feature development status in results
} else if (platform === 'cursor-ide') {
console.log('💡 Cursor IDE deployment includes AI configuration, extensions, snippets, and workspace settings');
if (options.cursorPath) {
console.log(`📍 Using Cursor executable: ${options.cursorPath}`);
}
if (options.workspacePath) {
console.log(`📁 Target workspace: ${options.workspacePath}`);
}
}
console.log(`🚀 Starting deployment to ${platform}...`);
// Step 1: Import context from Supabase
console.log('📥 Importing context from Supabase...');
const context = await this.importService.importFromSupabase(
options.contextId || 'latest',
);
if (!context) {
console.error('❌ Failed to import context from Supabase');
process.exit(1);
}
console.log(
`✅ Context imported successfully: ${context.metadata?.title || 'Unnamed Context'}`,
);
// Task 12.1: Validate component names and provide suggestions
if (options.components) {
for (const componentName of options.components) {
const suggestion = this.helpService.validateComponentName(componentName, platform);
if (suggestion.suggestions.length === 0 || suggestion.suggestions[0].confidence < 1.0) {
console.error(`❌ Invalid component: "${componentName}" for platform ${platform}`);
if (suggestion.didYouMean) {
console.log(`💡 Did you mean: "${suggestion.didYouMean}"?`);
}
if (suggestion.examples && suggestion.examples.length > 0) {
console.log(`📋 Valid components: ${suggestion.examples.join(', ')}`);
}
process.exit(1);
}
}
}
if (options.skipComponents) {
for (const componentName of options.skipComponents) {
const suggestion = this.helpService.validateComponentName(componentName, platform);
if (suggestion.suggestions.length === 0 || suggestion.suggestions[0].confidence < 1.0) {
console.warn(`⚠️ Warning: Invalid skip component: "${componentName}" for platform ${platform}`);
if (suggestion.didYouMean) {
console.log(`💡 Did you mean: "${suggestion.didYouMean}"?`);
}
}
}
}
// Step 2: Prepare deployment options
const deployOptions = {
platform: platform as SupportedPlatform,
dryRun: options.dryRun || false,
validateOnly: options.validateOnly || false,
conflictStrategy: options.conflictStrategy || 'prompt',
components: options.components?.map((c) => c as ComponentType),
skipComponents: options.skipComponents?.map((c) => c as ComponentType),
// Task 7.2: Add Cursor-specific options to deployOptions
// FIXME: cursor specific options 점검
cursorPath: options.cursorPath,
workspacePath: options.workspacePath,
skipAiConfig: options.skipAiConfig,
skipExtensions: options.skipExtensions,
skipDebugConfig: options.skipDebugConfig,
skipTasks: options.skipTasks,
skipSnippets: options.skipSnippets,
};
// Step 3: Deploy to target platform
if (options.validateOnly) {
console.log('🔍 Running validation only...');
} else if (options.dryRun) {
console.log('🧪 Running in dry-run mode...');
} else {
const platformNames = {
'claude-code': 'Claude Code',
'kiro-ide': 'Kiro IDE',
'cursor-ide': 'Cursor IDE',
};
console.log(`🚀 Deploying to ${platformNames[platform as keyof typeof platformNames] || platform}...`);
}
// Step 3: Route to appropriate deployment method based on platform
let result: DeploymentResult;
if (platform === 'claude-code') {
result = await this.deploymentService.deployToClaudeCode(
context,
deployOptions,
);
} else if (platform === 'kiro-ide') {
result = await this.deploymentService.deployToKiro(
context,
deployOptions,
);
} else if (platform === 'cursor-ide') {
// Task 7.2: Add Cursor IDE deployment routing
result = await this.deploymentService.deployToCursor(
context,
deployOptions,
);
} else {
console.error(
`❌ Platform '${platform}' deployment is not implemented yet.`,
);
process.exit(5); // Platform Error exit code
}
// Step 4: Generate and display results
// Task 12.2: Enhanced reporting with detailed analysis
if (options.generateReport || options.reportFormat || options.saveReport) {
const reportOptions = {
includePerformance: true,
includeAnalysis: true,
includeArtifacts: options.saveReport || false,
exportFormat: options.reportFormat || 'console' as const,
saveToFile: options.saveReport || false,
outputPath: options.reportPath,
verboseLevel: options.reportVerbose ? 'detailed' as const : 'standard' as const,
};
const deploymentReport = await this.reporterService.generateDeploymentReport(
result,
platform,
context,
options.contextId || 'latest',
reportOptions,
);
if (options.reportFormat === 'console' || !options.reportFormat) {
console.log(this.reporterService.formatReportForConsole(deploymentReport, reportOptions.verboseLevel));
} else {
const exportPath = await this.reporterService.exportReport(
deploymentReport,
options.reportFormat,
options.reportPath,
);
console.log(`📄 Report exported to: ${exportPath}`);
}
// Display failure analysis if deployment failed
if (!result.success) {
const failureAnalysis = await this.reporterService.generateFailureAnalysis(
result,
platform,
{ workspacePath: options.workspacePath, contextId: options.contextId },
);
console.log(this.reporterService.formatFailureAnalysisForConsole(failureAnalysis));
}
} else {
// Standard result display
if (result.success) {
console.log('\n✅ Deployment successful!');
console.log(
`📦 Components deployed: ${result.deployedComponents.join(', ')}`,
);
console.log(`📊 Summary:`);
console.log(` - Files deployed: ${result.summary.filesDeployed}`);
console.log(` - Files skipped: ${result.summary.filesSkipped}`);
console.log(
` - Conflicts resolved: ${result.summary.conflictsResolved}`,
);
if (result.summary.backupCreated) {
console.log(` - Backup created: ✅`);
}
// Task 7.2: Platform-specific result display
if (platform === 'cursor-ide') {
console.log('\n🎯 Cursor IDE specific information:');
console.log(` - AI configuration applied: ${!options.skipAiConfig ? '✅' : '❌'}`);
console.log(` - Extensions processed: ${!options.skipExtensions ? '✅' : '❌'}`);
console.log(` - Debug config applied: ${!options.skipDebugConfig ? '✅' : '❌'}`);
console.log(` - Tasks configured: ${!options.skipTasks ? '✅' : '❌'}`);
console.log(` - Snippets deployed: ${!options.skipSnippets ? '✅' : '❌'}`);
}
if (result.warnings.length > 0) {
console.log('\n⚠️ Warnings:');
result.warnings.forEach((warning) => {
console.log(` - ${warning.message}`);
});
}
// Task 12.2: Suggest generating detailed report
if (result.warnings.length > 0 || platform === 'cursor-ide') {
console.log('\n💡 For detailed analysis and recommendations, use:');
console.log(` taptik deploy --generate-report --report-verbose`);
}
}
}
if (!result.success) {
console.error('\n❌ Deployment failed!');
if (result.errors.length > 0) {
console.error('🚨 Errors:');
result.errors.forEach((error) => {
// Task 12.1: Enhanced error reporting with solutions
const enhancedError = this.errorHelper.enhanceError(error, platform);
console.error(` - [${error.severity}] ${error.message}`);
if (enhancedError.quickFix) {
console.error(` 💡 Quick fix: ${enhancedError.quickFix}`);
}
if (enhancedError.solutions && enhancedError.solutions.length > 0) {
console.error(` 🔧 Solutions available: ${enhancedError.solutions.length}`);
console.error(` 💬 Run with --help-error ${enhancedError.errorCode || 'UNKNOWN'} for detailed solutions`);
}
});
}
process.exit(1);
}
} catch (error) {
// Task 12.1: Enhanced error handling for unexpected errors
const deploymentError = {
component: 'deploy-command',
type: 'unexpected-error',
severity: 'high' as const,
message: (error as Error).message,
suggestion: 'Check logs and try again, or contact support if issue persists',
};
const enhanced = this.errorHelper.enhanceError(deploymentError, platform);
console.error('\n❌ Unexpected error during deployment:');
console.error(this.errorHelper.generateUserFriendlyMessage(deploymentError, platform, false));
process.exit(1);
}
}
@Option({
flags: '-p, --platform <platform>',
description: 'Target platform ("claude-code", "kiro-ide", or "cursor-ide")',
defaultValue: 'claude-code',
})
parsePlatform(value: string): SupportedPlatform {
const supportedPlatforms: SupportedPlatform[] = ['claude-code', 'kiro-ide', 'cursor-ide'];
if (!supportedPlatforms.includes(value as SupportedPlatform)) {
throw new Error(
`Unsupported platform: ${value}. Supported platforms: ${supportedPlatforms.join(', ')}`,
);
}
return value as SupportedPlatform;
}
@Option({
flags: '-c, --context-id <id>',
description: 'Context ID to deploy (default: latest)',
})
parseContextId(value: string): string {
return value;
}
@Option({
flags: '-d, --dry-run',
description: 'Simulate deployment without making changes',
})
parseDryRun(): boolean {
return true;
}
@Option({
flags: '-v, --validate-only',
description: 'Only validate the configuration without deploying',
})
parseValidateOnly(): boolean {
return true;
}
@Option({
flags: '-s, --conflict-strategy <strategy>',
description:
'Strategy for handling conflicts (prompt, overwrite, merge, skip)',
defaultValue: 'prompt',
})
parseConflictStrategy(value: string): ConflictStrategy {
const validStrategies: ConflictStrategy[] = [
'prompt',
'overwrite',
'merge',
'skip',
];
if (!validStrategies.includes(value as ConflictStrategy)) {
throw new Error(`Invalid conflict strategy: ${value}`);
}
return value as ConflictStrategy;
}
@Option({
flags: '--components <components...>',
description:
'Specific components to deploy. Claude Code: (settings, agents, commands, project). Kiro IDE: (settings, steering, specs, hooks, agents, templates). Cursor IDE: (global-settings, project-settings, ai-config, extensions-config, debug-config, tasks-config, snippets-config, workspace-config)',
})
parseComponents(value: string, previous: string[] = []): string[] {
return [...previous, value];
}
@Option({
flags: '--skip-components <components...>',
description: 'Components to skip during deployment',
})
parseSkipComponents(value: string, previous: string[] = []): string[] {
return [...previous, value];
}
@Option({
flags: '-f, --force',
description: 'Force deployment without confirmation prompts',
})
parseForce(): boolean {
return true;
}
// Task 7.2: Cursor-specific options
@Option({
flags: '--cursor-path <path>',
description: 'Path to Cursor IDE executable (for cursor-ide platform)',
})
parseCursorPath(value: string): string {
return value;
}
@Option({
flags: '--workspace-path <path>',
description: 'Workspace path for Cursor deployment (default: current directory)',
})
parseWorkspacePath(value: string): string {
return value;
}
@Option({
flags: '--skip-ai-config',
description: 'Skip AI configuration deployment (cursor-ide only)',
})
parseSkipAiConfig(): boolean {
return true;
}
@Option({
flags: '--skip-extensions',
description: 'Skip extensions configuration (cursor-ide only)',
})
parseSkipExtensions(): boolean {
return true;
}
@Option({
flags: '--skip-debug-config',
description: 'Skip debug configuration deployment (cursor-ide only)',
})
parseSkipDebugConfig(): boolean {
return true;
}
@Option({
flags: '--skip-tasks',
description: 'Skip tasks configuration deployment (cursor-ide only)',
})
parseSkipTasks(): boolean {
return true;
}
@Option({
flags: '--skip-snippets',
description: 'Skip snippets deployment (cursor-ide only)',
})
parseSkipSnippets(): boolean {
return true;
}
// Task 12.1: Help and documentation options
@Option({
flags: '-h, --help',
description: 'Show comprehensive help for deploy command',
})
parseHelp(): boolean {
return true;
}
@Option({
flags: '--help-platform <platform>',
description: 'Show help for specific platform (claude-code, kiro-ide, cursor-ide)',
})
parseHelpPlatform(value: string): string {
return value;
}
@Option({
flags: '--help-component <component>',
description: 'Show help for specific component',
})
parseHelpComponent(value: string): string {
return value;
}
@Option({
flags: '--list-components',
description: 'List all available components for the specified platform',
})
parseListComponents(): boolean {
return true;
}
// Task 12.2: Reporting and feedback options
@Option({
flags: '--generate-report',
description: 'Generate comprehensive deployment report',
})
parseGenerateReport(): boolean {
return true;
}
@Option({
flags: '--report-format <format>',
description: 'Report format: console, json, html, markdown',
})
parseReportFormat(value: string): 'console' | 'json' | 'html' | 'markdown' {
const validFormats = ['console', 'json', 'html', 'markdown'];
if (!validFormats.includes(value)) {
throw new Error(`Invalid report format: ${value}. Valid formats: ${validFormats.join(', ')}`);
}
return value as 'console' | 'json' | 'html' | 'markdown';
}
@Option({
flags: '--report-verbose',
description: 'Generate detailed verbose report with performance metrics',
})
parseReportVerbose(): boolean {
return true;
}
@Option({
flags: '--save-report',
description: 'Save report to file (automatically enabled for non-console formats)',
})
parseSaveReport(): boolean {
return true;
}
@Option({
flags: '--report-path <path>',
description: 'Custom path for saving reports',
})
parseReportPath(value: string): string {
return value;
}
}