@paths.design/caws-cli 8.0.0 → 8.1.0
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/budget-derivation.d.ts +74 -0
- package/dist/budget-derivation.d.ts.map +1 -0
- package/dist/cicd-optimizer.d.ts +142 -0
- package/dist/cicd-optimizer.d.ts.map +1 -0
- package/dist/commands/archive.d.ts +51 -0
- package/dist/commands/archive.d.ts.map +1 -0
- package/dist/commands/archive.js +114 -6
- package/dist/commands/burnup.d.ts +6 -0
- package/dist/commands/burnup.d.ts.map +1 -0
- package/dist/commands/burnup.js +109 -10
- package/dist/commands/diagnose.d.ts +52 -0
- package/dist/commands/diagnose.d.ts.map +1 -0
- package/dist/commands/diagnose.js +1 -1
- package/dist/commands/evaluate.d.ts +8 -0
- package/dist/commands/evaluate.d.ts.map +1 -0
- package/dist/commands/init.d.ts +5 -0
- package/dist/commands/init.d.ts.map +1 -0
- package/dist/commands/iterate.d.ts +8 -0
- package/dist/commands/iterate.d.ts.map +1 -0
- package/dist/commands/mode.d.ts +24 -0
- package/dist/commands/mode.d.ts.map +1 -0
- package/dist/commands/mode.js +24 -14
- package/dist/commands/plan.d.ts +49 -0
- package/dist/commands/plan.d.ts.map +1 -0
- package/dist/commands/provenance.d.ts +32 -0
- package/dist/commands/provenance.d.ts.map +1 -0
- package/dist/commands/provenance.js +216 -93
- package/dist/commands/quality-gates.d.ts +6 -0
- package/dist/commands/quality-gates.d.ts.map +1 -0
- package/dist/commands/quality-gates.js +82 -3
- package/dist/commands/quality-monitor.d.ts +17 -0
- package/dist/commands/quality-monitor.d.ts.map +1 -0
- package/dist/commands/specs.d.ts +71 -0
- package/dist/commands/specs.d.ts.map +1 -0
- package/dist/commands/specs.js +184 -6
- package/dist/commands/status.d.ts +44 -0
- package/dist/commands/status.d.ts.map +1 -0
- package/dist/commands/status.js +134 -10
- package/dist/commands/templates.d.ts +74 -0
- package/dist/commands/templates.d.ts.map +1 -0
- package/dist/commands/templates.js +2 -2
- package/dist/commands/tool.d.ts +13 -0
- package/dist/commands/tool.d.ts.map +1 -0
- package/dist/commands/troubleshoot.d.ts +8 -0
- package/dist/commands/troubleshoot.d.ts.map +1 -0
- package/dist/commands/tutorial.d.ts +55 -0
- package/dist/commands/tutorial.d.ts.map +1 -0
- package/dist/commands/validate.d.ts +15 -0
- package/dist/commands/validate.d.ts.map +1 -0
- package/dist/commands/waivers.d.ts +8 -0
- package/dist/commands/waivers.d.ts.map +1 -0
- package/dist/commands/workflow.d.ts +85 -0
- package/dist/commands/workflow.d.ts.map +1 -0
- package/dist/config/index.d.ts +29 -0
- package/dist/config/index.d.ts.map +1 -0
- package/dist/config/modes.d.ts +225 -0
- package/dist/config/modes.d.ts.map +1 -0
- package/dist/constants/spec-types.d.ts +41 -0
- package/dist/constants/spec-types.d.ts.map +1 -0
- package/dist/error-handler.d.ts +164 -0
- package/dist/error-handler.d.ts.map +1 -0
- package/dist/error-handler.js +6 -98
- package/dist/generators/jest-config-generator.js +242 -0
- package/dist/generators/jest-config.d.ts +32 -0
- package/dist/generators/jest-config.d.ts.map +1 -0
- package/dist/generators/working-spec.d.ts +13 -0
- package/dist/generators/working-spec.d.ts.map +1 -0
- package/dist/index-new.d.ts +5 -0
- package/dist/index-new.d.ts.map +1 -0
- package/dist/index-new.js +317 -0
- package/dist/index.d.ts +5 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +14 -7
- package/dist/index.js.backup +4711 -0
- package/dist/minimal-cli.d.ts +3 -0
- package/dist/minimal-cli.d.ts.map +1 -0
- package/dist/minimal-cli.js +3 -1
- package/dist/policy/PolicyManager.d.ts +104 -0
- package/dist/policy/PolicyManager.d.ts.map +1 -0
- package/dist/scaffold/claude-hooks.js +316 -0
- package/dist/scaffold/cursor-hooks.d.ts +7 -0
- package/dist/scaffold/cursor-hooks.d.ts.map +1 -0
- package/dist/scaffold/git-hooks.d.ts +38 -0
- package/dist/scaffold/git-hooks.d.ts.map +1 -0
- package/dist/scaffold/index.d.ts +15 -0
- package/dist/scaffold/index.d.ts.map +1 -0
- package/dist/scaffold/index.js +18 -0
- package/dist/spec/SpecFileManager.d.ts +146 -0
- package/dist/spec/SpecFileManager.d.ts.map +1 -0
- package/dist/templates/.claude/README.md +190 -0
- package/dist/templates/.claude/hooks/audit.sh +96 -0
- package/dist/templates/.claude/hooks/block-dangerous.sh +90 -0
- package/dist/templates/.claude/hooks/naming-check.sh +97 -0
- package/dist/templates/.claude/hooks/quality-check.sh +68 -0
- package/dist/templates/.claude/hooks/scan-secrets.sh +85 -0
- package/dist/templates/.claude/hooks/scope-guard.sh +105 -0
- package/dist/templates/.claude/hooks/validate-spec.sh +76 -0
- package/dist/templates/.claude/settings.json +95 -0
- package/dist/test-analysis.d.ts +182 -0
- package/dist/test-analysis.d.ts.map +1 -0
- package/dist/test-analysis.js +203 -10
- package/dist/tool-interface.d.ts +236 -0
- package/dist/tool-interface.d.ts.map +1 -0
- package/dist/tool-loader.d.ts +77 -0
- package/dist/tool-loader.d.ts.map +1 -0
- package/dist/tool-validator.d.ts +72 -0
- package/dist/tool-validator.d.ts.map +1 -0
- package/dist/utils/async-utils.d.ts +73 -0
- package/dist/utils/async-utils.d.ts.map +1 -0
- package/dist/utils/command-wrapper.d.ts +66 -0
- package/dist/utils/command-wrapper.d.ts.map +1 -0
- package/dist/utils/detection.d.ts +14 -0
- package/dist/utils/detection.d.ts.map +1 -0
- package/dist/utils/error-categories.js +210 -0
- package/dist/utils/finalization.d.ts +17 -0
- package/dist/utils/finalization.d.ts.map +1 -0
- package/dist/utils/git-lock.d.ts +13 -0
- package/dist/utils/git-lock.d.ts.map +1 -0
- package/dist/utils/gitignore-updater.d.ts +39 -0
- package/dist/utils/gitignore-updater.d.ts.map +1 -0
- package/dist/utils/project-analysis.d.ts +34 -0
- package/dist/utils/project-analysis.d.ts.map +1 -0
- package/dist/utils/promise-utils.d.ts +30 -0
- package/dist/utils/promise-utils.d.ts.map +1 -0
- package/dist/utils/quality-gates-utils.js +402 -0
- package/dist/utils/quality-gates.d.ts +49 -0
- package/dist/utils/quality-gates.d.ts.map +1 -0
- package/dist/utils/spec-resolver.d.ts +80 -0
- package/dist/utils/spec-resolver.d.ts.map +1 -0
- package/dist/utils/typescript-detector.d.ts +63 -0
- package/dist/utils/typescript-detector.d.ts.map +1 -0
- package/dist/utils/typescript-detector.js +36 -90
- package/dist/utils/yaml-validation.d.ts +32 -0
- package/dist/utils/yaml-validation.d.ts.map +1 -0
- package/dist/validation/spec-validation.d.ts +43 -0
- package/dist/validation/spec-validation.d.ts.map +1 -0
- package/dist/validation/spec-validation.js +59 -6
- package/dist/waivers-manager.d.ts +167 -0
- package/dist/waivers-manager.d.ts.map +1 -0
- package/package.json +5 -3
- package/templates/.claude/README.md +190 -0
- package/templates/.claude/hooks/audit.sh +96 -0
- package/templates/.claude/hooks/block-dangerous.sh +90 -0
- package/templates/.claude/hooks/naming-check.sh +97 -0
- package/templates/.claude/hooks/quality-check.sh +68 -0
- package/templates/.claude/hooks/scan-secrets.sh +85 -0
- package/templates/.claude/hooks/scope-guard.sh +105 -0
- package/templates/.claude/hooks/validate-spec.sh +76 -0
- package/templates/.claude/settings.json +95 -0
|
@@ -0,0 +1,164 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Enhanced error class with category and recovery suggestions
|
|
3
|
+
*/
|
|
4
|
+
export class CAWSError extends Error {
|
|
5
|
+
constructor(message: any, category?: any, suggestions?: any[]);
|
|
6
|
+
category: any;
|
|
7
|
+
suggestions: any[];
|
|
8
|
+
timestamp: Date;
|
|
9
|
+
executionTime: any;
|
|
10
|
+
}
|
|
11
|
+
export namespace ERROR_CATEGORIES {
|
|
12
|
+
let VALIDATION: string;
|
|
13
|
+
let PERMISSION: string;
|
|
14
|
+
let FILESYSTEM: string;
|
|
15
|
+
let NETWORK: string;
|
|
16
|
+
let CONFIGURATION: string;
|
|
17
|
+
let USER_INPUT: string;
|
|
18
|
+
let DEPENDENCY: string;
|
|
19
|
+
let UNKNOWN: string;
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Execution timing utilities
|
|
23
|
+
*/
|
|
24
|
+
export class ExecutionTimer {
|
|
25
|
+
startTime: bigint;
|
|
26
|
+
endTime: bigint;
|
|
27
|
+
start(): void;
|
|
28
|
+
end(): number;
|
|
29
|
+
getDuration(): number;
|
|
30
|
+
formatDuration(): string;
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Get error category from error object or message
|
|
34
|
+
* @param {Error|string} error - Error object or message
|
|
35
|
+
* @returns {string} Error category
|
|
36
|
+
*/
|
|
37
|
+
export function getErrorCategory(error: Error | string): string;
|
|
38
|
+
/**
|
|
39
|
+
* Wrap async operations with consistent error handling and timing
|
|
40
|
+
* @param {Function} operation - Async operation to wrap
|
|
41
|
+
* @param {string} context - Context for error messages
|
|
42
|
+
* @param {boolean} includeTiming - Whether to include timing in results
|
|
43
|
+
* @returns {Promise<any>} Operation result or throws handled error
|
|
44
|
+
*/
|
|
45
|
+
export function safeAsync(operation: Function, context?: string, includeTiming?: boolean): Promise<any>;
|
|
46
|
+
/**
|
|
47
|
+
* Wrap sync operations with timing
|
|
48
|
+
* @param {Function} operation - Sync operation to wrap
|
|
49
|
+
* @param {string} context - Context for error messages
|
|
50
|
+
* @param {boolean} includeTiming - Whether to include timing in results
|
|
51
|
+
* @returns {any} Operation result or throws handled error
|
|
52
|
+
*/
|
|
53
|
+
export function safeSync(operation: Function, context?: string, includeTiming?: boolean): any;
|
|
54
|
+
/**
|
|
55
|
+
* Handle CLI errors with consistent formatting and user guidance
|
|
56
|
+
* @param {Error} error - Error to handle
|
|
57
|
+
* @param {Object} context - Error context (command, option, etc.)
|
|
58
|
+
* @param {boolean} exit - Whether to exit the process (default: true)
|
|
59
|
+
*/
|
|
60
|
+
export function handleCliError(error: Error, context?: any, exit?: boolean): void;
|
|
61
|
+
/**
|
|
62
|
+
* Validate required environment and dependencies
|
|
63
|
+
* @returns {Object} Validation result with any errors
|
|
64
|
+
*/
|
|
65
|
+
export function validateEnvironment(): any;
|
|
66
|
+
/**
|
|
67
|
+
* Get recovery suggestions based on error category
|
|
68
|
+
* @param {Error} error - Original error
|
|
69
|
+
* @param {string} category - Error category
|
|
70
|
+
* @param {Object} context - Additional context (command, options, etc.)
|
|
71
|
+
* @returns {string[]} Array of recovery suggestions
|
|
72
|
+
*/
|
|
73
|
+
export function getRecoverySuggestions(error: Error, category: string, context?: any): string[];
|
|
74
|
+
/**
|
|
75
|
+
* Get documentation link for error category
|
|
76
|
+
* @param {string} category - Error category
|
|
77
|
+
* @param {Object} context - Additional context
|
|
78
|
+
* @returns {string} Documentation URL
|
|
79
|
+
*/
|
|
80
|
+
export function getDocumentationLink(category: string, context?: any): string;
|
|
81
|
+
/**
|
|
82
|
+
* Find similar command using Levenshtein distance
|
|
83
|
+
* @param {string} input - User's input command
|
|
84
|
+
* @param {string[]} validCommands - List of valid commands
|
|
85
|
+
* @returns {string|null} Most similar command or null
|
|
86
|
+
*/
|
|
87
|
+
export function findSimilarCommand(input: string, validCommands: string[]): string | null;
|
|
88
|
+
/**
|
|
89
|
+
* Command-specific error suggestions
|
|
90
|
+
*/
|
|
91
|
+
export const COMMAND_SUGGESTIONS: {
|
|
92
|
+
'unknown option': (option: any, command: any) => any[];
|
|
93
|
+
'unknown command': (command: any) => string[];
|
|
94
|
+
'template not found': () => string[];
|
|
95
|
+
'not a caws project': () => string[];
|
|
96
|
+
};
|
|
97
|
+
/**
|
|
98
|
+
* JSON output formatter for programmatic use
|
|
99
|
+
* @param {Object} data - Data to format as JSON
|
|
100
|
+
* @param {boolean} pretty - Whether to pretty-print (default: true)
|
|
101
|
+
*/
|
|
102
|
+
export function formatJsonOutput(data: any, pretty?: boolean): string;
|
|
103
|
+
/**
|
|
104
|
+
* Check if user requested JSON output
|
|
105
|
+
* @returns {boolean} True if --json flag is present
|
|
106
|
+
*/
|
|
107
|
+
export function isJsonOutput(): boolean;
|
|
108
|
+
/**
|
|
109
|
+
* Output data in appropriate format (JSON or human-readable)
|
|
110
|
+
* @param {Object} data - Data to output
|
|
111
|
+
* @param {boolean} success - Whether this is a success response
|
|
112
|
+
*/
|
|
113
|
+
export function outputResult(data: any, success?: boolean): any;
|
|
114
|
+
/**
|
|
115
|
+
* Troubleshooting guide system
|
|
116
|
+
*/
|
|
117
|
+
export const TROUBLESHOOTING_GUIDES: {
|
|
118
|
+
'coverage-report-not-found': {
|
|
119
|
+
title: string;
|
|
120
|
+
symptoms: string[];
|
|
121
|
+
rootCauses: string[];
|
|
122
|
+
solutions: string[];
|
|
123
|
+
commands: string[];
|
|
124
|
+
};
|
|
125
|
+
'mutation-report-not-found': {
|
|
126
|
+
title: string;
|
|
127
|
+
symptoms: string[];
|
|
128
|
+
rootCauses: string[];
|
|
129
|
+
solutions: string[];
|
|
130
|
+
commands: string[];
|
|
131
|
+
};
|
|
132
|
+
'working-spec-validation': {
|
|
133
|
+
title: string;
|
|
134
|
+
symptoms: string[];
|
|
135
|
+
rootCauses: string[];
|
|
136
|
+
solutions: string[];
|
|
137
|
+
commands: string[];
|
|
138
|
+
};
|
|
139
|
+
'monorepo-detection': {
|
|
140
|
+
title: string;
|
|
141
|
+
symptoms: string[];
|
|
142
|
+
rootCauses: string[];
|
|
143
|
+
solutions: string[];
|
|
144
|
+
commands: string[];
|
|
145
|
+
};
|
|
146
|
+
};
|
|
147
|
+
/**
|
|
148
|
+
* Get troubleshooting guide for a specific issue
|
|
149
|
+
* @param {string} issueKey - Key for the troubleshooting guide
|
|
150
|
+
* @returns {Object|null} Troubleshooting guide or null if not found
|
|
151
|
+
*/
|
|
152
|
+
export function getTroubleshootingGuide(issueKey: string): any | null;
|
|
153
|
+
/**
|
|
154
|
+
* Get all available troubleshooting guides
|
|
155
|
+
* @returns {Object} All troubleshooting guides
|
|
156
|
+
*/
|
|
157
|
+
export function getAllTroubleshootingGuides(): any;
|
|
158
|
+
/**
|
|
159
|
+
* Suggest troubleshooting guide based on error message
|
|
160
|
+
* @param {string} errorMessage - Error message to analyze
|
|
161
|
+
* @returns {string|null} Issue key if match found, null otherwise
|
|
162
|
+
*/
|
|
163
|
+
export function suggestTroubleshootingGuide(errorMessage: string): string | null;
|
|
164
|
+
//# sourceMappingURL=error-handler.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"error-handler.d.ts","sourceRoot":"","sources":["../src/error-handler.js"],"names":[],"mappings":"AA0GA;;GAEG;AACH;IACE,+DAOC;IAJC,cAAqD;IACrD,mBAA2F;IAC3F,gBAA2B;IAC3B,mBAAyB;CAE5B;;;;;;;;;;;AAED;;GAEG;AACH;IAEI,kBAAqB;IACrB,gBAAmB;IAGrB,cAEC;IAED,cAGC;IAED,sBAIC;IAED,yBAMC;CACF;AAjHD;;;;GAIG;AACH,wCAHW,KAAK,GAAC,MAAM,GACV,MAAM,CA+DlB;AAiDD;;;;;;GAMG;AACH,yDAJW,MAAM,kBACN,OAAO,GACL,OAAO,CAAC,GAAG,CAAC,CA8BxB;AAED;;;;;;GAMG;AACH,wDAJW,MAAM,kBACN,OAAO,GACL,GAAG,CA8Bf;AAgSD;;;;;GAKG;AACH,sCAJW,KAAK,wBAEL,OAAO,QAmDjB;AA0JD;;;GAGG;AACH,2CAqBC;AAnXD;;;;;;GAMG;AACH,8CALW,KAAK,YACL,MAAM,kBAEJ,MAAM,EAAE,CAwDpB;AAED;;;;;GAKG;AACH,+CAJW,MAAM,kBAEJ,MAAM,CA4BlB;AAxJD;;;;;GAKG;AACH,0CAJW,MAAM,iBACN,MAAM,EAAE,GACN,MAAM,GAAC,IAAI,CAiBvB;AAjHD;;GAEG;AACH;;;;;EAuFE;AA4JF;;;;GAIG;AACH,qDAFW,OAAO,UAIjB;AAED;;;GAGG;AACH,gCAFa,OAAO,CAQnB;AAED;;;;GAIG;AACH,kDAFW,OAAO,OAcjB;AA2DD;;GAEG;AACH;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EA0GE;AAEF;;;;GAIG;AACH,kDAHW,MAAM,GACJ,MAAO,IAAI,CAIvB;AAED;;;GAGG;AACH,mDAEC;AAED;;;;GAIG;AACH,0DAHW,MAAM,GACJ,MAAM,GAAC,IAAI,CAmBvB"}
|
package/dist/error-handler.js
CHANGED
|
@@ -5,104 +5,12 @@
|
|
|
5
5
|
*/
|
|
6
6
|
|
|
7
7
|
const chalk = require('chalk');
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
PERMISSION: 'permission',
|
|
15
|
-
FILESYSTEM: 'filesystem',
|
|
16
|
-
NETWORK: 'network',
|
|
17
|
-
CONFIGURATION: 'configuration',
|
|
18
|
-
USER_INPUT: 'user_input',
|
|
19
|
-
DEPENDENCY: 'dependency',
|
|
20
|
-
UNKNOWN: 'unknown',
|
|
21
|
-
};
|
|
22
|
-
|
|
23
|
-
/**
|
|
24
|
-
* Error code mappings for common system errors
|
|
25
|
-
*/
|
|
26
|
-
const ERROR_CODES = {
|
|
27
|
-
EACCES: ERROR_CATEGORIES.PERMISSION,
|
|
28
|
-
EPERM: ERROR_CATEGORIES.PERMISSION,
|
|
29
|
-
ENOENT: ERROR_CATEGORIES.FILESYSTEM,
|
|
30
|
-
ENOTFOUND: ERROR_CATEGORIES.NETWORK,
|
|
31
|
-
ECONNREFUSED: ERROR_CATEGORIES.NETWORK,
|
|
32
|
-
ETIMEDOUT: ERROR_CATEGORIES.NETWORK,
|
|
33
|
-
ENOSPC: ERROR_CATEGORIES.FILESYSTEM,
|
|
34
|
-
EEXIST: ERROR_CATEGORIES.FILESYSTEM,
|
|
35
|
-
EISDIR: ERROR_CATEGORIES.FILESYSTEM,
|
|
36
|
-
ENOTDIR: ERROR_CATEGORIES.FILESYSTEM,
|
|
37
|
-
};
|
|
38
|
-
|
|
39
|
-
/**
|
|
40
|
-
* Get error category from error object or message
|
|
41
|
-
* @param {Error|string} error - Error object or message
|
|
42
|
-
* @returns {string} Error category
|
|
43
|
-
*/
|
|
44
|
-
function getErrorCategory(error) {
|
|
45
|
-
const errorMessage = typeof error === 'string' ? error : error.message;
|
|
46
|
-
const errorCode = typeof error === 'object' && error.code ? error.code : null;
|
|
47
|
-
|
|
48
|
-
// Check error codes first
|
|
49
|
-
if (errorCode && ERROR_CODES[errorCode]) {
|
|
50
|
-
return ERROR_CODES[errorCode];
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
// Check message patterns
|
|
54
|
-
const lowerMessage = errorMessage.toLowerCase();
|
|
55
|
-
|
|
56
|
-
if (
|
|
57
|
-
lowerMessage.includes('validation') ||
|
|
58
|
-
lowerMessage.includes('invalid') ||
|
|
59
|
-
lowerMessage.includes('required')
|
|
60
|
-
) {
|
|
61
|
-
return ERROR_CATEGORIES.VALIDATION;
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
if (
|
|
65
|
-
lowerMessage.includes('permission') ||
|
|
66
|
-
lowerMessage.includes('access') ||
|
|
67
|
-
lowerMessage.includes('denied')
|
|
68
|
-
) {
|
|
69
|
-
return ERROR_CATEGORIES.PERMISSION;
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
if (
|
|
73
|
-
lowerMessage.includes('file') ||
|
|
74
|
-
lowerMessage.includes('directory') ||
|
|
75
|
-
lowerMessage.includes('path')
|
|
76
|
-
) {
|
|
77
|
-
return ERROR_CATEGORIES.FILESYSTEM;
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
if (
|
|
81
|
-
lowerMessage.includes('network') ||
|
|
82
|
-
lowerMessage.includes('connection') ||
|
|
83
|
-
lowerMessage.includes('timeout')
|
|
84
|
-
) {
|
|
85
|
-
return ERROR_CATEGORIES.NETWORK;
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
if (
|
|
89
|
-
lowerMessage.includes('config') ||
|
|
90
|
-
lowerMessage.includes('setting') ||
|
|
91
|
-
lowerMessage.includes('option')
|
|
92
|
-
) {
|
|
93
|
-
return ERROR_CATEGORIES.CONFIGURATION;
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
if (
|
|
97
|
-
lowerMessage.includes('input') ||
|
|
98
|
-
lowerMessage.includes('prompt') ||
|
|
99
|
-
lowerMessage.includes('answer')
|
|
100
|
-
) {
|
|
101
|
-
return ERROR_CATEGORIES.USER_INPUT;
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
return ERROR_CATEGORIES.UNKNOWN;
|
|
105
|
-
}
|
|
8
|
+
const {
|
|
9
|
+
ERROR_CATEGORIES,
|
|
10
|
+
ERROR_CODES,
|
|
11
|
+
getErrorCategory,
|
|
12
|
+
getCategorySuggestions,
|
|
13
|
+
} = require('./utils/error-categories');
|
|
106
14
|
|
|
107
15
|
/**
|
|
108
16
|
* Enhanced error class with category and recovery suggestions
|
|
@@ -0,0 +1,242 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview Jest Configuration Generator
|
|
3
|
+
* Generates Jest configuration for TypeScript projects
|
|
4
|
+
* @author @darianrosebrook
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
const fs = require('fs-extra');
|
|
8
|
+
const path = require('path');
|
|
9
|
+
const chalk = require('chalk');
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Generate Jest configuration for TypeScript project
|
|
13
|
+
* @param {Object} options - Configuration options
|
|
14
|
+
* @returns {string} Jest configuration content
|
|
15
|
+
*/
|
|
16
|
+
function generateJestConfig(options = {}) {
|
|
17
|
+
const {
|
|
18
|
+
preset = 'ts-jest',
|
|
19
|
+
testEnvironment = 'node',
|
|
20
|
+
rootDir = '.',
|
|
21
|
+
testMatch = ['**/__tests__/**/*.ts', '**/?(*.)+(spec|test).ts'],
|
|
22
|
+
moduleFileExtensions = ['ts', 'tsx', 'js', 'jsx', 'json', 'node'],
|
|
23
|
+
collectCoverageFrom = ['src/**/*.ts', '!src/**/*.d.ts', '!src/**/*.test.ts'],
|
|
24
|
+
coverageThreshold = {
|
|
25
|
+
global: {
|
|
26
|
+
branches: 80,
|
|
27
|
+
functions: 80,
|
|
28
|
+
lines: 80,
|
|
29
|
+
statements: 80,
|
|
30
|
+
},
|
|
31
|
+
},
|
|
32
|
+
} = options;
|
|
33
|
+
|
|
34
|
+
const config = {
|
|
35
|
+
preset,
|
|
36
|
+
testEnvironment,
|
|
37
|
+
rootDir,
|
|
38
|
+
testMatch,
|
|
39
|
+
moduleFileExtensions,
|
|
40
|
+
collectCoverageFrom,
|
|
41
|
+
coverageThreshold,
|
|
42
|
+
transform: {
|
|
43
|
+
'^.+\\.tsx?$': [
|
|
44
|
+
'ts-jest',
|
|
45
|
+
{
|
|
46
|
+
tsconfig: 'tsconfig.json',
|
|
47
|
+
},
|
|
48
|
+
],
|
|
49
|
+
},
|
|
50
|
+
moduleNameMapper: {
|
|
51
|
+
'^@/(.*)$': '<rootDir>/src/$1',
|
|
52
|
+
},
|
|
53
|
+
};
|
|
54
|
+
|
|
55
|
+
return `module.exports = ${JSON.stringify(config, null, 2)};\n`;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* Generate test setup file for TypeScript
|
|
60
|
+
* @returns {string} Setup file content
|
|
61
|
+
*/
|
|
62
|
+
function generateTestSetup() {
|
|
63
|
+
return `/**
|
|
64
|
+
* Jest setup file for TypeScript tests
|
|
65
|
+
* @author @darianrosebrook
|
|
66
|
+
*/
|
|
67
|
+
|
|
68
|
+
// Add custom matchers or global test setup here
|
|
69
|
+
beforeAll(() => {
|
|
70
|
+
// Global setup
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
afterAll(() => {
|
|
74
|
+
// Global teardown
|
|
75
|
+
});
|
|
76
|
+
`;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
/**
|
|
80
|
+
* Install Jest and TypeScript dependencies
|
|
81
|
+
* @param {string} projectDir - Project directory
|
|
82
|
+
* @param {Object} packageJson - Existing package.json
|
|
83
|
+
* @returns {Promise<Object>} Installation result
|
|
84
|
+
*/
|
|
85
|
+
async function installJestDependencies(projectDir, packageJson) {
|
|
86
|
+
const dependencies = ['jest', '@types/jest', 'ts-jest'];
|
|
87
|
+
|
|
88
|
+
// Check which dependencies are already installed
|
|
89
|
+
const allDeps = {
|
|
90
|
+
...packageJson.dependencies,
|
|
91
|
+
...packageJson.devDependencies,
|
|
92
|
+
};
|
|
93
|
+
|
|
94
|
+
const toInstall = dependencies.filter((dep) => !(dep in allDeps));
|
|
95
|
+
|
|
96
|
+
if (toInstall.length === 0) {
|
|
97
|
+
return {
|
|
98
|
+
installed: false,
|
|
99
|
+
message: 'All Jest dependencies already installed',
|
|
100
|
+
dependencies: [],
|
|
101
|
+
};
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
return {
|
|
105
|
+
installed: false,
|
|
106
|
+
needsInstall: true,
|
|
107
|
+
dependencies: toInstall,
|
|
108
|
+
installCommand: `npm install --save-dev ${toInstall.join(' ')}`,
|
|
109
|
+
};
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
/**
|
|
113
|
+
* Configure Jest for TypeScript project
|
|
114
|
+
* @param {string} projectDir - Project directory path
|
|
115
|
+
* @param {Object} options - Configuration options
|
|
116
|
+
* @returns {Promise<Object>} Configuration result
|
|
117
|
+
*/
|
|
118
|
+
async function configureJestForTypeScript(projectDir = process.cwd(), options = {}) {
|
|
119
|
+
const { force = false, quiet = false } = options;
|
|
120
|
+
|
|
121
|
+
// Check if Jest config already exists
|
|
122
|
+
const jestConfigPath = path.join(projectDir, 'jest.config.js');
|
|
123
|
+
if (fs.existsSync(jestConfigPath) && !force) {
|
|
124
|
+
return {
|
|
125
|
+
configured: false,
|
|
126
|
+
skipped: true,
|
|
127
|
+
message: 'Jest configuration already exists',
|
|
128
|
+
path: jestConfigPath,
|
|
129
|
+
};
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
// Generate Jest config
|
|
133
|
+
const jestConfig = generateJestConfig();
|
|
134
|
+
await fs.writeFile(jestConfigPath, jestConfig);
|
|
135
|
+
|
|
136
|
+
if (!quiet) {
|
|
137
|
+
console.log(chalk.green('✅ Created jest.config.js'));
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
// Generate test setup file
|
|
141
|
+
const setupPath = path.join(projectDir, 'tests', 'setup.ts');
|
|
142
|
+
await fs.ensureDir(path.join(projectDir, 'tests'));
|
|
143
|
+
await fs.writeFile(setupPath, generateTestSetup());
|
|
144
|
+
|
|
145
|
+
if (!quiet) {
|
|
146
|
+
console.log(chalk.green('✅ Created tests/setup.ts'));
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
// Update package.json with test script if needed
|
|
150
|
+
const packageJsonPath = path.join(projectDir, 'package.json');
|
|
151
|
+
if (fs.existsSync(packageJsonPath)) {
|
|
152
|
+
const packageJson = JSON.parse(await fs.readFile(packageJsonPath, 'utf8'));
|
|
153
|
+
|
|
154
|
+
if (!packageJson.scripts) {
|
|
155
|
+
packageJson.scripts = {};
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
if (!packageJson.scripts.test) {
|
|
159
|
+
packageJson.scripts.test = 'jest';
|
|
160
|
+
packageJson.scripts['test:coverage'] = 'jest --coverage';
|
|
161
|
+
packageJson.scripts['test:watch'] = 'jest --watch';
|
|
162
|
+
|
|
163
|
+
await fs.writeFile(packageJsonPath, JSON.stringify(packageJson, null, 2) + '\n');
|
|
164
|
+
|
|
165
|
+
if (!quiet) {
|
|
166
|
+
console.log(chalk.green('✅ Added test scripts to package.json'));
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
return {
|
|
172
|
+
configured: true,
|
|
173
|
+
files: [jestConfigPath, setupPath],
|
|
174
|
+
nextSteps: [
|
|
175
|
+
'Install dependencies: npm install --save-dev jest @types/jest ts-jest',
|
|
176
|
+
'Run tests: npm test',
|
|
177
|
+
'Run with coverage: npm run test:coverage',
|
|
178
|
+
],
|
|
179
|
+
};
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
/**
|
|
183
|
+
* Get Jest configuration recommendations
|
|
184
|
+
* @param {string} projectDir - Project directory path
|
|
185
|
+
* @returns {Object} Recommendations
|
|
186
|
+
*/
|
|
187
|
+
function getJestRecommendations(projectDir = process.cwd()) {
|
|
188
|
+
const recommendations = [];
|
|
189
|
+
const hasJestConfig = fs.existsSync(path.join(projectDir, 'jest.config.js'));
|
|
190
|
+
const packageJsonPath = path.join(projectDir, 'package.json');
|
|
191
|
+
|
|
192
|
+
if (fs.existsSync(packageJsonPath)) {
|
|
193
|
+
const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, 'utf8'));
|
|
194
|
+
const allDeps = {
|
|
195
|
+
...packageJson.dependencies,
|
|
196
|
+
...packageJson.devDependencies,
|
|
197
|
+
};
|
|
198
|
+
|
|
199
|
+
if (!hasJestConfig && !('jest' in allDeps)) {
|
|
200
|
+
recommendations.push({
|
|
201
|
+
type: 'missing_framework',
|
|
202
|
+
severity: 'high',
|
|
203
|
+
message: 'No testing framework detected',
|
|
204
|
+
fix: 'Install Jest: npm install --save-dev jest @types/jest ts-jest',
|
|
205
|
+
autoFixable: false,
|
|
206
|
+
});
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
if ('typescript' in allDeps && 'jest' in allDeps && !('ts-jest' in allDeps)) {
|
|
210
|
+
recommendations.push({
|
|
211
|
+
type: 'missing_ts_jest',
|
|
212
|
+
severity: 'high',
|
|
213
|
+
message: 'TypeScript project with Jest but missing ts-jest',
|
|
214
|
+
fix: 'Install ts-jest: npm install --save-dev ts-jest',
|
|
215
|
+
autoFixable: false,
|
|
216
|
+
});
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
if (!hasJestConfig && 'jest' in allDeps) {
|
|
220
|
+
recommendations.push({
|
|
221
|
+
type: 'missing_config',
|
|
222
|
+
severity: 'medium',
|
|
223
|
+
message: 'Jest installed but not configured',
|
|
224
|
+
fix: 'Run: caws scaffold to generate Jest configuration',
|
|
225
|
+
autoFixable: true,
|
|
226
|
+
});
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
return {
|
|
231
|
+
hasIssues: recommendations.length > 0,
|
|
232
|
+
recommendations,
|
|
233
|
+
};
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
module.exports = {
|
|
237
|
+
configureJestForTypeScript,
|
|
238
|
+
generateJestConfig,
|
|
239
|
+
generateTestSetup,
|
|
240
|
+
installJestDependencies,
|
|
241
|
+
getJestRecommendations,
|
|
242
|
+
};
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Configure Jest for TypeScript project
|
|
3
|
+
* @param {string} projectDir - Project directory path
|
|
4
|
+
* @param {Object} options - Configuration options
|
|
5
|
+
* @returns {Promise<Object>} Configuration result
|
|
6
|
+
*/
|
|
7
|
+
export function configureJestForTypeScript(projectDir?: string, options?: any): Promise<any>;
|
|
8
|
+
/**
|
|
9
|
+
* Generate Jest configuration for TypeScript project
|
|
10
|
+
* @param {Object} options - Configuration options
|
|
11
|
+
* @returns {string} Jest configuration content
|
|
12
|
+
*/
|
|
13
|
+
export function generateJestConfig(options?: any): string;
|
|
14
|
+
/**
|
|
15
|
+
* Generate test setup file for TypeScript
|
|
16
|
+
* @returns {string} Setup file content
|
|
17
|
+
*/
|
|
18
|
+
export function generateTestSetup(): string;
|
|
19
|
+
/**
|
|
20
|
+
* Install Jest and TypeScript dependencies
|
|
21
|
+
* @param {string} projectDir - Project directory
|
|
22
|
+
* @param {Object} packageJson - Existing package.json
|
|
23
|
+
* @returns {Promise<Object>} Installation result
|
|
24
|
+
*/
|
|
25
|
+
export function installJestDependencies(projectDir: string, packageJson: any): Promise<any>;
|
|
26
|
+
/**
|
|
27
|
+
* Get Jest configuration recommendations
|
|
28
|
+
* @param {string} projectDir - Project directory path
|
|
29
|
+
* @returns {Object} Recommendations
|
|
30
|
+
*/
|
|
31
|
+
export function getJestRecommendations(projectDir?: string): any;
|
|
32
|
+
//# sourceMappingURL=jest-config.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"jest-config.d.ts","sourceRoot":"","sources":["../../src/generators/jest-config.js"],"names":[],"mappings":"AA+GA;;;;;GAKG;AACH,wDAJW,MAAM,kBAEJ,OAAO,KAAQ,CAgE3B;AAzKD;;;;GAIG;AACH,mDAFa,MAAM,CA0ClB;AAED;;;GAGG;AACH,qCAFa,MAAM,CAiBlB;AAED;;;;;GAKG;AACH,oDAJW,MAAM,qBAEJ,OAAO,KAAQ,CA2B3B;AAwED;;;;GAIG;AACH,oDAHW,MAAM,OAkDhB"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Generate working spec YAML with user input
|
|
3
|
+
* @param {Object} answers - User responses
|
|
4
|
+
* @returns {string} - Generated YAML content
|
|
5
|
+
*/
|
|
6
|
+
export function generateWorkingSpec(answers: any): string;
|
|
7
|
+
/**
|
|
8
|
+
* Validate generated working spec against JSON schema
|
|
9
|
+
* @param {string} specContent - YAML spec content
|
|
10
|
+
* @param {Object} answers - User responses for error context
|
|
11
|
+
*/
|
|
12
|
+
export function validateGeneratedSpec(specContent: string, _answers: any): void;
|
|
13
|
+
//# sourceMappingURL=working-spec.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"working-spec.d.ts","sourceRoot":"","sources":["../../src/generators/working-spec.js"],"names":[],"mappings":"AAYA;;;;GAIG;AACH,mDAFa,MAAM,CAsLlB;AAED;;;;GAIG;AACH,mDAHW,MAAM,uBA8BhB"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index-new.d.ts","sourceRoot":"","sources":["../src/index-new.js"],"names":[],"mappings":""}
|