Skip to content

Commit f3d217e

Browse files
committed
Add AST-based validation scripts for API standardization, imports, and response envelopes
- Implemented `validate-api-standardization-ast.js` to validate API response standardization using TypeScript AST. - Created `validate-imports.js` to enforce custom import patterns and coding standards in the devlog monorepo. - Developed `validate-response-envelopes-ast.js` for validating response envelope formats in API routes and frontend files.
1 parent f38ed77 commit f3d217e

File tree

11 files changed

+308
-257
lines changed

11 files changed

+308
-257
lines changed

.husky/pre-commit

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,16 @@ echo "🔍 Running pre-commit validations..."
66
# Run lint-staged for efficient checking of staged files
77
npx lint-staged
88

9-
# Run custom import pattern validation (most important for catching issues)
9+
# Run custom import pattern validation
1010
echo "🔗 Validating import patterns..."
11-
node scripts/validate-imports.js
11+
node scripts/validation/validate-imports.js
1212

1313
# Run API response standardization validation (AST-based)
1414
echo "📡 Validating API response standardization..."
15-
node scripts/validate-api-standardization-ast.js
15+
node scripts/validation/validate-api-standardization-ast.js
1616

1717
# Run response envelope format validation (AST-based)
1818
echo "📦 Validating response envelope format..."
19-
node scripts/validate-response-envelopes-ast.js
19+
node scripts/validation/validate-response-envelopes-ast.js
2020

2121
echo "✅ Pre-commit checks passed!"

