@claudetools/cli 0.9.4 → 0.9.6
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/onboard/agents-md-builder.d.ts +7 -2
- package/dist/onboard/agents-md-builder.d.ts.map +1 -1
- package/dist/onboard/agents-md-builder.js.map +1 -1
- package/dist/onboard/docs-builder.d.ts +16 -0
- package/dist/onboard/docs-builder.d.ts.map +1 -0
- package/dist/onboard/docs-builder.js +1037 -0
- package/dist/onboard/docs-builder.js.map +1 -0
- package/dist/onboard/index.d.ts.map +1 -1
- package/dist/onboard/index.js +190 -51
- package/dist/onboard/index.js.map +1 -1
- package/package.json +1 -1
|
@@ -0,0 +1,1037 @@
|
|
|
1
|
+
// =============================================================================
|
|
2
|
+
// Documentation Builder
|
|
3
|
+
// =============================================================================
|
|
4
|
+
// Builds comprehensive docs/ directory structure for AI agent assistance
|
|
5
|
+
import { existsSync, mkdirSync, writeFileSync, readFileSync, appendFileSync } from 'fs';
|
|
6
|
+
import { join } from 'path';
|
|
7
|
+
import { isClaudeCliAvailable } from './claude-inference.js';
|
|
8
|
+
import { spawn } from 'child_process';
|
|
9
|
+
// =============================================================================
|
|
10
|
+
// Directory Structure
|
|
11
|
+
// =============================================================================
|
|
12
|
+
const DOCS_STRUCTURE = {
|
|
13
|
+
// Root index
|
|
14
|
+
'index.md': 'Documentation Index',
|
|
15
|
+
// Architecture
|
|
16
|
+
'architecture/index.md': 'Architecture Overview',
|
|
17
|
+
'architecture/system-design.md': 'System Design',
|
|
18
|
+
'architecture/data-flow.md': 'Data Flow',
|
|
19
|
+
'architecture/components.md': 'Component Architecture',
|
|
20
|
+
// API Documentation
|
|
21
|
+
'api/index.md': 'API Documentation',
|
|
22
|
+
'api/endpoints.md': 'API Endpoints',
|
|
23
|
+
'api/schemas.md': 'Data Schemas',
|
|
24
|
+
'api/authentication.md': 'Authentication',
|
|
25
|
+
// Development Guides
|
|
26
|
+
'guides/index.md': 'Development Guides',
|
|
27
|
+
'guides/getting-started.md': 'Getting Started',
|
|
28
|
+
'guides/development-workflow.md': 'Development Workflow',
|
|
29
|
+
'guides/contributing.md': 'Contributing Guide',
|
|
30
|
+
// Technical Reference
|
|
31
|
+
'reference/index.md': 'Technical Reference',
|
|
32
|
+
'reference/configuration.md': 'Configuration',
|
|
33
|
+
'reference/environment.md': 'Environment Variables',
|
|
34
|
+
'reference/dependencies.md': 'Dependencies',
|
|
35
|
+
// Patterns & Conventions
|
|
36
|
+
'patterns/index.md': 'Patterns & Conventions',
|
|
37
|
+
'patterns/coding-standards.md': 'Coding Standards',
|
|
38
|
+
'patterns/naming-conventions.md': 'Naming Conventions',
|
|
39
|
+
'patterns/file-structure.md': 'File Structure',
|
|
40
|
+
// Testing
|
|
41
|
+
'testing/index.md': 'Testing Documentation',
|
|
42
|
+
'testing/strategy.md': 'Testing Strategy',
|
|
43
|
+
'testing/unit-tests.md': 'Unit Testing',
|
|
44
|
+
'testing/integration-tests.md': 'Integration Testing',
|
|
45
|
+
'testing/e2e-tests.md': 'E2E Testing',
|
|
46
|
+
// Deployment
|
|
47
|
+
'deployment/index.md': 'Deployment Documentation',
|
|
48
|
+
'deployment/environments.md': 'Environments',
|
|
49
|
+
'deployment/ci-cd.md': 'CI/CD Pipeline',
|
|
50
|
+
'deployment/infrastructure.md': 'Infrastructure',
|
|
51
|
+
// Decisions (ADRs)
|
|
52
|
+
'decisions/index.md': 'Architecture Decision Records',
|
|
53
|
+
'decisions/template.md': 'ADR Template',
|
|
54
|
+
};
|
|
55
|
+
// =============================================================================
|
|
56
|
+
// Claude Inference for Doc Generation
|
|
57
|
+
// =============================================================================
|
|
58
|
+
async function runClaudeForDocs(prompt, projectPath, timeout = 90000) {
|
|
59
|
+
return new Promise((resolve) => {
|
|
60
|
+
const proc = spawn('claude', ['--print', '--dangerously-skip-permissions', prompt], {
|
|
61
|
+
cwd: projectPath,
|
|
62
|
+
stdio: ['pipe', 'pipe', 'pipe'],
|
|
63
|
+
timeout,
|
|
64
|
+
});
|
|
65
|
+
let stdout = '';
|
|
66
|
+
const timer = setTimeout(() => {
|
|
67
|
+
proc.kill();
|
|
68
|
+
resolve(null);
|
|
69
|
+
}, timeout);
|
|
70
|
+
proc.stdout?.on('data', (data) => {
|
|
71
|
+
stdout += data.toString();
|
|
72
|
+
});
|
|
73
|
+
proc.on('close', (code) => {
|
|
74
|
+
clearTimeout(timer);
|
|
75
|
+
resolve(code === 0 ? stdout.trim() : null);
|
|
76
|
+
});
|
|
77
|
+
proc.on('error', () => {
|
|
78
|
+
clearTimeout(timer);
|
|
79
|
+
resolve(null);
|
|
80
|
+
});
|
|
81
|
+
});
|
|
82
|
+
}
|
|
83
|
+
// =============================================================================
|
|
84
|
+
// Document Generators
|
|
85
|
+
// =============================================================================
|
|
86
|
+
function generateDocsIndex(projectName, stack, answers) {
|
|
87
|
+
return `# ${projectName} Documentation
|
|
88
|
+
|
|
89
|
+
> Auto-generated documentation for AI agent assistance.
|
|
90
|
+
> Regenerate with \`claudetools onboard --refresh\`
|
|
91
|
+
|
|
92
|
+
## Project Overview
|
|
93
|
+
|
|
94
|
+
${answers.projectDescription || `${projectName} - A ${stack.primaryLanguage} project.`}
|
|
95
|
+
|
|
96
|
+
**Purpose:** ${answers.primaryPurpose || 'Software application'}
|
|
97
|
+
**Target Audience:** ${answers.targetAudience || 'Developers'}
|
|
98
|
+
|
|
99
|
+
## Quick Navigation
|
|
100
|
+
|
|
101
|
+
### Architecture
|
|
102
|
+
- [System Design](architecture/system-design.md) - Overall system architecture
|
|
103
|
+
- [Data Flow](architecture/data-flow.md) - How data moves through the system
|
|
104
|
+
- [Components](architecture/components.md) - Component breakdown
|
|
105
|
+
|
|
106
|
+
### API
|
|
107
|
+
- [Endpoints](api/endpoints.md) - API endpoint reference
|
|
108
|
+
- [Schemas](api/schemas.md) - Data schemas and types
|
|
109
|
+
- [Authentication](api/authentication.md) - Auth implementation
|
|
110
|
+
|
|
111
|
+
### Guides
|
|
112
|
+
- [Getting Started](guides/getting-started.md) - Setup and first steps
|
|
113
|
+
- [Development Workflow](guides/development-workflow.md) - Day-to-day development
|
|
114
|
+
- [Contributing](guides/contributing.md) - How to contribute
|
|
115
|
+
|
|
116
|
+
### Reference
|
|
117
|
+
- [Configuration](reference/configuration.md) - Configuration options
|
|
118
|
+
- [Environment](reference/environment.md) - Environment variables
|
|
119
|
+
- [Dependencies](reference/dependencies.md) - Project dependencies
|
|
120
|
+
|
|
121
|
+
### Patterns
|
|
122
|
+
- [Coding Standards](patterns/coding-standards.md) - Code style and standards
|
|
123
|
+
- [Naming Conventions](patterns/naming-conventions.md) - Naming rules
|
|
124
|
+
- [File Structure](patterns/file-structure.md) - Project organization
|
|
125
|
+
|
|
126
|
+
### Testing
|
|
127
|
+
- [Strategy](testing/strategy.md) - Testing approach
|
|
128
|
+
- [Unit Tests](testing/unit-tests.md) - Unit testing guide
|
|
129
|
+
- [E2E Tests](testing/e2e-tests.md) - End-to-end testing
|
|
130
|
+
|
|
131
|
+
### Deployment
|
|
132
|
+
- [Environments](deployment/environments.md) - Deployment environments
|
|
133
|
+
- [CI/CD](deployment/ci-cd.md) - Continuous integration/deployment
|
|
134
|
+
- [Infrastructure](deployment/infrastructure.md) - Infrastructure setup
|
|
135
|
+
|
|
136
|
+
### Decisions
|
|
137
|
+
- [ADR Index](decisions/index.md) - Architecture Decision Records
|
|
138
|
+
|
|
139
|
+
---
|
|
140
|
+
|
|
141
|
+
## Technology Stack
|
|
142
|
+
|
|
143
|
+
**Language:** ${stack.primaryLanguage}
|
|
144
|
+
**Package Manager:** ${stack.packageManager}
|
|
145
|
+
|
|
146
|
+
${stack.frameworks.length > 0 ? `### Frameworks\n${stack.frameworks.map(f => `- **${f.name}** ${f.version} (${f.category})`).join('\n')}` : ''}
|
|
147
|
+
|
|
148
|
+
${stack.libraries.length > 0 ? `### Libraries\n${stack.libraries.map(l => `- **${l.name}** ${l.version} (${l.category})`).join('\n')}` : ''}
|
|
149
|
+
|
|
150
|
+
${stack.devTools.length > 0 ? `### Dev Tools\n${stack.devTools.map(t => `- **${t.name}** (${t.category})`).join('\n')}` : ''}
|
|
151
|
+
|
|
152
|
+
---
|
|
153
|
+
|
|
154
|
+
*Last updated: ${new Date().toISOString()}*
|
|
155
|
+
`;
|
|
156
|
+
}
|
|
157
|
+
function generateArchitectureIndex(answers) {
|
|
158
|
+
return `# Architecture Overview
|
|
159
|
+
|
|
160
|
+
${answers.architectureStyle ? `**Architecture Style:** ${answers.architectureStyle}` : ''}
|
|
161
|
+
|
|
162
|
+
## Documents
|
|
163
|
+
|
|
164
|
+
- [System Design](system-design.md) - High-level system architecture
|
|
165
|
+
- [Data Flow](data-flow.md) - Data flow diagrams and descriptions
|
|
166
|
+
- [Components](components.md) - Component architecture and responsibilities
|
|
167
|
+
|
|
168
|
+
## Key Decisions
|
|
169
|
+
|
|
170
|
+
Architecture decisions are documented in [/decisions](../decisions/index.md).
|
|
171
|
+
`;
|
|
172
|
+
}
|
|
173
|
+
function generateSystemDesign(answers, stack) {
|
|
174
|
+
return `# System Design
|
|
175
|
+
|
|
176
|
+
## Overview
|
|
177
|
+
|
|
178
|
+
${answers.projectDescription || 'This document describes the system architecture.'}
|
|
179
|
+
|
|
180
|
+
## Architecture Style
|
|
181
|
+
|
|
182
|
+
${answers.architectureStyle || 'Not specified'}
|
|
183
|
+
|
|
184
|
+
## High-Level Architecture
|
|
185
|
+
|
|
186
|
+
\`\`\`
|
|
187
|
+
┌─────────────────────────────────────────────────────────────┐
|
|
188
|
+
│ Application │
|
|
189
|
+
├─────────────────────────────────────────────────────────────┤
|
|
190
|
+
│ ┌─────────────┐ ┌─────────────┐ ┌─────────────┐ │
|
|
191
|
+
│ │ UI Layer │ │ API Layer │ │ Services │ │
|
|
192
|
+
│ │ │ │ │ │ │ │
|
|
193
|
+
│ │ ${stack.frameworks.find(f => f.category === 'frontend')?.name || 'Frontend'} │ │ ${stack.frameworks.find(f => f.category === 'backend')?.name || 'Backend'} │ │ Business │ │
|
|
194
|
+
│ │ │ │ │ │ Logic │ │
|
|
195
|
+
│ └─────────────┘ └─────────────┘ └─────────────┘ │
|
|
196
|
+
├─────────────────────────────────────────────────────────────┤
|
|
197
|
+
│ Data Layer │
|
|
198
|
+
│ ┌─────────────┐ ┌─────────────┐ ┌─────────────┐ │
|
|
199
|
+
│ │ Database │ │ Cache │ │ Storage │ │
|
|
200
|
+
│ └─────────────┘ └─────────────┘ └─────────────┘ │
|
|
201
|
+
└─────────────────────────────────────────────────────────────┘
|
|
202
|
+
\`\`\`
|
|
203
|
+
|
|
204
|
+
## State Management
|
|
205
|
+
|
|
206
|
+
${answers.stateManagement || 'See codebase for state management implementation.'}
|
|
207
|
+
|
|
208
|
+
## Data Fetching
|
|
209
|
+
|
|
210
|
+
${answers.dataFetching || 'See codebase for data fetching patterns.'}
|
|
211
|
+
|
|
212
|
+
## Key Components
|
|
213
|
+
|
|
214
|
+
<!-- AI Agent: Analyze the codebase to identify and document key components -->
|
|
215
|
+
|
|
216
|
+
## Dependencies
|
|
217
|
+
|
|
218
|
+
See [dependencies.md](../reference/dependencies.md) for full dependency list.
|
|
219
|
+
`;
|
|
220
|
+
}
|
|
221
|
+
function generateDataFlow(answers) {
|
|
222
|
+
return `# Data Flow
|
|
223
|
+
|
|
224
|
+
## Overview
|
|
225
|
+
|
|
226
|
+
This document describes how data flows through the application.
|
|
227
|
+
|
|
228
|
+
## Request Flow
|
|
229
|
+
|
|
230
|
+
\`\`\`
|
|
231
|
+
User Action
|
|
232
|
+
│
|
|
233
|
+
▼
|
|
234
|
+
┌─────────┐
|
|
235
|
+
│ UI │ ──────────────────────────────────────┐
|
|
236
|
+
└────┬────┘ │
|
|
237
|
+
│ │
|
|
238
|
+
▼ ▼
|
|
239
|
+
┌─────────┐ ┌─────────┐ ┌─────────┐ ┌─────────┐
|
|
240
|
+
│ State │ ◄── │ API │ ◄── │ Service │──│Database │
|
|
241
|
+
│ Manager │ │ Client │ │ Layer │ │ │
|
|
242
|
+
└─────────┘ └─────────┘ └─────────┘ └─────────┘
|
|
243
|
+
\`\`\`
|
|
244
|
+
|
|
245
|
+
## Data Fetching Pattern
|
|
246
|
+
|
|
247
|
+
${answers.dataFetching || 'Standard fetch/API pattern'}
|
|
248
|
+
|
|
249
|
+
## State Updates
|
|
250
|
+
|
|
251
|
+
${answers.stateManagement || 'See state management documentation'}
|
|
252
|
+
|
|
253
|
+
<!-- AI Agent: Document specific data flows for key features -->
|
|
254
|
+
`;
|
|
255
|
+
}
|
|
256
|
+
function generateComponentArchitecture(stack) {
|
|
257
|
+
const isReact = stack.frameworks.some(f => ['react', 'next'].includes(f.name.toLowerCase()));
|
|
258
|
+
return `# Component Architecture
|
|
259
|
+
|
|
260
|
+
## Overview
|
|
261
|
+
|
|
262
|
+
${isReact ? 'This project uses React components with a functional component approach.' : 'Component-based architecture.'}
|
|
263
|
+
|
|
264
|
+
## Component Hierarchy
|
|
265
|
+
|
|
266
|
+
\`\`\`
|
|
267
|
+
App
|
|
268
|
+
├── Layout
|
|
269
|
+
│ ├── Header
|
|
270
|
+
│ ├── Navigation
|
|
271
|
+
│ └── Footer
|
|
272
|
+
├── Pages
|
|
273
|
+
│ ├── Home
|
|
274
|
+
│ ├── Dashboard
|
|
275
|
+
│ └── Settings
|
|
276
|
+
└── Shared
|
|
277
|
+
├── UI Components
|
|
278
|
+
├── Forms
|
|
279
|
+
└── Utilities
|
|
280
|
+
\`\`\`
|
|
281
|
+
|
|
282
|
+
## Component Guidelines
|
|
283
|
+
|
|
284
|
+
1. **Single Responsibility** - Each component does one thing well
|
|
285
|
+
2. **Composition** - Build complex UIs from simple components
|
|
286
|
+
3. **Props Interface** - Clear, typed props for each component
|
|
287
|
+
4. **State Colocation** - Keep state as close to usage as possible
|
|
288
|
+
|
|
289
|
+
## Component Categories
|
|
290
|
+
|
|
291
|
+
### Layout Components
|
|
292
|
+
Structural components that define page layout.
|
|
293
|
+
|
|
294
|
+
### Feature Components
|
|
295
|
+
Business logic and feature-specific components.
|
|
296
|
+
|
|
297
|
+
### UI Components
|
|
298
|
+
Reusable, presentational components.
|
|
299
|
+
|
|
300
|
+
### Utility Components
|
|
301
|
+
Error boundaries, providers, HOCs.
|
|
302
|
+
|
|
303
|
+
<!-- AI Agent: Analyze src/components to document actual component structure -->
|
|
304
|
+
`;
|
|
305
|
+
}
|
|
306
|
+
function generateApiIndex(stack) {
|
|
307
|
+
return `# API Documentation
|
|
308
|
+
|
|
309
|
+
## Overview
|
|
310
|
+
|
|
311
|
+
API documentation for ${stack.frameworks.find(f => f.category === 'backend')?.name || 'the backend'}.
|
|
312
|
+
|
|
313
|
+
## Documents
|
|
314
|
+
|
|
315
|
+
- [Endpoints](endpoints.md) - API endpoint reference
|
|
316
|
+
- [Schemas](schemas.md) - Request/response schemas
|
|
317
|
+
- [Authentication](authentication.md) - Auth implementation
|
|
318
|
+
|
|
319
|
+
## Base URL
|
|
320
|
+
|
|
321
|
+
\`\`\`
|
|
322
|
+
Development: http://localhost:3000/api
|
|
323
|
+
Production: https://api.example.com
|
|
324
|
+
\`\`\`
|
|
325
|
+
|
|
326
|
+
## Authentication
|
|
327
|
+
|
|
328
|
+
See [authentication.md](authentication.md) for details.
|
|
329
|
+
|
|
330
|
+
## Error Handling
|
|
331
|
+
|
|
332
|
+
All errors follow this format:
|
|
333
|
+
|
|
334
|
+
\`\`\`json
|
|
335
|
+
{
|
|
336
|
+
"error": {
|
|
337
|
+
"code": "ERROR_CODE",
|
|
338
|
+
"message": "Human readable message",
|
|
339
|
+
"details": {}
|
|
340
|
+
}
|
|
341
|
+
}
|
|
342
|
+
\`\`\`
|
|
343
|
+
`;
|
|
344
|
+
}
|
|
345
|
+
function generateEndpoints() {
|
|
346
|
+
return `# API Endpoints
|
|
347
|
+
|
|
348
|
+
## Overview
|
|
349
|
+
|
|
350
|
+
This document lists all API endpoints.
|
|
351
|
+
|
|
352
|
+
<!-- AI Agent: Scan route files to document actual endpoints -->
|
|
353
|
+
|
|
354
|
+
## Endpoints
|
|
355
|
+
|
|
356
|
+
### Authentication
|
|
357
|
+
|
|
358
|
+
| Method | Path | Description |
|
|
359
|
+
|--------|------|-------------|
|
|
360
|
+
| POST | /api/auth/login | User login |
|
|
361
|
+
| POST | /api/auth/register | User registration |
|
|
362
|
+
| POST | /api/auth/logout | User logout |
|
|
363
|
+
| GET | /api/auth/me | Get current user |
|
|
364
|
+
|
|
365
|
+
### Resources
|
|
366
|
+
|
|
367
|
+
| Method | Path | Description |
|
|
368
|
+
|--------|------|-------------|
|
|
369
|
+
| GET | /api/resources | List resources |
|
|
370
|
+
| POST | /api/resources | Create resource |
|
|
371
|
+
| GET | /api/resources/:id | Get resource |
|
|
372
|
+
| PUT | /api/resources/:id | Update resource |
|
|
373
|
+
| DELETE | /api/resources/:id | Delete resource |
|
|
374
|
+
|
|
375
|
+
## Request Examples
|
|
376
|
+
|
|
377
|
+
\`\`\`bash
|
|
378
|
+
# Login
|
|
379
|
+
curl -X POST http://localhost:3000/api/auth/login \\
|
|
380
|
+
-H "Content-Type: application/json" \\
|
|
381
|
+
-d '{"email": "user@example.com", "password": "secret"}'
|
|
382
|
+
\`\`\`
|
|
383
|
+
`;
|
|
384
|
+
}
|
|
385
|
+
function generateSchemas(stack) {
|
|
386
|
+
const hasZod = stack.libraries.some(l => l.name === 'zod');
|
|
387
|
+
const hasPrisma = stack.libraries.some(l => l.name.includes('prisma'));
|
|
388
|
+
return `# Data Schemas
|
|
389
|
+
|
|
390
|
+
## Overview
|
|
391
|
+
|
|
392
|
+
${hasZod ? 'This project uses Zod for runtime validation.' : ''}
|
|
393
|
+
${hasPrisma ? 'Database schemas are defined with Prisma.' : ''}
|
|
394
|
+
|
|
395
|
+
## Core Schemas
|
|
396
|
+
|
|
397
|
+
<!-- AI Agent: Extract actual schemas from codebase -->
|
|
398
|
+
|
|
399
|
+
### User
|
|
400
|
+
|
|
401
|
+
\`\`\`typescript
|
|
402
|
+
interface User {
|
|
403
|
+
id: string;
|
|
404
|
+
email: string;
|
|
405
|
+
name: string;
|
|
406
|
+
createdAt: Date;
|
|
407
|
+
updatedAt: Date;
|
|
408
|
+
}
|
|
409
|
+
\`\`\`
|
|
410
|
+
|
|
411
|
+
### Common Types
|
|
412
|
+
|
|
413
|
+
\`\`\`typescript
|
|
414
|
+
type ID = string;
|
|
415
|
+
type Timestamp = Date;
|
|
416
|
+
type Email = string;
|
|
417
|
+
\`\`\`
|
|
418
|
+
|
|
419
|
+
## Validation
|
|
420
|
+
|
|
421
|
+
${hasZod ? `
|
|
422
|
+
Schemas are validated using Zod:
|
|
423
|
+
|
|
424
|
+
\`\`\`typescript
|
|
425
|
+
import { z } from 'zod';
|
|
426
|
+
|
|
427
|
+
const UserSchema = z.object({
|
|
428
|
+
email: z.string().email(),
|
|
429
|
+
name: z.string().min(1),
|
|
430
|
+
password: z.string().min(8),
|
|
431
|
+
});
|
|
432
|
+
\`\`\`
|
|
433
|
+
` : 'See codebase for validation implementation.'}
|
|
434
|
+
`;
|
|
435
|
+
}
|
|
436
|
+
function generateGettingStarted(stack) {
|
|
437
|
+
const pm = stack.packageManager;
|
|
438
|
+
const installCmd = pm === 'yarn' ? 'yarn' : pm === 'pnpm' ? 'pnpm install' : 'npm install';
|
|
439
|
+
const devCmd = pm === 'yarn' ? 'yarn dev' : pm === 'pnpm' ? 'pnpm dev' : 'npm run dev';
|
|
440
|
+
return `# Getting Started
|
|
441
|
+
|
|
442
|
+
## Prerequisites
|
|
443
|
+
|
|
444
|
+
- Node.js >= 18.0.0
|
|
445
|
+
- ${stack.packageManager} package manager
|
|
446
|
+
|
|
447
|
+
## Installation
|
|
448
|
+
|
|
449
|
+
\`\`\`bash
|
|
450
|
+
# Clone the repository
|
|
451
|
+
git clone <repository-url>
|
|
452
|
+
cd <project-name>
|
|
453
|
+
|
|
454
|
+
# Install dependencies
|
|
455
|
+
${installCmd}
|
|
456
|
+
|
|
457
|
+
# Set up environment
|
|
458
|
+
cp .env.example .env
|
|
459
|
+
# Edit .env with your configuration
|
|
460
|
+
|
|
461
|
+
# Start development server
|
|
462
|
+
${devCmd}
|
|
463
|
+
\`\`\`
|
|
464
|
+
|
|
465
|
+
## Environment Setup
|
|
466
|
+
|
|
467
|
+
1. Copy \`.env.example\` to \`.env\`
|
|
468
|
+
2. Configure required variables (see [environment.md](../reference/environment.md))
|
|
469
|
+
3. Set up any external services
|
|
470
|
+
|
|
471
|
+
## First Steps
|
|
472
|
+
|
|
473
|
+
1. Run the development server
|
|
474
|
+
2. Open http://localhost:3000
|
|
475
|
+
3. Explore the codebase
|
|
476
|
+
|
|
477
|
+
## Common Tasks
|
|
478
|
+
|
|
479
|
+
| Task | Command |
|
|
480
|
+
|------|---------|
|
|
481
|
+
| Development | \`${devCmd}\` |
|
|
482
|
+
| Build | \`${pm === 'yarn' ? 'yarn build' : pm + ' run build'}\` |
|
|
483
|
+
| Test | \`${pm === 'yarn' ? 'yarn test' : pm + ' test'}\` |
|
|
484
|
+
| Lint | \`${pm === 'yarn' ? 'yarn lint' : pm + ' run lint'}\` |
|
|
485
|
+
|
|
486
|
+
## Next Steps
|
|
487
|
+
|
|
488
|
+
- Read [Development Workflow](development-workflow.md)
|
|
489
|
+
- Review [Coding Standards](../patterns/coding-standards.md)
|
|
490
|
+
- Check [Architecture Overview](../architecture/index.md)
|
|
491
|
+
`;
|
|
492
|
+
}
|
|
493
|
+
function generateDevelopmentWorkflow(stack) {
|
|
494
|
+
return `# Development Workflow
|
|
495
|
+
|
|
496
|
+
## Branch Strategy
|
|
497
|
+
|
|
498
|
+
\`\`\`
|
|
499
|
+
main
|
|
500
|
+
│
|
|
501
|
+
├── develop
|
|
502
|
+
│ │
|
|
503
|
+
│ ├── feature/xxx
|
|
504
|
+
│ ├── fix/xxx
|
|
505
|
+
│ └── chore/xxx
|
|
506
|
+
│
|
|
507
|
+
└── release/x.x.x
|
|
508
|
+
\`\`\`
|
|
509
|
+
|
|
510
|
+
## Development Cycle
|
|
511
|
+
|
|
512
|
+
1. **Create Branch** - \`git checkout -b feature/my-feature\`
|
|
513
|
+
2. **Develop** - Make changes, write tests
|
|
514
|
+
3. **Test** - Run test suite
|
|
515
|
+
4. **Commit** - Follow commit conventions
|
|
516
|
+
5. **Push** - Push to remote
|
|
517
|
+
6. **PR** - Create pull request
|
|
518
|
+
7. **Review** - Code review process
|
|
519
|
+
8. **Merge** - Merge to develop
|
|
520
|
+
|
|
521
|
+
## Commit Convention
|
|
522
|
+
|
|
523
|
+
\`\`\`
|
|
524
|
+
type(scope): description
|
|
525
|
+
|
|
526
|
+
[optional body]
|
|
527
|
+
|
|
528
|
+
[optional footer]
|
|
529
|
+
\`\`\`
|
|
530
|
+
|
|
531
|
+
Types: \`feat\`, \`fix\`, \`docs\`, \`style\`, \`refactor\`, \`test\`, \`chore\`
|
|
532
|
+
|
|
533
|
+
## Code Review Checklist
|
|
534
|
+
|
|
535
|
+
- [ ] Code follows project conventions
|
|
536
|
+
- [ ] Tests pass
|
|
537
|
+
- [ ] No console.log or debug code
|
|
538
|
+
- [ ] Documentation updated if needed
|
|
539
|
+
- [ ] No hardcoded values
|
|
540
|
+
- [ ] Error handling in place
|
|
541
|
+
`;
|
|
542
|
+
}
|
|
543
|
+
function generateCodingStandards(answers, stack) {
|
|
544
|
+
const conventions = answers.codingConventions || [];
|
|
545
|
+
return `# Coding Standards
|
|
546
|
+
|
|
547
|
+
## Overview
|
|
548
|
+
|
|
549
|
+
This document defines the coding standards for this project.
|
|
550
|
+
|
|
551
|
+
## Language
|
|
552
|
+
|
|
553
|
+
**Primary Language:** ${stack.primaryLanguage}
|
|
554
|
+
|
|
555
|
+
## General Principles
|
|
556
|
+
|
|
557
|
+
1. **Readability** - Code should be self-documenting
|
|
558
|
+
2. **Simplicity** - Prefer simple solutions
|
|
559
|
+
3. **Consistency** - Follow established patterns
|
|
560
|
+
4. **Testability** - Write testable code
|
|
561
|
+
|
|
562
|
+
## Conventions
|
|
563
|
+
|
|
564
|
+
${conventions.length > 0 ? conventions.map(c => `- ${c}`).join('\n') : '- Follow standard conventions for the language'}
|
|
565
|
+
|
|
566
|
+
## TypeScript Guidelines
|
|
567
|
+
|
|
568
|
+
${stack.primaryLanguage === 'typescript' ? `
|
|
569
|
+
- Use strict mode
|
|
570
|
+
- Avoid \`any\` - use \`unknown\` if type is truly unknown
|
|
571
|
+
- Prefer interfaces for object shapes
|
|
572
|
+
- Use type guards for narrowing
|
|
573
|
+
- Export types alongside implementations
|
|
574
|
+
` : 'See language-specific guidelines.'}
|
|
575
|
+
|
|
576
|
+
## Component Guidelines
|
|
577
|
+
|
|
578
|
+
${stack.frameworks.some(f => f.name.toLowerCase().includes('react')) ? `
|
|
579
|
+
- Use functional components
|
|
580
|
+
- Keep components small and focused
|
|
581
|
+
- Extract reusable logic to custom hooks
|
|
582
|
+
- Use composition over inheritance
|
|
583
|
+
- Prop types should be explicit
|
|
584
|
+
` : ''}
|
|
585
|
+
|
|
586
|
+
## File Organization
|
|
587
|
+
|
|
588
|
+
\`\`\`
|
|
589
|
+
src/
|
|
590
|
+
├── components/ # UI components
|
|
591
|
+
├── hooks/ # Custom hooks
|
|
592
|
+
├── lib/ # Utilities
|
|
593
|
+
├── services/ # API services
|
|
594
|
+
├── types/ # Type definitions
|
|
595
|
+
└── utils/ # Helper functions
|
|
596
|
+
\`\`\`
|
|
597
|
+
`;
|
|
598
|
+
}
|
|
599
|
+
function generateTestingStrategy(answers, stack) {
|
|
600
|
+
const approaches = answers.testingApproach || [];
|
|
601
|
+
const hasVitest = stack.devTools.some(t => t.name === 'vitest');
|
|
602
|
+
const hasJest = stack.devTools.some(t => t.name === 'jest');
|
|
603
|
+
const hasPlaywright = stack.devTools.some(t => t.name === 'playwright');
|
|
604
|
+
return `# Testing Strategy
|
|
605
|
+
|
|
606
|
+
## Overview
|
|
607
|
+
|
|
608
|
+
${Array.isArray(approaches) && approaches.length > 0 ? `Testing approaches used:\n${approaches.map((a) => `- ${a}`).join('\n')}` : 'Testing approach to be defined.'}
|
|
609
|
+
|
|
610
|
+
## Test Framework
|
|
611
|
+
|
|
612
|
+
${hasVitest ? '**Vitest** - Fast unit test runner' : ''}
|
|
613
|
+
${hasJest ? '**Jest** - Test framework' : ''}
|
|
614
|
+
${hasPlaywright ? '**Playwright** - E2E testing' : ''}
|
|
615
|
+
|
|
616
|
+
## Testing Pyramid
|
|
617
|
+
|
|
618
|
+
\`\`\`
|
|
619
|
+
╱╲
|
|
620
|
+
╱ ╲
|
|
621
|
+
╱ E2E╲ Few, critical paths
|
|
622
|
+
╱──────╲
|
|
623
|
+
╱ ╲
|
|
624
|
+
╱Integration╲ Some, key integrations
|
|
625
|
+
╱────────────╲
|
|
626
|
+
╱ ╲
|
|
627
|
+
╱ Unit Tests ╲ Many, fast, isolated
|
|
628
|
+
╲────────────────╱
|
|
629
|
+
\`\`\`
|
|
630
|
+
|
|
631
|
+
## Test Organization
|
|
632
|
+
|
|
633
|
+
\`\`\`
|
|
634
|
+
__tests__/
|
|
635
|
+
├── unit/ # Unit tests
|
|
636
|
+
├── integration/ # Integration tests
|
|
637
|
+
└── e2e/ # End-to-end tests
|
|
638
|
+
\`\`\`
|
|
639
|
+
|
|
640
|
+
## Running Tests
|
|
641
|
+
|
|
642
|
+
\`\`\`bash
|
|
643
|
+
# Run all tests
|
|
644
|
+
${stack.packageManager} test
|
|
645
|
+
|
|
646
|
+
# Run with coverage
|
|
647
|
+
${stack.packageManager} test --coverage
|
|
648
|
+
|
|
649
|
+
# Run specific test
|
|
650
|
+
${stack.packageManager} test -- path/to/test
|
|
651
|
+
\`\`\`
|
|
652
|
+
|
|
653
|
+
## Coverage Requirements
|
|
654
|
+
|
|
655
|
+
- Statements: 80%
|
|
656
|
+
- Branches: 75%
|
|
657
|
+
- Functions: 80%
|
|
658
|
+
- Lines: 80%
|
|
659
|
+
`;
|
|
660
|
+
}
|
|
661
|
+
function generateDeploymentEnvironments() {
|
|
662
|
+
return `# Environments
|
|
663
|
+
|
|
664
|
+
## Overview
|
|
665
|
+
|
|
666
|
+
| Environment | Purpose | URL |
|
|
667
|
+
|-------------|---------|-----|
|
|
668
|
+
| Development | Local dev | localhost:3000 |
|
|
669
|
+
| Staging | Pre-production | staging.example.com |
|
|
670
|
+
| Production | Live | example.com |
|
|
671
|
+
|
|
672
|
+
## Environment Variables
|
|
673
|
+
|
|
674
|
+
See [environment.md](../reference/environment.md) for variable documentation.
|
|
675
|
+
|
|
676
|
+
## Configuration by Environment
|
|
677
|
+
|
|
678
|
+
### Development
|
|
679
|
+
- Debug logging enabled
|
|
680
|
+
- Hot reload active
|
|
681
|
+
- Mock services available
|
|
682
|
+
|
|
683
|
+
### Staging
|
|
684
|
+
- Production-like setup
|
|
685
|
+
- Test data available
|
|
686
|
+
- Debug tools enabled
|
|
687
|
+
|
|
688
|
+
### Production
|
|
689
|
+
- Optimized builds
|
|
690
|
+
- Error tracking
|
|
691
|
+
- Performance monitoring
|
|
692
|
+
`;
|
|
693
|
+
}
|
|
694
|
+
function generateAdrTemplate() {
|
|
695
|
+
return `# ADR Template
|
|
696
|
+
|
|
697
|
+
Use this template for new Architecture Decision Records.
|
|
698
|
+
|
|
699
|
+
---
|
|
700
|
+
|
|
701
|
+
# ADR-XXX: Title
|
|
702
|
+
|
|
703
|
+
## Status
|
|
704
|
+
|
|
705
|
+
Proposed | Accepted | Deprecated | Superseded
|
|
706
|
+
|
|
707
|
+
## Context
|
|
708
|
+
|
|
709
|
+
What is the issue that we're seeing that is motivating this decision?
|
|
710
|
+
|
|
711
|
+
## Decision
|
|
712
|
+
|
|
713
|
+
What is the change that we're proposing and/or doing?
|
|
714
|
+
|
|
715
|
+
## Consequences
|
|
716
|
+
|
|
717
|
+
What becomes easier or more difficult to do because of this change?
|
|
718
|
+
|
|
719
|
+
### Positive
|
|
720
|
+
|
|
721
|
+
- Benefit 1
|
|
722
|
+
- Benefit 2
|
|
723
|
+
|
|
724
|
+
### Negative
|
|
725
|
+
|
|
726
|
+
- Drawback 1
|
|
727
|
+
- Drawback 2
|
|
728
|
+
|
|
729
|
+
### Neutral
|
|
730
|
+
|
|
731
|
+
- Side effect 1
|
|
732
|
+
|
|
733
|
+
## References
|
|
734
|
+
|
|
735
|
+
- Link to related docs
|
|
736
|
+
- Link to discussions
|
|
737
|
+
`;
|
|
738
|
+
}
|
|
739
|
+
function generateAdrIndex() {
|
|
740
|
+
return `# Architecture Decision Records
|
|
741
|
+
|
|
742
|
+
## Overview
|
|
743
|
+
|
|
744
|
+
Architecture Decision Records (ADRs) document significant architectural decisions.
|
|
745
|
+
|
|
746
|
+
## Index
|
|
747
|
+
|
|
748
|
+
| ADR | Title | Status | Date |
|
|
749
|
+
|-----|-------|--------|------|
|
|
750
|
+
| 001 | [Template](template.md) | Template | - |
|
|
751
|
+
|
|
752
|
+
## Creating New ADRs
|
|
753
|
+
|
|
754
|
+
1. Copy \`template.md\`
|
|
755
|
+
2. Number sequentially (ADR-002, ADR-003, etc.)
|
|
756
|
+
3. Fill in all sections
|
|
757
|
+
4. Submit for review
|
|
758
|
+
|
|
759
|
+
## ADR Lifecycle
|
|
760
|
+
|
|
761
|
+
1. **Proposed** - Under discussion
|
|
762
|
+
2. **Accepted** - Decision made
|
|
763
|
+
3. **Deprecated** - No longer applies
|
|
764
|
+
4. **Superseded** - Replaced by newer ADR
|
|
765
|
+
`;
|
|
766
|
+
}
|
|
767
|
+
// =============================================================================
|
|
768
|
+
// Main Builder
|
|
769
|
+
// =============================================================================
|
|
770
|
+
export async function buildDocs(projectPath, projectName, stack, answers, options = {}) {
|
|
771
|
+
const docsPath = join(projectPath, 'docs');
|
|
772
|
+
const generatedDocs = [];
|
|
773
|
+
const useClaude = options.useClaudeInference && isClaudeCliAvailable();
|
|
774
|
+
// Create directory structure
|
|
775
|
+
const directories = [
|
|
776
|
+
docsPath,
|
|
777
|
+
join(docsPath, 'architecture'),
|
|
778
|
+
join(docsPath, 'api'),
|
|
779
|
+
join(docsPath, 'guides'),
|
|
780
|
+
join(docsPath, 'reference'),
|
|
781
|
+
join(docsPath, 'patterns'),
|
|
782
|
+
join(docsPath, 'testing'),
|
|
783
|
+
join(docsPath, 'deployment'),
|
|
784
|
+
join(docsPath, 'decisions'),
|
|
785
|
+
];
|
|
786
|
+
for (const dir of directories) {
|
|
787
|
+
if (!existsSync(dir)) {
|
|
788
|
+
mkdirSync(dir, { recursive: true });
|
|
789
|
+
}
|
|
790
|
+
}
|
|
791
|
+
// Generate base documents with templates
|
|
792
|
+
const docs = {
|
|
793
|
+
'index.md': generateDocsIndex(projectName, stack, answers),
|
|
794
|
+
'architecture/index.md': generateArchitectureIndex(answers),
|
|
795
|
+
'guides/index.md': '# Development Guides\n\n- [Getting Started](getting-started.md)\n- [Development Workflow](development-workflow.md)\n- [Contributing](contributing.md)\n',
|
|
796
|
+
'guides/getting-started.md': generateGettingStarted(stack),
|
|
797
|
+
'guides/development-workflow.md': generateDevelopmentWorkflow(stack),
|
|
798
|
+
'reference/index.md': '# Technical Reference\n\n- [Configuration](configuration.md)\n- [Environment](environment.md)\n- [Dependencies](dependencies.md)\n',
|
|
799
|
+
'patterns/index.md': '# Patterns & Conventions\n\n- [Coding Standards](coding-standards.md)\n- [Naming Conventions](naming-conventions.md)\n- [File Structure](file-structure.md)\n',
|
|
800
|
+
'testing/index.md': '# Testing Documentation\n\n- [Strategy](strategy.md)\n- [Unit Tests](unit-tests.md)\n- [Integration Tests](integration-tests.md)\n- [E2E Tests](e2e-tests.md)\n',
|
|
801
|
+
'deployment/index.md': '# Deployment Documentation\n\n- [Environments](environments.md)\n- [CI/CD](ci-cd.md)\n- [Infrastructure](infrastructure.md)\n',
|
|
802
|
+
'deployment/environments.md': generateDeploymentEnvironments(),
|
|
803
|
+
'decisions/index.md': generateAdrIndex(),
|
|
804
|
+
'decisions/template.md': generateAdrTemplate(),
|
|
805
|
+
};
|
|
806
|
+
// Claude-generated documents - analyze codebase and generate actual content
|
|
807
|
+
if (useClaude) {
|
|
808
|
+
const claudePrompts = {
|
|
809
|
+
'architecture/system-design.md': `Analyze this codebase and write a System Design document. Include:
|
|
810
|
+
- Overall architecture overview
|
|
811
|
+
- High-level component diagram (ASCII art)
|
|
812
|
+
- Key modules and their responsibilities
|
|
813
|
+
- Technology choices and rationale
|
|
814
|
+
- Data storage approach
|
|
815
|
+
Format as markdown. Be specific to THIS codebase, not generic.`,
|
|
816
|
+
'architecture/data-flow.md': `Analyze this codebase and document the Data Flow. Include:
|
|
817
|
+
- How data enters the system (user input, API calls, etc.)
|
|
818
|
+
- State management approach and data stores
|
|
819
|
+
- Data transformation pipeline
|
|
820
|
+
- API request/response flow
|
|
821
|
+
- Side effects and external service communication
|
|
822
|
+
Use ASCII diagrams where helpful. Be specific to this codebase.`,
|
|
823
|
+
'architecture/components.md': `Analyze the component structure in this codebase and document:
|
|
824
|
+
- Component hierarchy (ASCII tree)
|
|
825
|
+
- Key components and their purposes
|
|
826
|
+
- Component categories (layout, feature, UI, utility)
|
|
827
|
+
- Props patterns and data flow between components
|
|
828
|
+
- Shared components and their usage
|
|
829
|
+
Be specific to the actual components found.`,
|
|
830
|
+
'api/index.md': `Analyze this codebase's API structure and create an API Overview document:
|
|
831
|
+
- API architecture approach (REST, GraphQL, tRPC, etc.)
|
|
832
|
+
- Base URL and versioning strategy
|
|
833
|
+
- Authentication method
|
|
834
|
+
- Request/response format
|
|
835
|
+
- Error handling conventions
|
|
836
|
+
Be specific to what's actually implemented.`,
|
|
837
|
+
'api/endpoints.md': `Scan this codebase for API routes/endpoints and document them:
|
|
838
|
+
- List all endpoints with methods (GET, POST, etc.)
|
|
839
|
+
- Group by resource/feature
|
|
840
|
+
- Include request parameters and body schemas
|
|
841
|
+
- Include response formats
|
|
842
|
+
- Note any middleware or authentication requirements
|
|
843
|
+
Format as markdown tables. Document actual endpoints found.`,
|
|
844
|
+
'api/schemas.md': `Analyze this codebase for data schemas and types. Document:
|
|
845
|
+
- Core data models/entities
|
|
846
|
+
- TypeScript interfaces or types
|
|
847
|
+
- Zod schemas if present
|
|
848
|
+
- Database models if applicable
|
|
849
|
+
- Request/response DTOs
|
|
850
|
+
Include actual code examples from the codebase.`,
|
|
851
|
+
'api/authentication.md': `Analyze the authentication implementation in this codebase:
|
|
852
|
+
- Authentication method (JWT, sessions, OAuth, etc.)
|
|
853
|
+
- Login/logout flow
|
|
854
|
+
- Token storage and refresh
|
|
855
|
+
- Protected routes/middleware
|
|
856
|
+
- User session management
|
|
857
|
+
Document what's actually implemented, or note if auth is not yet implemented.`,
|
|
858
|
+
'guides/contributing.md': `Create a Contributing Guide for this project based on its setup:
|
|
859
|
+
- How to set up the development environment
|
|
860
|
+
- Code style and conventions used
|
|
861
|
+
- Branch naming and PR process
|
|
862
|
+
- Testing requirements
|
|
863
|
+
- Commit message format
|
|
864
|
+
Base this on actual project configuration found.`,
|
|
865
|
+
'reference/configuration.md': `Document the configuration system for this project:
|
|
866
|
+
- Configuration files and their purposes
|
|
867
|
+
- Build configuration (webpack, vite, tsconfig, etc.)
|
|
868
|
+
- Framework configuration (next.config, etc.)
|
|
869
|
+
- Linting and formatting setup
|
|
870
|
+
Include actual config file contents and explanations.`,
|
|
871
|
+
'reference/environment.md': `Document environment variables for this project:
|
|
872
|
+
- List all env vars from .env.example or .env files
|
|
873
|
+
- Explain purpose of each variable
|
|
874
|
+
- Mark required vs optional
|
|
875
|
+
- Note default values
|
|
876
|
+
- Group by category (database, API keys, feature flags)
|
|
877
|
+
Document actual variables found in the codebase.`,
|
|
878
|
+
'reference/dependencies.md': `Analyze package.json and document key dependencies:
|
|
879
|
+
- Core dependencies and their purposes
|
|
880
|
+
- Development dependencies explained
|
|
881
|
+
- Peer dependencies if any
|
|
882
|
+
- Version requirements and compatibility notes
|
|
883
|
+
Group by category (framework, UI, testing, tooling).`,
|
|
884
|
+
'patterns/coding-standards.md': generateCodingStandards(answers, stack) + `
|
|
885
|
+
|
|
886
|
+
<!-- Claude: Enhance this with specific patterns observed in the codebase -->`,
|
|
887
|
+
'patterns/naming-conventions.md': `Analyze this codebase and document the naming conventions used:
|
|
888
|
+
- File naming patterns (kebab-case, PascalCase, etc.)
|
|
889
|
+
- Component naming conventions
|
|
890
|
+
- Function and variable naming
|
|
891
|
+
- CSS/styling class names
|
|
892
|
+
- Route/URL naming
|
|
893
|
+
Provide specific examples from the actual codebase.`,
|
|
894
|
+
'patterns/file-structure.md': `Document the file structure of this project:
|
|
895
|
+
- Directory layout with explanations
|
|
896
|
+
- File organization patterns
|
|
897
|
+
- Module boundaries
|
|
898
|
+
- Import/export conventions
|
|
899
|
+
- Where different types of code belong
|
|
900
|
+
Use ASCII tree diagrams. Be specific to this codebase.`,
|
|
901
|
+
'testing/strategy.md': generateTestingStrategy(answers, stack) + `
|
|
902
|
+
|
|
903
|
+
<!-- Claude: Enhance with specific testing patterns from this codebase -->`,
|
|
904
|
+
'testing/unit-tests.md': `Document unit testing in this project:
|
|
905
|
+
- Test framework and configuration
|
|
906
|
+
- Test file organization
|
|
907
|
+
- Mocking patterns used
|
|
908
|
+
- Common test utilities
|
|
909
|
+
- Example test patterns
|
|
910
|
+
Include actual examples from the codebase if tests exist.`,
|
|
911
|
+
'testing/integration-tests.md': `Document integration testing in this project:
|
|
912
|
+
- Integration test setup
|
|
913
|
+
- Database/API mocking
|
|
914
|
+
- Test data management
|
|
915
|
+
- CI integration
|
|
916
|
+
Include examples from the codebase if present, or recommendations if not.`,
|
|
917
|
+
'testing/e2e-tests.md': `Document E2E testing in this project:
|
|
918
|
+
- E2E framework (Playwright, Cypress, etc.)
|
|
919
|
+
- Test configuration
|
|
920
|
+
- Page object patterns
|
|
921
|
+
- Test data and fixtures
|
|
922
|
+
- Running E2E tests locally and in CI
|
|
923
|
+
Document actual setup or provide recommendations.`,
|
|
924
|
+
'deployment/ci-cd.md': `Analyze CI/CD configuration in this project:
|
|
925
|
+
- CI/CD platform (GitHub Actions, etc.)
|
|
926
|
+
- Workflow stages and jobs
|
|
927
|
+
- Build and test commands
|
|
928
|
+
- Deployment triggers
|
|
929
|
+
- Environment handling
|
|
930
|
+
Document actual .github/workflows or equivalent.`,
|
|
931
|
+
'deployment/infrastructure.md': `Document infrastructure for this project:
|
|
932
|
+
- Hosting platform (Vercel, AWS, etc.)
|
|
933
|
+
- Database infrastructure
|
|
934
|
+
- CDN and caching
|
|
935
|
+
- Monitoring and logging
|
|
936
|
+
- Scaling considerations
|
|
937
|
+
Document actual setup or common patterns for the stack.`,
|
|
938
|
+
};
|
|
939
|
+
// Generate Claude-powered docs in parallel batches
|
|
940
|
+
const claudeDocPaths = Object.keys(claudePrompts);
|
|
941
|
+
const batchSize = 3; // Run 3 at a time to avoid overwhelming
|
|
942
|
+
const totalClaudeDocs = claudeDocPaths.length;
|
|
943
|
+
let completedDocs = 0;
|
|
944
|
+
const progress = options.onProgress || (() => { });
|
|
945
|
+
progress(`Generating ${totalClaudeDocs} AI-powered docs...`, 0, totalClaudeDocs);
|
|
946
|
+
for (let i = 0; i < claudeDocPaths.length; i += batchSize) {
|
|
947
|
+
const batch = claudeDocPaths.slice(i, i + batchSize);
|
|
948
|
+
// Show which docs are being generated
|
|
949
|
+
const docNames = batch.map(p => p.split('/').pop()?.replace('.md', '')).join(', ');
|
|
950
|
+
progress(`Analyzing: ${docNames}`, completedDocs, totalClaudeDocs);
|
|
951
|
+
const results = await Promise.all(batch.map(async (docPath) => {
|
|
952
|
+
const prompt = claudePrompts[docPath];
|
|
953
|
+
const content = await runClaudeForDocs(prompt, projectPath);
|
|
954
|
+
return { docPath, content };
|
|
955
|
+
}));
|
|
956
|
+
for (const { docPath, content } of results) {
|
|
957
|
+
completedDocs++;
|
|
958
|
+
const docName = docPath.split('/').pop()?.replace('.md', '') || docPath;
|
|
959
|
+
if (content) {
|
|
960
|
+
docs[docPath] = content;
|
|
961
|
+
progress(`Generated: ${docName}`, completedDocs, totalClaudeDocs);
|
|
962
|
+
}
|
|
963
|
+
else {
|
|
964
|
+
// Fallback to template if Claude fails
|
|
965
|
+
docs[docPath] = docs[docPath] || getFallbackTemplate(docPath);
|
|
966
|
+
progress(`Fallback: ${docName}`, completedDocs, totalClaudeDocs);
|
|
967
|
+
}
|
|
968
|
+
}
|
|
969
|
+
}
|
|
970
|
+
progress(`Completed ${totalClaudeDocs} documents`, totalClaudeDocs, totalClaudeDocs);
|
|
971
|
+
}
|
|
972
|
+
else {
|
|
973
|
+
// No Claude - use template fallbacks
|
|
974
|
+
docs['architecture/system-design.md'] = generateSystemDesign(answers, stack);
|
|
975
|
+
docs['architecture/data-flow.md'] = generateDataFlow(answers);
|
|
976
|
+
docs['architecture/components.md'] = generateComponentArchitecture(stack);
|
|
977
|
+
docs['api/index.md'] = generateApiIndex(stack);
|
|
978
|
+
docs['api/endpoints.md'] = generateEndpoints();
|
|
979
|
+
docs['api/schemas.md'] = generateSchemas(stack);
|
|
980
|
+
docs['api/authentication.md'] = '# Authentication\n\nAuthentication documentation to be added.\n';
|
|
981
|
+
docs['guides/contributing.md'] = '# Contributing\n\nContributing guide to be added.\n';
|
|
982
|
+
docs['reference/configuration.md'] = '# Configuration\n\nConfiguration documentation to be added.\n';
|
|
983
|
+
docs['reference/environment.md'] = '# Environment Variables\n\nEnvironment variable documentation to be added.\n';
|
|
984
|
+
docs['reference/dependencies.md'] = '# Dependencies\n\nDependency documentation to be added.\n';
|
|
985
|
+
docs['patterns/coding-standards.md'] = generateCodingStandards(answers, stack);
|
|
986
|
+
docs['patterns/naming-conventions.md'] = '# Naming Conventions\n\nNaming convention documentation to be added.\n';
|
|
987
|
+
docs['patterns/file-structure.md'] = '# File Structure\n\nFile structure documentation to be added.\n';
|
|
988
|
+
docs['testing/strategy.md'] = generateTestingStrategy(answers, stack);
|
|
989
|
+
docs['testing/unit-tests.md'] = '# Unit Testing\n\nUnit testing documentation to be added.\n';
|
|
990
|
+
docs['testing/integration-tests.md'] = '# Integration Testing\n\nIntegration testing documentation to be added.\n';
|
|
991
|
+
docs['testing/e2e-tests.md'] = '# E2E Testing\n\nE2E testing documentation to be added.\n';
|
|
992
|
+
docs['deployment/ci-cd.md'] = '# CI/CD Pipeline\n\nCI/CD documentation to be added.\n';
|
|
993
|
+
docs['deployment/infrastructure.md'] = '# Infrastructure\n\nInfrastructure documentation to be added.\n';
|
|
994
|
+
}
|
|
995
|
+
// Write all documents
|
|
996
|
+
for (const [relativePath, content] of Object.entries(docs)) {
|
|
997
|
+
const fullPath = join(docsPath, relativePath);
|
|
998
|
+
writeFileSync(fullPath, content);
|
|
999
|
+
// Determine category from path
|
|
1000
|
+
const category = relativePath.includes('/')
|
|
1001
|
+
? relativePath.split('/')[0]
|
|
1002
|
+
: 'general';
|
|
1003
|
+
generatedDocs.push({
|
|
1004
|
+
path: `docs/${relativePath}`,
|
|
1005
|
+
title: DOCS_STRUCTURE[relativePath] || relativePath,
|
|
1006
|
+
content,
|
|
1007
|
+
generated: true,
|
|
1008
|
+
category,
|
|
1009
|
+
});
|
|
1010
|
+
}
|
|
1011
|
+
// Add docs/ to .gitignore
|
|
1012
|
+
addToGitignore(projectPath, 'docs/');
|
|
1013
|
+
return generatedDocs;
|
|
1014
|
+
}
|
|
1015
|
+
function getFallbackTemplate(docPath) {
|
|
1016
|
+
const title = docPath.split('/').pop()?.replace('.md', '').replace(/-/g, ' ') || 'Documentation';
|
|
1017
|
+
const capitalizedTitle = title.charAt(0).toUpperCase() + title.slice(1);
|
|
1018
|
+
return `# ${capitalizedTitle}\n\nDocumentation to be added.\n`;
|
|
1019
|
+
}
|
|
1020
|
+
function addToGitignore(projectPath, entry) {
|
|
1021
|
+
const gitignorePath = join(projectPath, '.gitignore');
|
|
1022
|
+
try {
|
|
1023
|
+
if (existsSync(gitignorePath)) {
|
|
1024
|
+
const content = readFileSync(gitignorePath, 'utf-8');
|
|
1025
|
+
if (!content.includes(entry)) {
|
|
1026
|
+
appendFileSync(gitignorePath, `\n# ClaudeTools generated docs\n${entry}\n`);
|
|
1027
|
+
}
|
|
1028
|
+
}
|
|
1029
|
+
else {
|
|
1030
|
+
writeFileSync(gitignorePath, `# ClaudeTools generated docs\n${entry}\n`);
|
|
1031
|
+
}
|
|
1032
|
+
}
|
|
1033
|
+
catch {
|
|
1034
|
+
// Non-fatal
|
|
1035
|
+
}
|
|
1036
|
+
}
|
|
1037
|
+
//# sourceMappingURL=docs-builder.js.map
|