Skip to content

Commit 3867c41

Browse files
ericyangpanclaude
andcommitted
build: migrate generate-manifest-indexes script from .js to .mjs
Converts the manifest generation script to ES modules (.mjs) for consistency with other build scripts in the project. Changes: - Renames generate-manifest-indexes.js to .mjs - Updates package.json npm script to reference the .mjs file - Updates Cloudflare environment type definitions 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
1 parent 455464c commit 3867c41

File tree

3 files changed

+66
-9
lines changed

3 files changed

+66
-9
lines changed

cloudflare-env.d.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
/* eslint-disable */
2-
// Generated by Wrangler by running `wrangler types --env-interface CloudflareEnv ./cloudflare-env.d.ts` (hash: faf8a0423f869fe736da1a5ac5255eb6)
3-
// Runtime types generated with workerd@1.20250927.0 2025-03-01 global_fetch_strictly_public,nodejs_compat
2+
// Generated by Wrangler by running `wrangler types --env-interface CloudflareEnv ./cloudflare-env.d.ts` (hash: 508754d496fd9e0dd697301273fd295d)
3+
// Runtime types generated with workerd@1.20251001.0 2025-03-01 global_fetch_strictly_public,nodejs_compat
44
declare namespace Cloudflare {
5+
interface GlobalProps {
6+
mainModule: typeof import("./.open-next/worker");
7+
}
58
interface Env {
6-
NEXTJS_ENV: string;
79
ASSETS: Fetcher;
810
}
911
}

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
"spell:fix": "cspell '**/*.{ts,tsx,js,jsx,json,md,mdx}' --show-suggestions",
1212
"validate:manifests": "node scripts/validate-manifests.mjs",
1313
"validate:urls": "node scripts/validate-urls.mjs",
14-
"generate:manifests": "node scripts/generate-manifest-indexes.js",
14+
"generate:manifests": "node scripts/generate-manifest-indexes.mjs",
1515
"generate:metadata": "node scripts/generate-metadata.mjs",
1616
"fetch:github-stars": "node scripts/fetch-github-stars.mjs",
1717
"deploy": "npm run validate:manifests && npm run generate:manifests && npm run generate:metadata && BUILD_TIME=$(date -u +%Y-%m-%dT%H:%M:%SZ) opennextjs-cloudflare build && opennextjs-cloudflare deploy",
Lines changed: 60 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,15 @@
66
* This script automatically generates TypeScript index files for each manifest type.
77
* It scans the manifests directory and creates aggregated exports in src/lib/manifests/
88
*
9-
* Usage: node scripts/generate-manifest-indexes.js
9+
* Usage: node scripts/generate-manifest-indexes.mjs
1010
*/
1111

12-
const fs = require('fs');
13-
const path = require('path');
12+
import fs from 'fs';
13+
import path from 'path';
14+
import { fileURLToPath } from 'url';
15+
16+
const __filename = fileURLToPath(import.meta.url);
17+
const __dirname = path.dirname(__filename);
1418

1519
const MANIFESTS_DIR = path.join(__dirname, '../manifests');
1620
const OUTPUT_DIR = path.join(__dirname, '../src/lib/generated');
@@ -106,7 +110,7 @@ function generateIndexFile(typeName) {
106110

107111
const content = `/**
108112
* Auto-generated manifest index for ${typeName}
109-
* Generated by scripts/generate-manifest-indexes.js
113+
* Generated by scripts/generate-manifest-indexes.mjs
110114
* Do not edit manually - run the script to regenerate
111115
*/
112116
@@ -137,7 +141,7 @@ export type { ${toPascalCase(typeName.replace(/s$/, ''))} } from './${typeName}'
137141

138142
const content = `/**
139143
* Auto-generated main manifest index
140-
* Generated by scripts/generate-manifest-indexes.js
144+
* Generated by scripts/generate-manifest-indexes.mjs
141145
* Do not edit manually - run the script to regenerate
142146
*/
143147
@@ -149,6 +153,53 @@ ${exports}
149153
console.log(`✓ Generated index.ts`);
150154
}
151155

156+
/**
157+
* Generate GitHub stars TypeScript file from centralized JSON
158+
*/
159+
function generateGithubStarsFile() {
160+
const githubStarsPath = path.join(MANIFESTS_DIR, 'github-stars.json');
161+
162+
if (!fs.existsSync(githubStarsPath)) {
163+
console.log('⚠ github-stars.json not found, skipping stars generation');
164+
return;
165+
}
166+
167+
const starsData = JSON.parse(fs.readFileSync(githubStarsPath, 'utf8'));
168+
169+
const content = `/**
170+
* Auto-generated GitHub stars data
171+
* Generated by scripts/generate-manifest-indexes.mjs
172+
* Do not edit manually - run the script to regenerate
173+
*/
174+
175+
export type GithubStarsData = Record<string, Record<string, number | null>>;
176+
177+
export const githubStarsData: GithubStarsData = ${JSON.stringify(starsData, null, 2)};
178+
179+
/**
180+
* Get GitHub stars for a specific product
181+
* @param category - The product category (extensions, clis, ides)
182+
* @param id - The product ID
183+
* @returns The number of stars (in thousands) or null if not available
184+
*/
185+
export function getGithubStars(category: string, id: string): number | null {
186+
return githubStarsData[category]?.[id] ?? null;
187+
}
188+
189+
export default githubStarsData;
190+
`;
191+
192+
const outputPath = path.join(OUTPUT_DIR, 'github-stars.ts');
193+
fs.writeFileSync(outputPath, content, 'utf8');
194+
195+
// Count total entries
196+
const totalEntries = Object.values(starsData).reduce((sum, category) => {
197+
return sum + Object.keys(category).length;
198+
}, 0);
199+
200+
console.log(`✓ Generated github-stars.ts (${totalEntries} entries)`);
201+
}
202+
152203
/**
153204
* Main execution
154205
*/
@@ -171,6 +222,10 @@ function main() {
171222
console.log('');
172223
generateMainIndex();
173224

225+
// Generate GitHub stars file
226+
console.log('');
227+
generateGithubStarsFile();
228+
174229
console.log('\n' + '='.repeat(60));
175230
console.log('✅ All index files generated successfully!');
176231
console.log('='.repeat(60));

0 commit comments

Comments
 (0)