|
| 1 | +import { readFileSync, writeFileSync } from 'fs'; |
| 2 | +import { resolve } from 'path'; |
| 3 | + |
| 4 | +/** |
| 5 | + * Removes /api/eor prefix from generated OpenAPI client files |
| 6 | + * This is needed when generating from local OpenAPI spec that includes the prefix |
| 7 | + */ |
| 8 | +function cleanupApiEorPrefix() { |
| 9 | + const files = [ |
| 10 | + resolve(process.cwd(), 'src/client/sdk.gen.ts'), |
| 11 | + resolve(process.cwd(), 'src/client/types.gen.ts'), |
| 12 | + ]; |
| 13 | + |
| 14 | + let totalReplacements = 0; |
| 15 | + |
| 16 | + for (const filePath of files) { |
| 17 | + try { |
| 18 | + let content = readFileSync(filePath, 'utf-8'); |
| 19 | + const originalContent = content; |
| 20 | + |
| 21 | + // Replace /api/eor/ prefix with / (handles v1/, v2/, auth/, and any other paths) |
| 22 | + content = content.replace(/url: '\/api\/eor\//g, "url: '/"); |
| 23 | + |
| 24 | + if (content !== originalContent) { |
| 25 | + writeFileSync(filePath, content, 'utf-8'); |
| 26 | + const fileName = filePath.split('/').pop(); |
| 27 | + const replacements = (originalContent.match(/\/api\/eor\//g) || []) |
| 28 | + .length; |
| 29 | + console.log(`✓ Cleaned ${replacements} URLs in ${fileName}`); |
| 30 | + totalReplacements += replacements; |
| 31 | + } |
| 32 | + } catch (error) { |
| 33 | + console.error(`Error processing ${filePath}:`, error); |
| 34 | + process.exit(1); |
| 35 | + } |
| 36 | + } |
| 37 | + |
| 38 | + if (totalReplacements > 0) { |
| 39 | + console.log( |
| 40 | + `\n✓ Successfully removed /api/eor prefix from ${totalReplacements} URLs`, |
| 41 | + ); |
| 42 | + } else { |
| 43 | + console.log('\n✓ No /api/eor prefixes found'); |
| 44 | + } |
| 45 | +} |
| 46 | + |
| 47 | +cleanupApiEorPrefix(); |
0 commit comments