Skip to content

Commit 96105ff

Browse files
authored
Merge pull request #35 from cawpea/develop
Release: demo feature
2 parents 1d105a1 + d4ce158 commit 96105ff

27 files changed

Lines changed: 1836 additions & 0 deletions

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,3 +142,6 @@ dist
142142
# Vite logs files
143143
vite.config.js.timestamp-*
144144
vite.config.ts.timestamp-*
145+
146+
# Demo backup files
147+
demo/**/*.backup

CLAUDE.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,22 @@ npm run lint:fix # Auto-fix linting issues
3535
npm run format # Format code with Prettier
3636
npm run type-check # Run TypeScript compiler checks
3737
npm run docs:validate # Validate documentation updates
38+
npm run demo:validate # Test with demo environment
3839
```
3940

41+
### Demo Environment
42+
43+
The `demo/` directory provides a local testing environment:
44+
45+
```bash
46+
npm run demo:validate:valid # Validate correct CODE_REF usage
47+
npm run demo:validate:invalid # See error detection examples
48+
npm run demo:fix:dry # Preview auto-fix changes
49+
npm run demo:reset # Reset demo to original state
50+
```
51+
52+
See [demo/README.md](demo/README.md) for detailed usage.
53+
4054
### Commit Message Format
4155

4256
Follow [Conventional Commits](https://www.conventionalcommits.org/):

README.md

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,33 @@ This references lines 15-35 of the file. If the code changes, `coderef` will det
159159

160160
For more examples and usage patterns, see [docs/user-guide/](docs/user-guide/).
161161

162+
## Demo Environment
163+
164+
Try out `docs-coderef` with the included demo environment:
165+
166+
```bash
167+
# Clone the repository
168+
git clone https://github.com/cawpea/docs-coderef.git
169+
cd docs-coderef
170+
171+
# Install dependencies and build
172+
npm install
173+
npm run build
174+
175+
# Try the demo
176+
npm run demo:validate:valid # See valid CODE_REF examples
177+
npm run demo:validate:invalid # See error detection
178+
npm run demo:fix:dry # Preview auto-fix
179+
```
180+
181+
The `demo/` directory includes:
182+
183+
- Sample TypeScript files with various code patterns
184+
- Documentation with valid and invalid CODE_REF examples
185+
- Scripts for testing validation and fixing
186+
187+
See [demo/README.md](demo/README.md) for detailed instructions.
188+
162189
## Configuration
163190

164191
Create `.docs-coderefrc.json` in your project root:

demo/.docs-coderefrc.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"projectRoot": ".",
3+
"docsDir": "docs",
4+
"ignoreFile": ".gitignore",
5+
"verbose": true
6+
}

demo/README.md

Lines changed: 293 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,293 @@
1+
# docs-coderef Demo Environment
2+
3+
This directory contains a complete local testing environment for the `docs-coderef` tool. It demonstrates various CODE_REF patterns, both valid and intentionally invalid, to help you understand how the tool works.
4+
5+
## Prerequisites
6+
7+
- Node.js >= 22.0.0
8+
- The project must be built before running demos
9+
10+
## Quick Start
11+
12+
1. **Build the project**:
13+
14+
```bash
15+
npm run build
16+
```
17+
18+
2. **Validate the demo documentation**:
19+
20+
```bash
21+
npx docs-coderef validate demo/docs
22+
```
23+
24+
3. **Test the fix command**:
25+
```bash
26+
npx docs-coderef fix
27+
```
28+
29+
Or use the convenience scripts:
30+
31+
```bash
32+
# Quick validation
33+
npm run demo:validate
34+
35+
# Validate only valid examples
36+
npm run demo:validate:valid
37+
38+
# Validate only invalid examples (will show errors)
39+
npm run demo:validate:invalid
40+
41+
# Test fix in dry-run mode
42+
npm run demo:fix:dry
43+
44+
# Test fix in auto mode
45+
npm run demo:fix:auto
46+
```
47+
48+
## Directory Structure
49+
50+
```
51+
demo/
52+
├── README.md # This file
53+
├── .docs-coderefrc.json # Demo-specific configuration
54+
├── src/ # Sample source code files
55+
│ ├── basic/
56+
│ │ ├── functions.ts # Various function patterns
57+
│ │ ├── variables.ts # Constants and variables
58+
│ │ └── classes.ts # Class and method examples
59+
│ ├── advanced/
60+
│ │ ├── generics.ts # Generic functions/classes
61+
│ │ ├── destructuring.ts # Destructuring patterns
62+
│ │ └── async.ts # Async/await patterns
63+
│ └── edge-cases/
64+
│ ├── overloads.ts # Function overloads
65+
│ └── multiple-symbols.ts # Multiple symbols with same name
66+
├── docs/ # Sample markdown documentation
67+
│ ├── valid/
68+
│ │ ├── line-based.md # ✅ Valid line-based references
69+
│ │ ├── symbol-based.md # ✅ Valid symbol references
70+
│ │ ├── class-methods.md # ✅ Valid class method references
71+
│ │ └── variables.md # ✅ Valid variable references
72+
│ ├── invalid/
73+
│ │ ├── wrong-lines.md # ❌ Intentional line mismatch errors
74+
│ │ ├── missing-blocks.md # ❌ Missing code blocks
75+
│ │ ├── content-mismatch.md # ❌ Code content doesn't match
76+
│ │ └── symbol-errors.md # ❌ Symbol not found errors
77+
│ └── mixed/
78+
│ └── combined-patterns.md # 🔀 Mix of valid and invalid
79+
└── scripts/
80+
├── test-validate.sh # Run validation on demo
81+
├── test-fix.sh # Run fix on demo (with backup)
82+
└── reset-demo.sh # Reset demo to initial state
83+
```
84+
85+
## Demo Scenarios
86+
87+
### 1. Valid References (`docs/valid/`)
88+
89+
These files demonstrate correct usage of CODE_REF comments:
90+
91+
- **line-based.md**: Line number references like `<!-- CODE_REF: src/basic/functions.ts:7-13 -->`
92+
- **symbol-based.md**: Symbol references like `<!-- CODE_REF: src/basic/functions.ts#greet -->`
93+
- **class-methods.md**: Class method references like `<!-- CODE_REF: src/basic/classes.ts#User#getName -->`
94+
- **variables.md**: Variable references like `<!-- CODE_REF: src/basic/variables.ts#API_KEY -->`
95+
96+
Run validation:
97+
98+
```bash
99+
npx docs-coderef validate demo/docs/valid
100+
```
101+
102+
Expected result: ✅ All validations should pass
103+
104+
### 2. Invalid References (`docs/invalid/`)
105+
106+
These files contain intentional errors to demonstrate error detection:
107+
108+
- **wrong-lines.md**: `CODE_LOCATION_MISMATCH` - Code is correct but at different line numbers
109+
- **missing-blocks.md**: `CODE_BLOCK_MISSING` - CODE_REF without following code block
110+
- **content-mismatch.md**: `CODE_CONTENT_MISMATCH` - Code block doesn't match source
111+
- **symbol-errors.md**: `SYMBOL_NOT_FOUND` - References to non-existent symbols
112+
113+
Run validation:
114+
115+
```bash
116+
npx docs-coderef validate demo/docs/invalid
117+
```
118+
119+
Expected result: ❌ Multiple validation errors (this is intentional!)
120+
121+
### 3. Mixed Patterns (`docs/mixed/`)
122+
123+
- **combined-patterns.md**: A realistic documentation file with both valid and invalid references
124+
125+
Run validation:
126+
127+
```bash
128+
npx docs-coderef validate demo/docs/mixed/combined-patterns.md
129+
```
130+
131+
Expected result: ⚠️ Some errors, some successes
132+
133+
## Example Commands
134+
135+
### Validation
136+
137+
```bash
138+
# Validate all demo documentation
139+
npx docs-coderef validate demo/docs
140+
141+
# Validate specific file
142+
npx docs-coderef validate demo/docs/valid/symbol-based.md
143+
144+
# Validate specific directory
145+
npx docs-coderef validate demo/docs/valid
146+
147+
# Validate with verbose output
148+
npx docs-coderef validate demo/docs --verbose
149+
150+
# Change working directory to demo first
151+
cd demo
152+
npx docs-coderef validate docs
153+
```
154+
155+
### Fix
156+
157+
```bash
158+
# Interactive fix with preview (recommended)
159+
npx docs-coderef fix
160+
161+
# Dry-run mode (preview without making changes)
162+
npx docs-coderef fix --dry-run
163+
164+
# Auto-fix all errors without prompting
165+
npx docs-coderef fix --auto
166+
167+
# Create backups before fixing
168+
npx docs-coderef fix --backup
169+
```
170+
171+
### Using Shell Scripts
172+
173+
```bash
174+
# From project root:
175+
./demo/scripts/test-validate.sh # Build and validate
176+
./demo/scripts/test-fix.sh # Build and run fix
177+
./demo/scripts/reset-demo.sh # Reset demo to original state
178+
```
179+
180+
## CODE_REF Pattern Reference
181+
182+
### Line-Based References
183+
184+
```markdown
185+
<!-- CODE_REF: src/basic/functions.ts:7-13 -->
186+
```
187+
188+
References specific line numbers in a file.
189+
190+
### Symbol References
191+
192+
```markdown
193+
<!-- CODE_REF: src/basic/functions.ts#greet -->
194+
```
195+
196+
References a function, class, or variable by name.
197+
198+
### Class Method References
199+
200+
```markdown
201+
<!-- CODE_REF: src/basic/classes.ts#User#getName -->
202+
```
203+
204+
References a method within a class: `ClassName#methodName`
205+
206+
### Symbol with Line Hint
207+
208+
```markdown
209+
<!-- CODE_REF: src/edge-cases/multiple-symbols.ts#DataProcessor#process:10-15 -->
210+
```
211+
212+
Useful when multiple symbols have the same name.
213+
214+
## Expected Validation Output
215+
216+
### Valid Files
217+
218+
When validating `demo/docs/valid/`, you should see:
219+
220+
```
221+
✓ demo/docs/valid/line-based.md - All 5 CODE_REF references are valid
222+
✓ demo/docs/valid/symbol-based.md - All 5 CODE_REF references are valid
223+
✓ demo/docs/valid/class-methods.md - All 5 CODE_REF references are valid
224+
✓ demo/docs/valid/variables.md - All 8 CODE_REF references are valid
225+
```
226+
227+
### Invalid Files
228+
229+
When validating `demo/docs/invalid/`, you should see errors like:
230+
231+
```
232+
✗ demo/docs/invalid/wrong-lines.md
233+
- CODE_LOCATION_MISMATCH: Code matches but at different lines
234+
235+
✗ demo/docs/invalid/missing-blocks.md
236+
- CODE_BLOCK_MISSING: No code block found after CODE_REF
237+
238+
✗ demo/docs/invalid/content-mismatch.md
239+
- CODE_CONTENT_MISMATCH: Code block content differs from source
240+
241+
✗ demo/docs/invalid/symbol-errors.md
242+
- SYMBOL_NOT_FOUND: Symbol does not exist in file
243+
```
244+
245+
## Resetting the Demo
246+
247+
After running `fix --auto`, the demo files will be modified. To restore them to their original state:
248+
249+
```bash
250+
# Using the script (recommended)
251+
./demo/scripts/reset-demo.sh
252+
253+
# Or manually
254+
git checkout demo/docs/
255+
```
256+
257+
## Exploring the Demo
258+
259+
1. **Start with valid examples**: Check `docs/valid/` to see correct CODE_REF usage
260+
2. **Examine source files**: Look at the TypeScript files in `src/` to understand what's being referenced
261+
3. **Try validation**: Run validation on different directories to see the output
262+
4. **Test error detection**: Validate `docs/invalid/` to see how errors are reported
263+
5. **Experiment with fix**: Run `fix --dry-run` to see what changes would be made
264+
6. **Try real fixes**: Run `fix` on invalid files and observe the interactive prompts
265+
7. **Reset and repeat**: Use `reset-demo.sh` to start fresh
266+
267+
## Troubleshooting
268+
269+
### "Command not found: docs-coderef"
270+
271+
- Make sure you've run `npm run build` first
272+
- The tool must be built before it can be used
273+
274+
### "File not found" errors
275+
276+
- Check that you're running commands from the project root
277+
- Paths in CODE_REF should be relative to demo directory
278+
279+
### "Symbol not found" errors
280+
281+
- Verify the symbol name matches exactly (case-sensitive)
282+
- Check that you're referencing a TypeScript/JavaScript file
283+
- Make sure the symbol is exported
284+
285+
### Validation succeeds but should fail
286+
287+
- Check that CODE_REF paths are correct
288+
- Verify code blocks match source exactly (including whitespace)
289+
- Ensure JSDoc comments are included if present in source
290+
291+
---
292+
293+
Happy testing! 🚀

0 commit comments

Comments
 (0)