package.json

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,17 +15,15 @@
1515
"clean": "pnpm -r clean && rm -f *.tsbuildinfo",
1616
"dev:mcp": "concurrently --names \"AI,CORE,MCP\" --prefix-colors \"red,green,yellow\" \"pnpm --filter @codervisor/devlog-ai dev\" \"pnpm --filter @codervisor/devlog-core dev\" \"pnpm --filter @codervisor/devlog-mcp dev\"",
1717
"dev:web": "concurrently --names \"AI,CORE,WEB\" --prefix-colors \"red,green,blue\" \"pnpm --filter @codervisor/devlog-ai dev\" \"pnpm --filter @codervisor/devlog-core dev\" \"pnpm --filter @codervisor/devlog-web dev\"",
18-
"dev:web:check": "scripts/dev-with-check.sh pnpm dev:web",
1918
"start:web": "pnpm --filter @codervisor/devlog-web start",
2019
"preview:web": "pnpm --filter @codervisor/devlog-web preview",
2120
"format": "prettier --write packages/**/*.{ts,tsx,js,jsx,json,md}",
22-
"validate": "node scripts/validate-all.js",
23-
"validate:imports": "node scripts/validate-imports.js",
24-
"validate:api": "node scripts/validate-api-standardization-ast.js",
25-
"validate:envelopes": "node scripts/validate-response-envelopes-ast.js",
26-
"validate:quick": "node scripts/validate-all.js --no-build --no-types",
27-
"detect-migration": "node scripts/detect-migration.js",
28-
"pre-commit": "lint-staged && node scripts/validate-imports.js",
21+
"validate": "node scripts/validation/validate-all.js",
22+
"validate:imports": "node scripts/validation/validate-imports.js",
23+
"validate:api": "node scripts/validation/validate-api-standardization-ast.js",
24+
"validate:envelopes": "node scripts/validation/validate-response-envelopes-ast.js",
25+
"validate:quick": "node scripts/validation/validate-all.js --no-build --no-types",
26+
"pre-commit": "lint-staged && node scripts/validation/validate-imports.js",
2927
"prepare": "husky"
3028
},
3129
"keywords": [

scripts/README.md

Lines changed: 191 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,191 @@
1+
# Scripts Directory
2+
3+
This directory contains all development and maintenance scripts for the devlog project, organized into logical categories.
4+
5+
## 📁 Folder Structure
6+
7+
```
8+
scripts/
9+
├── run.js # Main script orchestrator
10+
├── validation/ # Code quality and standardization
11+
│ ├── validate-all.js # Comprehensive validation suite
12+
│ ├── validate-imports.js # Import pattern validation
13+
│ ├── validate-api-standardization-ast.js # API standardization (AST-based)
14+
│ └── validate-response-envelopes-ast.js # Response envelope validation (AST-based)
15+
└── database/ # Database management
16+
└── init-db.sql # Database initialization script
17+
```
18+
19+
## 🚀 Usage
20+
21+
### Using the Script Orchestrator
22+
23+
The `run.js` script provides a unified interface to all project scripts:
24+
25+
```bash
26+
# General syntax
27+
node scripts/run.js <category> <script> [options]
28+
29+
# Show help and available scripts
30+
node scripts/run.js --help
31+
```
32+
33+
### Validation Scripts
34+
35+
```bash
36+
# Run all validation checks
37+
node scripts/run.js validation all
38+
39+
# Run specific validations
40+
node scripts/run.js validation imports
41+
node scripts/run.js validation api
42+
node scripts/run.js validation envelopes
43+
44+
# Quick validation (skip build/type checks)
45+
node scripts/run.js validation all --no-build --no-types
46+
```
47+
48+
### Development Scripts
49+
50+
```bash
51+
# Check development server status
52+
node scripts/run.js development dev-check pnpm dev:web
53+
```
54+
55+
### Package.json Shortcuts
56+
57+
For convenience, common scripts are available via package.json:
58+
59+
```bash
60+
# Validation shortcuts
61+
pnpm validate # validation all
62+
pnpm validate:api # validation api
63+
pnpm validate:envelopes # validation envelopes
64+
pnpm validate:imports # validation imports
65+
pnpm validate:quick # validation all --no-build --no-types
66+
```
67+
68+
## 📋 Script Categories
69+
70+
### 🔍 Validation Scripts
71+
72+
**Purpose**: Enforce code quality and standardization rules
73+
74+
- **`validate-all.js`** - Comprehensive validation including imports, API patterns, build checks
75+
- **`validate-imports.js`** - ESM import pattern validation for TypeScript files
76+
- **`validate-api-standardization-ast.js`** - AST-based API endpoint and frontend pattern validation
77+
- **`validate-response-envelopes-ast.js`** - AST-based response envelope format validation
78+
79+
**Features**:
80+
- AST-based analysis for accuracy
81+
- Context-aware validation (API vs frontend code)
82+
- Husky pre-commit integration
83+
- Detailed error reporting with suggestions
84+
85+
### ️Database Scripts
86+
87+
**Purpose**: Database management and initialization
88+
89+
- **`init-db.sql`** - Database schema initialization
90+
91+
**Features**:
92+
- Schema setup
93+
- Initial data population
94+
95+
## 🔧 Adding New Scripts
96+
97+
### 1. Choose the Right Category
98+
99+
- **validation/** - Code quality, linting, standardization
100+
- **development/** - Dev workflow, build tools, utilities
101+
- **database/** - Schema, data management
102+
- **Create new category** if none fit
103+
104+
### 2. Add to Script Orchestrator
105+
106+
Update `scripts/run.js` to include your new script:
107+
108+
```javascript
109+
const SCRIPT_CATEGORIES = {
110+
// existing categories...
111+
newCategory: {
112+
description: 'Description of new category',
113+
scripts: {
114+
'script-name': 'script-file.js'
115+
}
116+
}
117+
};
118+
```
119+
120+
### 3. Update Package.json (Optional)
121+
122+
Add shortcuts to `package.json` for frequently used scripts:
123+
124+
```json
125+
{
126+
"scripts": {
127+
"script-name": "node scripts/run.js category script-name"
128+
}
129+
}
130+
```
131+
132+
### 4. Update Documentation
133+
134+
- Add script documentation to this README
135+
- Update relevant guides in `docs/guides/`
136+
- Include usage examples
137+
138+
## 🎯 Best Practices
139+
140+
### Script Development
141+
142+
1. **Use proper shebangs** - `#!/usr/bin/env node` for Node.js scripts
143+
2. **Make scripts executable** - `chmod +x script-name.js`
144+
3. **Handle errors gracefully** - Proper exit codes and error messages
145+
4. **Include help text** - `--help` option for complex scripts
146+
5. **Use consistent naming** - Clear, descriptive script names
147+
148+
### Error Handling
149+
150+
```javascript
151+
// Good error handling example
152+
try {
153+
// Script logic
154+
} catch (error) {
155+
console.error(`❌ Script failed: ${error.message}`);
156+
process.exit(1);
157+
}
158+
```
159+
160+
### Documentation
161+
162+
- Include header comments explaining script purpose
163+
- Document command line options
164+
- Provide usage examples
165+
- Maintain this README when adding scripts
166+
167+
## 🔄 Migration from Old Structure
168+
169+
**Before**: All scripts in `scripts/` root
170+
**After**: Organized into categorized folders
171+
172+
**Breaking Changes**: None - package.json scripts maintain backwards compatibility
173+
174+
**Deprecated Paths**: Direct script paths are deprecated but still work:
175+
- `scripts/validate-all.js``scripts/validation/validate-all.js`
176+
- Use `scripts/run.js` or package.json shortcuts instead
177+
178+
## 🧪 Testing Scripts
179+
180+
Test scripts in development:
181+
182+
```bash
183+
# Test validation
184+
node scripts/run.js validation all --no-build
185+
186+
# Test with specific options
187+
node scripts/run.js validation api --help
188+
189+
# Test package.json shortcuts
190+
pnpm validate:quick
191+
```

0 commit comments

Comments
 (0)