|
| 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