mirror of
https://github.com/HarborGuard/HarborGuard.git
synced 2026-03-23 00:02:41 +08:00
- notifications.ts: update severity-utils import to lib/utils/ path - cleanup.ts: define MAX_BATCH_ITERATIONS locally in orphan cleanup method - repositories/route.ts: coalesce nullable Zod fields with ?? undefined - generate-openapi.ts: update import to lib/api/ path - Remove stale .next type cache for old /api/image/ routes
49 lines
1.4 KiB
TypeScript
49 lines
1.4 KiB
TypeScript
#!/usr/bin/env tsx
|
|
|
|
/**
|
|
* Generate a static OpenAPI specification at build time
|
|
*/
|
|
|
|
import fs from 'fs';
|
|
import path from 'path';
|
|
import { generateDynamicOpenApiSpec } from '../src/lib/api/openapi-dynamic';
|
|
|
|
async function generateStaticSpec() {
|
|
try {
|
|
console.log('[Build] Generating static OpenAPI specification...');
|
|
|
|
// Generate the spec
|
|
const spec = generateDynamicOpenApiSpec();
|
|
|
|
// Write to a JSON file that can be imported at runtime
|
|
const outputPath = path.join(process.cwd(), 'src', 'generated', 'openapi.json');
|
|
|
|
// Ensure the directory exists
|
|
const outputDir = path.dirname(outputPath);
|
|
if (!fs.existsSync(outputDir)) {
|
|
fs.mkdirSync(outputDir, { recursive: true });
|
|
}
|
|
|
|
// Write the spec
|
|
fs.writeFileSync(outputPath, JSON.stringify(spec, null, 2));
|
|
|
|
console.log(`[Build] OpenAPI spec generated successfully with ${Object.keys(spec.paths || {}).length} paths`);
|
|
console.log(`[Build] Written to: ${outputPath}`);
|
|
|
|
return true;
|
|
} catch (error) {
|
|
console.error('[Build] Failed to generate OpenAPI spec:', error);
|
|
// Don't fail the build, just warn
|
|
console.warn('[Build] Using fallback OpenAPI spec');
|
|
return false;
|
|
}
|
|
}
|
|
|
|
// Run if called directly
|
|
if (import.meta.url === `file://${process.argv[1]}`) {
|
|
generateStaticSpec().then(success => {
|
|
process.exit(success ? 0 : 1);
|
|
});
|
|
}
|
|
|
|
export { generateStaticSpec }; |