Skip to content

Commit 3705d3d

Browse files
ericyangpanclaude
andcommitted
refactor(scripts): reorganize scripts into modular structure
- Restructure scripts into feature-based directories (fetch/, generate/, validate/, refactor/, _shared/) - Replace monolithic script files with modular architecture - Update package.json scripts to use new structure with grouped commands - Add scripts/README.md documentation - Remove deprecated scripts: fetch-github-stars.mjs, generate-manifest-indexes.mjs, generate-metadata.mjs, sort-manifest-fields.mjs, validate-manifests.mjs, validate-urls.mjs - Add new script entry points: fetch/index.mjs, generate/index.mjs, validate/index.mjs, refactor/index.mjs 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
1 parent fe49441 commit 3705d3d

File tree

14 files changed

+743
-19
lines changed

14 files changed

+743
-19
lines changed

package.json

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
"version": "1.0.0",
44
"description": "AI Coding Stack Website",
55
"scripts": {
6-
"dev": "npm run generate:manifests && npm run generate:metadata && next dev",
7-
"build:next": "npm run validate:manifests && npm run generate:manifests && npm run generate:metadata && BUILD_TIME=$(date -u +%Y-%m-%dT%H:%M:%SZ) next build",
6+
"dev": "npm run validate && npm run generate && next dev",
7+
"build:next": "npm run validate && npm run generate && BUILD_TIME=$(date -u +%Y-%m-%dT%H:%M:%SZ) next build",
88
"build": "npm run build:next && opennextjs-cloudflare build --skipBuild",
99
"start": "next start",
1010
"format": "biome format --write .",
@@ -15,11 +15,17 @@
1515
"check": "biome check . && npm run spell",
1616
"spell": "cspell '**/*.{ts,tsx,js,jsx,json,md,mdx}'",
1717
"spell:fix": "cspell '**/*.{ts,tsx,js,jsx,json,md,mdx}' --show-suggestions",
18-
"validate:manifests": "node scripts/validate-manifests.mjs",
19-
"validate:urls": "node scripts/validate-urls.mjs",
20-
"generate:manifests": "node scripts/generate-manifest-indexes.mjs",
21-
"generate:metadata": "node scripts/generate-metadata.mjs",
22-
"fetch:github-stars": "node scripts/fetch-github-stars.mjs",
18+
"validate": "node scripts/validate/index.mjs",
19+
"validate:manifests": "node scripts/validate/index.mjs manifests",
20+
"validate:github-stars": "node scripts/validate/index.mjs github-stars",
21+
"validate:urls": "node scripts/validate/index.mjs urls",
22+
"generate": "node scripts/generate/index.mjs",
23+
"generate:manifests": "node scripts/generate/index.mjs manifest-indexes",
24+
"generate:metadata": "node scripts/generate/index.mjs metadata",
25+
"refactor": "node scripts/refactor/index.mjs",
26+
"refactor:sort-fields": "node scripts/refactor/index.mjs sort-manifest-fields",
27+
"fetch": "node scripts/fetch/index.mjs",
28+
"fetch:github-stars": "node scripts/fetch/index.mjs github-stars",
2329
"deploy": "npm run build:next && opennextjs-cloudflare build --skipBuild && opennextjs-cloudflare deploy",
2430
"preview": "npm run build:next && opennextjs-cloudflare build --skipBuild && opennextjs-cloudflare preview",
2531
"cf-typegen": "wrangler types --env-interface CloudflareEnv ./cloudflare-env.d.ts",
@@ -30,7 +36,6 @@
3036
"@mdx-js/react": "^3.1.1",
3137
"@next/third-parties": "^15.5.4",
3238
"@opennextjs/cloudflare": "^1.13.1",
33-
"@xyflow/react": "^12.9.3",
3439
"lucide-react": "^0.554.0",
3540
"next": "^15.5.6",
3641
"next-intl": "^4.5.5",

scripts/README.md

Lines changed: 287 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,287 @@
1+
# Scripts Documentation
2+
3+
This directory contains utility scripts for managing and validating the AI Coding Stack project. Scripts are organized into four categories:
4+
5+
- **`validate/`** - Validation scripts that check data integrity
6+
- **`generate/`** - Generation scripts that create derived files
7+
- **`refactor/`** - Refactoring scripts that reorganize or reformat data
8+
- **`fetch/`** - Data fetching scripts that retrieve external data
9+
10+
## Directory Structure
11+
12+
```
13+
scripts/
14+
├── validate/
15+
│ ├── index.mjs # Entry point for all validation scripts
16+
│ ├── validate-manifests.mjs
17+
│ ├── validate-github-stars.mjs
18+
│ └── validate-urls.mjs
19+
├── generate/
20+
│ ├── index.mjs # Entry point for all generation scripts
21+
│ ├── generate-manifest-indexes.mjs
22+
│ └── generate-metadata.mjs
23+
├── refactor/
24+
│ ├── index.mjs # Entry point for all refactoring scripts
25+
│ └── sort-manifest-fields.mjs
26+
└── fetch/
27+
├── index.mjs # Entry point for all fetch scripts
28+
└── fetch-github-stars.mjs
29+
```
30+
31+
## Usage
32+
33+
### Running All Scripts in a Category
34+
35+
Each category has an entry point script (`index.mjs`) that can run all scripts in that category:
36+
37+
```bash
38+
# Run all validation scripts
39+
npm run validate
40+
41+
# Run all generation scripts
42+
npm run generate
43+
44+
# Run all refactoring scripts
45+
npm run refactor
46+
47+
# Run all fetch scripts
48+
npm run fetch
49+
```
50+
51+
### Running Individual Scripts
52+
53+
You can also run individual scripts by passing the script name to the entry point:
54+
55+
```bash
56+
# Validation scripts
57+
npm run validate:manifests
58+
npm run validate:github-stars
59+
npm run validate:urls
60+
61+
# Generation scripts
62+
npm run generate:manifests
63+
npm run generate:metadata
64+
65+
# Refactoring scripts
66+
npm run refactor:sort-fields
67+
68+
# Fetch scripts
69+
npm run fetch:github-stars
70+
```
71+
72+
Or directly using Node:
73+
74+
```bash
75+
# Run specific script
76+
node scripts/validate/index.mjs manifests
77+
node scripts/generate/index.mjs metadata
78+
node scripts/fetch/index.mjs github-stars
79+
```
80+
81+
## Validation Scripts
82+
83+
### validate-manifests.mjs
84+
85+
Validates all manifest JSON files against their corresponding JSON schemas.
86+
87+
```bash
88+
npm run validate:manifests
89+
```
90+
91+
**What it checks:**
92+
- JSON syntax validity
93+
- Schema compliance for each manifest type
94+
- Required fields presence
95+
- Field format validation (URLs, enums, etc.)
96+
- Filename matches the `id` field in the manifest
97+
98+
**Manifest types validated:**
99+
- `manifests/clis/*.json` - CLI tools
100+
- `manifests/ides/*.json` - IDEs
101+
- `manifests/extensions/*.json` - Editor extensions
102+
- `manifests/providers/*.json` - API providers
103+
- `manifests/models/*.json` - LLM models
104+
- `manifests/vendors/*.json` - Vendor information
105+
- `manifests/collections.json` - Collections data
106+
107+
### validate-github-stars.mjs
108+
109+
Validates that entries in `data/github-stars.json` match the actual manifest files.
110+
111+
```bash
112+
npm run validate:github-stars
113+
```
114+
115+
**What it checks:**
116+
- All entries in `github-stars.json` have corresponding manifest files
117+
- All manifest files are present in `github-stars.json`
118+
- No orphaned entries in either direction
119+
120+
**Categories validated:**
121+
- `extensions`
122+
- `clis`
123+
- `ides`
124+
125+
**Common issues:**
126+
- Orphaned entries: Entries in `github-stars.json` without manifest files
127+
- Missing entries: Manifest files without corresponding `github-stars.json` entries
128+
129+
**How to fix:**
130+
1. Remove orphaned entries from `data/github-stars.json`
131+
2. Add missing entries to `data/github-stars.json` (set value to `null` if unknown)
132+
3. Or remove unused manifest files if they are not needed
133+
134+
### validate-urls.mjs
135+
136+
Validates URLs in manifest files to ensure they are accessible.
137+
138+
```bash
139+
npm run validate:urls
140+
```
141+
142+
**What it checks:**
143+
- URL accessibility (HTTP status codes)
144+
- Network connectivity
145+
- URL format validity
146+
147+
**Note:** This script may take a while as it makes HTTP requests to validate each URL.
148+
149+
## Generation Scripts
150+
151+
### generate-manifest-indexes.mjs
152+
153+
Generates TypeScript index files from individual manifest files.
154+
155+
```bash
156+
npm run generate:manifests
157+
```
158+
159+
**What it generates:**
160+
- `src/lib/generated/ides.ts` - IDE manifest index
161+
- `src/lib/generated/clis.ts` - CLI manifest index
162+
- `src/lib/generated/models.ts` - Model manifest index
163+
- `src/lib/generated/providers.ts` - Provider manifest index
164+
- `src/lib/generated/extensions.ts` - Extension manifest index
165+
- `src/lib/generated/vendors.ts` - Vendor manifest index
166+
- `src/lib/generated/index.ts` - Main manifest index
167+
- `src/lib/generated/github-stars.ts` - GitHub stars data
168+
169+
### generate-metadata.mjs
170+
171+
Generates TypeScript metadata files from MDX content and manifest data.
172+
173+
```bash
174+
npm run generate:metadata
175+
```
176+
177+
**What it generates:**
178+
- `src/lib/generated/metadata.ts` - Articles, docs, FAQ, and collections metadata
179+
- `src/lib/generated/articles.ts` - Article components and metadata
180+
- `src/lib/generated/docs.ts` - Doc components and metadata
181+
- `src/lib/generated/manifesto.ts` - Manifesto component loader
182+
183+
## Refactoring Scripts
184+
185+
### sort-manifest-fields.mjs
186+
187+
Sorts fields in manifest JSON files according to their schema definitions.
188+
189+
```bash
190+
npm run refactor:sort-fields
191+
```
192+
193+
**What it does:**
194+
- Reorders fields in manifest files to match schema property order
195+
- Ensures consistent field ordering across all manifests
196+
- Handles nested objects and arrays
197+
198+
## Data Fetching Scripts
199+
200+
### fetch-github-stars.mjs
201+
202+
Fetches GitHub star counts for projects listed in manifests.
203+
204+
```bash
205+
npm run fetch:github-stars
206+
```
207+
208+
**What it does:**
209+
- Reads `githubUrl` from manifest files
210+
- Fetches star counts from GitHub API
211+
- Updates `data/github-stars.json` with latest counts
212+
213+
**Environment variables:**
214+
- `GITHUB_TOKEN` - Optional GitHub token to avoid rate limits (recommended)
215+
216+
**Note:** Without a GitHub token, you may hit rate limits (60 requests/hour).
217+
218+
## Build Process
219+
220+
The build process runs validation and generation scripts automatically:
221+
222+
```bash
223+
npm run build:next
224+
```
225+
226+
This runs in order:
227+
1. `validate:manifests` - Validate all manifest schemas
228+
2. `validate:github-stars` - Validate github-stars.json consistency
229+
3. `generate:manifests` - Generate manifest indexes
230+
4. `generate:metadata` - Generate TypeScript metadata
231+
5. Next.js build
232+
233+
## Development Workflow
234+
235+
During development, use:
236+
237+
```bash
238+
npm run dev
239+
```
240+
241+
This will:
242+
1. Generate manifest indexes
243+
2. Generate metadata
244+
3. Start Next.js development server
245+
246+
## CI/CD Integration
247+
248+
For CI/CD pipelines, you can use the entry point scripts to run all scripts in a category:
249+
250+
```bash
251+
# Run all validations (recommended for CI)
252+
npm run validate
253+
254+
# Run all generation scripts
255+
npm run generate
256+
257+
# Run all refactoring scripts
258+
npm run refactor
259+
260+
# Run all fetch scripts (if needed)
261+
npm run fetch
262+
```
263+
264+
Or run individual scripts as needed:
265+
266+
```bash
267+
npm run validate:manifests
268+
npm run generate:manifests
269+
npm run generate:metadata
270+
npm run refactor:sort-fields
271+
```
272+
273+
## Manual Execution
274+
275+
To run scripts manually without npm:
276+
277+
```bash
278+
# Run all scripts in a category
279+
node scripts/validate/index.mjs
280+
node scripts/generate/index.mjs
281+
node scripts/fetch/index.mjs
282+
283+
# Run specific script
284+
node scripts/validate/index.mjs manifests
285+
node scripts/generate/index.mjs metadata
286+
node scripts/fetch/index.mjs github-stars
287+
```

0 commit comments

Comments
 (0)