claude-code-templates 1.0.2 → 1.1.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/package.json +7 -2
- package/scripts/sync-templates.js +182 -0
- package/src/command-scanner.js +175 -0
- package/src/file-operations.js +34 -2
- package/src/prompts.js +47 -1
- package/src/templates.js +10 -1
- package/templates/common/.claude/commands/git-workflow.md +239 -0
- package/templates/common/.claude/commands/project-setup.md +316 -0
- package/templates/go/README.md +25 -0
- package/templates/javascript-typescript/.claude/commands/api-endpoint.md +51 -1
- package/templates/javascript-typescript/.claude/commands/debug.md +52 -1
- package/templates/javascript-typescript/.claude/commands/lint.md +48 -1
- package/templates/javascript-typescript/.claude/commands/npm-scripts.md +48 -1
- package/templates/javascript-typescript/.claude/commands/react-component.md +54 -1
- package/templates/javascript-typescript/.claude/commands/refactor.md +55 -1
- package/templates/javascript-typescript/.claude/commands/route.md +193 -0
- package/templates/javascript-typescript/.claude/commands/test.md +61 -1
- package/templates/javascript-typescript/.claude/commands/typescript-migrate.md +51 -1
- package/templates/javascript-typescript/.claude/settings.json +41 -2
- package/templates/javascript-typescript/.mcp.json +13 -0
- package/templates/javascript-typescript/README.md +213 -187
- package/templates/python/.claude/commands/django-model.md +124 -0
- package/templates/python/.claude/commands/flask-route.md +217 -0
- package/templates/python/.claude/commands/lint.md +111 -0
- package/templates/python/.claude/commands/test.md +73 -0
- package/templates/rust/README.md +26 -0
- package/templates/javascript-typescript/.claude/hooks/format-on-save.json +0 -1
- package/templates/javascript-typescript/.claude/hooks/lint-on-save.json +0 -1
- package/templates/javascript-typescript/.claude/hooks/typescript-check.json +0 -1
- package/templates/javascript-typescript/examples/node-api/.claude/commands/middleware.md +0 -1
- package/templates/javascript-typescript/examples/node-api/.claude/commands/route.md +0 -1
- package/templates/javascript-typescript/examples/node-api/CLAUDE.md +0 -1
- package/templates/javascript-typescript/examples/react-app/.claude/commands/component.md +0 -1
- package/templates/javascript-typescript/examples/react-app/.claude/commands/hooks.md +0 -1
- package/templates/javascript-typescript/examples/react-app/CLAUDE.md +0 -1
|
@@ -1 +1,48 @@
|
|
|
1
|
-
# Lint
|
|
1
|
+
# Lint Assistant
|
|
2
|
+
|
|
3
|
+
Analyze and fix linting issues in $ARGUMENTS following project conventions.
|
|
4
|
+
|
|
5
|
+
## Task
|
|
6
|
+
|
|
7
|
+
I'll help you identify and fix code style and quality issues by:
|
|
8
|
+
|
|
9
|
+
1. Running appropriate linters for the project
|
|
10
|
+
2. Analyzing linting errors and warnings
|
|
11
|
+
3. Fixing issues automatically when possible
|
|
12
|
+
4. Explaining complex issues that require manual intervention
|
|
13
|
+
5. Ensuring code follows project style guidelines
|
|
14
|
+
|
|
15
|
+
## Process
|
|
16
|
+
|
|
17
|
+
I'll follow these steps:
|
|
18
|
+
|
|
19
|
+
1. Identify the linting tools used in the project (ESLint, Prettier, TSLint, etc.)
|
|
20
|
+
2. Run the appropriate linting commands
|
|
21
|
+
3. Parse and categorize the results
|
|
22
|
+
4. Apply automatic fixes for common issues
|
|
23
|
+
5. Provide explanations and suggestions for more complex problems
|
|
24
|
+
6. Verify fixes don't introduce new issues
|
|
25
|
+
|
|
26
|
+
## Common Linting Issues I Can Fix
|
|
27
|
+
|
|
28
|
+
- Code style inconsistencies (spacing, indentation, quotes, etc.)
|
|
29
|
+
- Unused variables and imports
|
|
30
|
+
- Missing type annotations in TypeScript
|
|
31
|
+
- Accessibility (a11y) issues in UI components
|
|
32
|
+
- Potential bugs flagged by static analysis
|
|
33
|
+
- Performance issues in React/Vue components
|
|
34
|
+
- Security vulnerabilities detected by linters
|
|
35
|
+
- Deprecated API usage
|
|
36
|
+
- Import ordering problems
|
|
37
|
+
- Missing documentation
|
|
38
|
+
|
|
39
|
+
## Linting Tools I Can Work With
|
|
40
|
+
|
|
41
|
+
- ESLint (with various plugins and configs)
|
|
42
|
+
- Prettier
|
|
43
|
+
- TSLint (legacy)
|
|
44
|
+
- stylelint (for CSS/SCSS)
|
|
45
|
+
- commitlint (for commit messages)
|
|
46
|
+
- Custom lint rules specific to your project
|
|
47
|
+
|
|
48
|
+
I'll adapt my approach based on your project's specific linting configuration and style guide requirements.
|
|
@@ -1 +1,48 @@
|
|
|
1
|
-
# NPM Scripts
|
|
1
|
+
# NPM Scripts Assistant
|
|
2
|
+
|
|
3
|
+
Help me with NPM scripts: $ARGUMENTS
|
|
4
|
+
|
|
5
|
+
## Task
|
|
6
|
+
|
|
7
|
+
I'll help you work with package.json scripts by:
|
|
8
|
+
|
|
9
|
+
1. Analyzing existing npm scripts in your project
|
|
10
|
+
2. Creating new scripts or modifying existing ones
|
|
11
|
+
3. Explaining what specific scripts do
|
|
12
|
+
4. Suggesting improvements or optimizations
|
|
13
|
+
5. Troubleshooting script execution issues
|
|
14
|
+
|
|
15
|
+
## Process
|
|
16
|
+
|
|
17
|
+
I'll follow these steps:
|
|
18
|
+
|
|
19
|
+
1. Examine your package.json file to understand current scripts
|
|
20
|
+
2. Analyze dependencies and devDependencies for available tools
|
|
21
|
+
3. Identify common patterns and conventions in your scripts
|
|
22
|
+
4. Implement requested changes or create new scripts
|
|
23
|
+
5. Provide explanations of how the scripts work
|
|
24
|
+
6. Test scripts when possible to verify functionality
|
|
25
|
+
|
|
26
|
+
## Common Script Types I Can Help With
|
|
27
|
+
|
|
28
|
+
- Build processes (webpack, rollup, esbuild, etc.)
|
|
29
|
+
- Development servers and hot reloading
|
|
30
|
+
- Testing (unit, integration, e2e)
|
|
31
|
+
- Linting and code formatting
|
|
32
|
+
- Type checking
|
|
33
|
+
- Deployment and CI/CD
|
|
34
|
+
- Database migrations
|
|
35
|
+
- Code generation
|
|
36
|
+
- Environment setup
|
|
37
|
+
- Pre/post hooks for git operations
|
|
38
|
+
|
|
39
|
+
## Script Optimization Techniques
|
|
40
|
+
|
|
41
|
+
- Parallelizing tasks for faster execution
|
|
42
|
+
- Adding cross-platform compatibility
|
|
43
|
+
- Improving error reporting and logging
|
|
44
|
+
- Implementing watch modes for development
|
|
45
|
+
- Creating composite scripts for common workflows
|
|
46
|
+
- Adding appropriate exit codes for CI/CD pipelines
|
|
47
|
+
|
|
48
|
+
I'll adapt my approach based on your project's specific needs, dependencies, and build tools.
|
|
@@ -1 +1,54 @@
|
|
|
1
|
-
# React Component
|
|
1
|
+
# React Component Generator
|
|
2
|
+
|
|
3
|
+
Create a React component for $ARGUMENTS following project conventions.
|
|
4
|
+
|
|
5
|
+
## Task
|
|
6
|
+
|
|
7
|
+
I'll help you create a complete React component by:
|
|
8
|
+
|
|
9
|
+
1. Analyzing your project structure and conventions
|
|
10
|
+
2. Creating component files with appropriate organization
|
|
11
|
+
3. Implementing the component with proper TypeScript types
|
|
12
|
+
4. Adding styles according to your project's styling approach
|
|
13
|
+
5. Creating tests for the component
|
|
14
|
+
6. Adding documentation and usage examples
|
|
15
|
+
|
|
16
|
+
## Process
|
|
17
|
+
|
|
18
|
+
I'll follow these steps:
|
|
19
|
+
|
|
20
|
+
1. Examine your project to understand component patterns and conventions
|
|
21
|
+
2. Identify the styling approach (CSS/SCSS modules, styled-components, Tailwind, etc.)
|
|
22
|
+
3. Determine testing frameworks and patterns
|
|
23
|
+
4. Create the component with appropriate file structure
|
|
24
|
+
5. Implement component logic, props interface, and styling
|
|
25
|
+
6. Add comprehensive tests
|
|
26
|
+
7. Document the component's usage and props
|
|
27
|
+
|
|
28
|
+
## Component Features
|
|
29
|
+
|
|
30
|
+
I can implement various component types and features:
|
|
31
|
+
|
|
32
|
+
- Functional components with hooks
|
|
33
|
+
- TypeScript interfaces for props and state
|
|
34
|
+
- Proper prop validation and defaults
|
|
35
|
+
- Responsive design considerations
|
|
36
|
+
- Accessibility (a11y) best practices
|
|
37
|
+
- Performance optimizations (memoization, etc.)
|
|
38
|
+
- Error boundaries when appropriate
|
|
39
|
+
- Loading and error states
|
|
40
|
+
- Animation and transition effects
|
|
41
|
+
|
|
42
|
+
## Component Architecture Patterns
|
|
43
|
+
|
|
44
|
+
I'll adapt to your project's component architecture:
|
|
45
|
+
|
|
46
|
+
- Atomic Design methodology (atoms, molecules, organisms)
|
|
47
|
+
- Feature-based organization
|
|
48
|
+
- Container/Presentational pattern
|
|
49
|
+
- Compound components
|
|
50
|
+
- Render props pattern
|
|
51
|
+
- Higher-Order Components (HOCs)
|
|
52
|
+
- Custom hooks for logic extraction
|
|
53
|
+
|
|
54
|
+
I'll analyze your existing components to match your project's specific patterns and conventions.
|
|
@@ -1 +1,55 @@
|
|
|
1
|
-
#
|
|
1
|
+
# Code Refactoring Assistant
|
|
2
|
+
|
|
3
|
+
Refactor $ARGUMENTS following modern JavaScript/TypeScript best practices.
|
|
4
|
+
|
|
5
|
+
## Task
|
|
6
|
+
|
|
7
|
+
I'll help you refactor code by:
|
|
8
|
+
|
|
9
|
+
1. Analyzing the current implementation
|
|
10
|
+
2. Identifying improvement opportunities
|
|
11
|
+
3. Applying modern patterns and practices
|
|
12
|
+
4. Maintaining existing functionality
|
|
13
|
+
5. Ensuring type safety and test coverage
|
|
14
|
+
6. Documenting the changes made
|
|
15
|
+
|
|
16
|
+
## Process
|
|
17
|
+
|
|
18
|
+
I'll follow these steps:
|
|
19
|
+
|
|
20
|
+
1. Examine the code to understand its purpose and structure
|
|
21
|
+
2. Identify code smells, anti-patterns, or outdated approaches
|
|
22
|
+
3. Plan the refactoring strategy with clear goals
|
|
23
|
+
4. Implement changes incrementally while maintaining behavior
|
|
24
|
+
5. Verify refactored code with tests
|
|
25
|
+
6. Document improvements and benefits
|
|
26
|
+
|
|
27
|
+
## Refactoring Techniques
|
|
28
|
+
|
|
29
|
+
I can apply various refactoring techniques:
|
|
30
|
+
|
|
31
|
+
- Converting to modern JavaScript/TypeScript features
|
|
32
|
+
- Improving type definitions and type safety
|
|
33
|
+
- Extracting reusable functions and components
|
|
34
|
+
- Applying design patterns appropriately
|
|
35
|
+
- Converting callbacks to Promises or async/await
|
|
36
|
+
- Simplifying complex conditionals and loops
|
|
37
|
+
- Removing duplicate code
|
|
38
|
+
- Improving naming and readability
|
|
39
|
+
- Optimizing performance
|
|
40
|
+
- Enhancing error handling
|
|
41
|
+
|
|
42
|
+
## Modern Practices I Can Apply
|
|
43
|
+
|
|
44
|
+
- ES modules and import/export syntax
|
|
45
|
+
- Optional chaining and nullish coalescing
|
|
46
|
+
- Array and object destructuring
|
|
47
|
+
- Spread and rest operators
|
|
48
|
+
- Template literals
|
|
49
|
+
- Arrow functions
|
|
50
|
+
- Class fields and private methods
|
|
51
|
+
- TypeScript utility types
|
|
52
|
+
- Functional programming patterns
|
|
53
|
+
- React hooks (for React components)
|
|
54
|
+
|
|
55
|
+
I'll ensure the refactored code maintains compatibility with your project's requirements while improving quality and maintainability.
|
|
@@ -0,0 +1,193 @@
|
|
|
1
|
+
# Route Creator
|
|
2
|
+
|
|
3
|
+
Create API routes and endpoints for Node.js applications with proper structure and best practices.
|
|
4
|
+
|
|
5
|
+
## Purpose
|
|
6
|
+
|
|
7
|
+
This command helps you quickly create new API routes with:
|
|
8
|
+
- RESTful endpoint structure
|
|
9
|
+
- Proper HTTP method handling
|
|
10
|
+
- Input validation
|
|
11
|
+
- Error handling
|
|
12
|
+
- Documentation comments
|
|
13
|
+
- TypeScript support
|
|
14
|
+
|
|
15
|
+
## Usage
|
|
16
|
+
|
|
17
|
+
Use this command to create API routes for your Node.js application:
|
|
18
|
+
|
|
19
|
+
```
|
|
20
|
+
/route
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
## What this command does
|
|
24
|
+
|
|
25
|
+
1. **Analyzes your project structure** to understand your routing setup
|
|
26
|
+
2. **Asks for route details** (endpoint path, HTTP methods, parameters)
|
|
27
|
+
3. **Creates route files** with proper structure and validation
|
|
28
|
+
4. **Generates TypeScript types** for request/response (if TypeScript project)
|
|
29
|
+
5. **Adds proper error handling** and status codes
|
|
30
|
+
6. **Includes documentation** and examples
|
|
31
|
+
|
|
32
|
+
## Example Output
|
|
33
|
+
|
|
34
|
+
For a `/users` route, this might create:
|
|
35
|
+
|
|
36
|
+
### Express.js Route
|
|
37
|
+
```javascript
|
|
38
|
+
// routes/users.js
|
|
39
|
+
const express = require('express');
|
|
40
|
+
const router = express.Router();
|
|
41
|
+
|
|
42
|
+
// GET /users - Get all users
|
|
43
|
+
router.get('/', async (req, res) => {
|
|
44
|
+
try {
|
|
45
|
+
// TODO: Implement user fetching logic
|
|
46
|
+
const users = [];
|
|
47
|
+
res.json(users);
|
|
48
|
+
} catch (error) {
|
|
49
|
+
res.status(500).json({ error: 'Failed to fetch users' });
|
|
50
|
+
}
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
// GET /users/:id - Get user by ID
|
|
54
|
+
router.get('/:id', async (req, res) => {
|
|
55
|
+
try {
|
|
56
|
+
const { id } = req.params;
|
|
57
|
+
// TODO: Implement user fetching by ID
|
|
58
|
+
const user = {};
|
|
59
|
+
|
|
60
|
+
if (!user) {
|
|
61
|
+
return res.status(404).json({ error: 'User not found' });
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
res.json(user);
|
|
65
|
+
} catch (error) {
|
|
66
|
+
res.status(500).json({ error: 'Failed to fetch user' });
|
|
67
|
+
}
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
// POST /users - Create new user
|
|
71
|
+
router.post('/', async (req, res) => {
|
|
72
|
+
try {
|
|
73
|
+
const { name, email } = req.body;
|
|
74
|
+
|
|
75
|
+
// Input validation
|
|
76
|
+
if (!name || !email) {
|
|
77
|
+
return res.status(400).json({
|
|
78
|
+
error: 'Name and email are required'
|
|
79
|
+
});
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
// TODO: Implement user creation logic
|
|
83
|
+
const newUser = { id: Date.now(), name, email };
|
|
84
|
+
|
|
85
|
+
res.status(201).json(newUser);
|
|
86
|
+
} catch (error) {
|
|
87
|
+
res.status(500).json({ error: 'Failed to create user' });
|
|
88
|
+
}
|
|
89
|
+
});
|
|
90
|
+
|
|
91
|
+
module.exports = router;
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
### TypeScript Route (if TS project)
|
|
95
|
+
```typescript
|
|
96
|
+
// routes/users.ts
|
|
97
|
+
import { Router, Request, Response } from 'express';
|
|
98
|
+
|
|
99
|
+
interface User {
|
|
100
|
+
id: number;
|
|
101
|
+
name: string;
|
|
102
|
+
email: string;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
interface CreateUserRequest {
|
|
106
|
+
name: string;
|
|
107
|
+
email: string;
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
const router = Router();
|
|
111
|
+
|
|
112
|
+
// GET /users - Get all users
|
|
113
|
+
router.get('/', async (req: Request, res: Response<User[]>) => {
|
|
114
|
+
try {
|
|
115
|
+
// TODO: Implement user fetching logic
|
|
116
|
+
const users: User[] = [];
|
|
117
|
+
res.json(users);
|
|
118
|
+
} catch (error) {
|
|
119
|
+
res.status(500).json({ error: 'Failed to fetch users' } as any);
|
|
120
|
+
}
|
|
121
|
+
});
|
|
122
|
+
|
|
123
|
+
// POST /users - Create new user
|
|
124
|
+
router.post('/', async (req: Request<{}, User, CreateUserRequest>, res: Response<User>) => {
|
|
125
|
+
try {
|
|
126
|
+
const { name, email } = req.body;
|
|
127
|
+
|
|
128
|
+
if (!name || !email) {
|
|
129
|
+
return res.status(400).json({
|
|
130
|
+
error: 'Name and email are required'
|
|
131
|
+
} as any);
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
// TODO: Implement user creation logic
|
|
135
|
+
const newUser: User = { id: Date.now(), name, email };
|
|
136
|
+
|
|
137
|
+
res.status(201).json(newUser);
|
|
138
|
+
} catch (error) {
|
|
139
|
+
res.status(500).json({ error: 'Failed to create user' } as any);
|
|
140
|
+
}
|
|
141
|
+
});
|
|
142
|
+
|
|
143
|
+
export default router;
|
|
144
|
+
```
|
|
145
|
+
|
|
146
|
+
## When to use this command
|
|
147
|
+
|
|
148
|
+
- **Creating new API endpoints** for your application
|
|
149
|
+
- **Adding CRUD operations** for data models
|
|
150
|
+
- **Building RESTful APIs** with proper structure
|
|
151
|
+
- **Setting up route handlers** with validation and error handling
|
|
152
|
+
- **Generating boilerplate** for API development
|
|
153
|
+
|
|
154
|
+
## Framework Support
|
|
155
|
+
|
|
156
|
+
This command adapts to your specific Node.js framework:
|
|
157
|
+
|
|
158
|
+
### Express.js
|
|
159
|
+
- Creates `routes/` directory structure
|
|
160
|
+
- Uses Express Router
|
|
161
|
+
- Includes middleware support
|
|
162
|
+
- Adds common HTTP methods (GET, POST, PUT, DELETE)
|
|
163
|
+
|
|
164
|
+
### Fastify
|
|
165
|
+
- Creates Fastify route plugins
|
|
166
|
+
- Includes schema validation
|
|
167
|
+
- Uses Fastify's built-in serialization
|
|
168
|
+
- Adds proper error handling
|
|
169
|
+
|
|
170
|
+
### NestJS
|
|
171
|
+
- Creates controller classes
|
|
172
|
+
- Includes decorators (@Get, @Post, etc.)
|
|
173
|
+
- Generates DTOs for validation
|
|
174
|
+
- Uses dependency injection
|
|
175
|
+
|
|
176
|
+
## Best Practices Included
|
|
177
|
+
|
|
178
|
+
- **Input Validation** - Validates request parameters and body
|
|
179
|
+
- **Error Handling** - Proper try/catch blocks and error responses
|
|
180
|
+
- **Status Codes** - Appropriate HTTP status codes for different scenarios
|
|
181
|
+
- **TypeScript Types** - Strong typing for requests and responses
|
|
182
|
+
- **Documentation** - JSDoc comments explaining each endpoint
|
|
183
|
+
- **Security** - Basic input sanitization and validation
|
|
184
|
+
- **Testing Setup** - Suggests test cases for the new routes
|
|
185
|
+
|
|
186
|
+
## Tips
|
|
187
|
+
|
|
188
|
+
1. **Plan your API structure** before creating routes
|
|
189
|
+
2. **Use consistent naming** for endpoints (plural nouns for collections)
|
|
190
|
+
3. **Include proper validation** for all input data
|
|
191
|
+
4. **Add authentication/authorization** where needed
|
|
192
|
+
5. **Test your routes** after creation
|
|
193
|
+
6. **Document your API** for other developers
|
|
@@ -1 +1,61 @@
|
|
|
1
|
-
# Test
|
|
1
|
+
# Test Assistant
|
|
2
|
+
|
|
3
|
+
Help with tests for $ARGUMENTS following project conventions and testing best practices.
|
|
4
|
+
|
|
5
|
+
## Task
|
|
6
|
+
|
|
7
|
+
I'll help you with testing by:
|
|
8
|
+
|
|
9
|
+
1. Creating comprehensive test suites for your code
|
|
10
|
+
2. Implementing different types of tests (unit, integration, e2e)
|
|
11
|
+
3. Mocking dependencies and external services
|
|
12
|
+
4. Improving test coverage for existing code
|
|
13
|
+
5. Troubleshooting failing tests
|
|
14
|
+
6. Setting up testing infrastructure
|
|
15
|
+
|
|
16
|
+
## Process
|
|
17
|
+
|
|
18
|
+
I'll follow these steps:
|
|
19
|
+
|
|
20
|
+
1. Examine your project to understand testing frameworks and patterns
|
|
21
|
+
2. Analyze the code to be tested to understand its functionality
|
|
22
|
+
3. Identify appropriate testing strategies and edge cases
|
|
23
|
+
4. Implement tests with proper structure and assertions
|
|
24
|
+
5. Ensure tests are maintainable and follow best practices
|
|
25
|
+
6. Run tests to verify they pass and provide adequate coverage
|
|
26
|
+
|
|
27
|
+
## Testing Frameworks I Can Work With
|
|
28
|
+
|
|
29
|
+
- Jest, Vitest, Mocha, Jasmine for JavaScript/TypeScript
|
|
30
|
+
- React Testing Library, Enzyme for React components
|
|
31
|
+
- Cypress, Playwright, Puppeteer for E2E testing
|
|
32
|
+
- Supertest, Pactum for API testing
|
|
33
|
+
- Storybook for component testing
|
|
34
|
+
- Testing-library family for various frameworks
|
|
35
|
+
|
|
36
|
+
## Testing Techniques
|
|
37
|
+
|
|
38
|
+
I can implement various testing approaches:
|
|
39
|
+
|
|
40
|
+
- TDD (Test-Driven Development)
|
|
41
|
+
- BDD (Behavior-Driven Development)
|
|
42
|
+
- Snapshot testing
|
|
43
|
+
- Property-based testing
|
|
44
|
+
- Parameterized tests
|
|
45
|
+
- Contract testing
|
|
46
|
+
- Visual regression testing
|
|
47
|
+
- Performance testing
|
|
48
|
+
|
|
49
|
+
## Mocking Strategies
|
|
50
|
+
|
|
51
|
+
I can help with different mocking approaches:
|
|
52
|
+
|
|
53
|
+
- Function mocks and spies
|
|
54
|
+
- Module mocks
|
|
55
|
+
- HTTP request mocking
|
|
56
|
+
- Browser API mocking
|
|
57
|
+
- Timer mocking
|
|
58
|
+
- Database mocking
|
|
59
|
+
- Service worker mocking
|
|
60
|
+
|
|
61
|
+
I'll adapt to your project's specific testing frameworks, patterns, and conventions to ensure consistency with your existing codebase.
|
|
@@ -1 +1,51 @@
|
|
|
1
|
-
# TypeScript
|
|
1
|
+
# TypeScript Migration Assistant
|
|
2
|
+
|
|
3
|
+
Migrate $ARGUMENTS from JavaScript to TypeScript with proper typing and modern practices.
|
|
4
|
+
|
|
5
|
+
## Task
|
|
6
|
+
|
|
7
|
+
I'll help you migrate JavaScript code to TypeScript by:
|
|
8
|
+
|
|
9
|
+
1. Converting JavaScript files to TypeScript (.js/.jsx to .ts/.tsx)
|
|
10
|
+
2. Adding appropriate type definitions and interfaces
|
|
11
|
+
3. Configuring TypeScript settings for your project
|
|
12
|
+
4. Resolving type errors and compatibility issues
|
|
13
|
+
5. Implementing modern TypeScript patterns and features
|
|
14
|
+
6. Ensuring backward compatibility with existing code
|
|
15
|
+
|
|
16
|
+
## Process
|
|
17
|
+
|
|
18
|
+
I'll follow these steps:
|
|
19
|
+
|
|
20
|
+
1. Examine your project structure and dependencies
|
|
21
|
+
2. Analyze the JavaScript code to understand its functionality
|
|
22
|
+
3. Create or update tsconfig.json with appropriate settings
|
|
23
|
+
4. Convert files to TypeScript with proper type annotations
|
|
24
|
+
5. Add necessary type definitions for libraries
|
|
25
|
+
6. Fix type errors and implement type safety
|
|
26
|
+
7. Refactor code to leverage TypeScript features
|
|
27
|
+
|
|
28
|
+
## TypeScript Features I Can Implement
|
|
29
|
+
|
|
30
|
+
- Interfaces and type aliases for complex data structures
|
|
31
|
+
- Generics for reusable, type-safe components and functions
|
|
32
|
+
- Union and intersection types for flexible typing
|
|
33
|
+
- Enums for related constants
|
|
34
|
+
- Utility types (Partial, Pick, Omit, etc.)
|
|
35
|
+
- Type guards and type narrowing
|
|
36
|
+
- Mapped and conditional types
|
|
37
|
+
- Function overloading
|
|
38
|
+
- Readonly properties and immutability
|
|
39
|
+
- Module augmentation for extending third-party types
|
|
40
|
+
|
|
41
|
+
## Migration Strategies
|
|
42
|
+
|
|
43
|
+
I can apply different migration approaches based on your needs:
|
|
44
|
+
|
|
45
|
+
- Gradual migration with allowJs and incremental adoption
|
|
46
|
+
- File-by-file conversion while maintaining functionality
|
|
47
|
+
- Comprehensive migration with full type safety
|
|
48
|
+
- Hybrid approach with .d.ts files for complex modules
|
|
49
|
+
- Integration with existing type definitions (@types packages)
|
|
50
|
+
|
|
51
|
+
I'll adapt to your project's specific requirements and ensure a smooth transition to TypeScript while maintaining existing functionality.
|
|
@@ -49,7 +49,17 @@
|
|
|
49
49
|
"hooks": [
|
|
50
50
|
{
|
|
51
51
|
"type": "command",
|
|
52
|
-
"command": "if [[ \"$(jq -r '.tool_input.file_path' | grep -E '\\.js$|\\.jsx$|\\.ts$|\\.tsx$')\" != \"\" && $(jq -r '.tool_input.content' | grep -E 'console\\.log') != \"\" ]]; then echo 'Warning: console.log statements should be removed before committing' >&2; fi"
|
|
52
|
+
"command": "if [[ \"$(echo $STDIN_JSON | jq -r '.tool_input.file_path' | grep -E '\\.js$|\\.jsx$|\\.ts$|\\.tsx$')\" != \"\" && $(echo $STDIN_JSON | jq -r '.tool_input.content' | grep -E 'console\\.log') != \"\" ]]; then echo 'Warning: console.log statements should be removed before committing' >&2; exit 2; fi"
|
|
53
|
+
}
|
|
54
|
+
]
|
|
55
|
+
},
|
|
56
|
+
{
|
|
57
|
+
"matcher": "Write",
|
|
58
|
+
"hooks": [
|
|
59
|
+
{
|
|
60
|
+
"type": "command",
|
|
61
|
+
"command": "FILE=$(echo $STDIN_JSON | jq -r '.tool_input.file_path // \"\"'); if [[ \"$FILE\" == \"package.json\" ]]; then echo 'Checking for vulnerable dependencies...'; npx audit-ci --moderate; fi",
|
|
62
|
+
"timeout": 60
|
|
53
63
|
}
|
|
54
64
|
]
|
|
55
65
|
}
|
|
@@ -70,10 +80,29 @@
|
|
|
70
80
|
"hooks": [
|
|
71
81
|
{
|
|
72
82
|
"type": "command",
|
|
73
|
-
"command": "FILE=$(echo $STDIN_JSON | jq -r '.tool_input.file_path // \"\"'); if [[ \"$FILE\" =~ \\.(ts|tsx)$ ]]; then npx tsc --noEmit; fi",
|
|
83
|
+
"command": "FILE=$(echo $STDIN_JSON | jq -r '.tool_input.file_path // \"\"'); if [[ \"$FILE\" =~ \\.(ts|tsx)$ ]]; then RESULT=$(npx tsc --noEmit 2>&1); if [ $? -ne 0 ]; then echo \"TypeScript errors found: $RESULT\" >&2; exit 2; fi; fi",
|
|
74
84
|
"timeout": 30
|
|
75
85
|
}
|
|
76
86
|
]
|
|
87
|
+
},
|
|
88
|
+
{
|
|
89
|
+
"matcher": "Write|Edit|MultiEdit",
|
|
90
|
+
"hooks": [
|
|
91
|
+
{
|
|
92
|
+
"type": "command",
|
|
93
|
+
"command": "FILE=$(echo $STDIN_JSON | jq -r '.tool_input.file_path // \"\"'); if [[ \"$FILE\" =~ \\.(ts|tsx)$ ]] && grep -q 'import.*from.*\\*' \"$FILE\"; then echo 'Warning: Avoid wildcard imports for better tree-shaking' >&2; exit 2; fi"
|
|
94
|
+
}
|
|
95
|
+
]
|
|
96
|
+
},
|
|
97
|
+
{
|
|
98
|
+
"matcher": "Write|Edit|MultiEdit",
|
|
99
|
+
"hooks": [
|
|
100
|
+
{
|
|
101
|
+
"type": "command",
|
|
102
|
+
"command": "FILE=$(echo $STDIN_JSON | jq -r '.tool_input.file_path // \"\"'); if [[ \"$FILE\" =~ \\.(js|jsx|ts|tsx)$ && \"$FILE\" != *\".test.\"* && \"$FILE\" != *\".spec.\"* ]]; then TEST_FILE=$(echo \"$FILE\" | sed -E 's/\\.(js|jsx|ts|tsx)$/.test.\\1/'); if [ -f \"$TEST_FILE\" ]; then echo \"Running tests for modified file...\"; npx jest \"$TEST_FILE\" --passWithNoTests; fi; fi",
|
|
103
|
+
"timeout": 60
|
|
104
|
+
}
|
|
105
|
+
]
|
|
77
106
|
}
|
|
78
107
|
],
|
|
79
108
|
"Notification": [
|
|
@@ -97,6 +126,16 @@
|
|
|
97
126
|
"timeout": 60
|
|
98
127
|
}
|
|
99
128
|
]
|
|
129
|
+
},
|
|
130
|
+
{
|
|
131
|
+
"matcher": "",
|
|
132
|
+
"hooks": [
|
|
133
|
+
{
|
|
134
|
+
"type": "command",
|
|
135
|
+
"command": "if [[ -f package.json && $(git status --porcelain | grep -E '\\.js$|\\.jsx$|\\.ts$|\\.tsx$') ]]; then echo 'Analyzing bundle size impact...'; npx bundlesize; fi",
|
|
136
|
+
"timeout": 60
|
|
137
|
+
}
|
|
138
|
+
]
|
|
100
139
|
}
|
|
101
140
|
]
|
|
102
141
|
}
|