()
| 154 | } |
| 155 | |
| 156 | async function main() { |
| 157 | const args = process.argv.slice(2); |
| 158 | const usePlaceholder = args.includes('--placeholder'); |
| 159 | const sanitizeOnly = args.includes('--sanitize'); |
| 160 | const localIdx = args.indexOf('--local'); |
| 161 | const localPort = localIdx !== -1 ? args[localIdx + 1] || '8787' : null; |
| 162 | |
| 163 | mkdirSync(specsDir, { recursive: true }); |
| 164 | |
| 165 | if (sanitizeOnly) { |
| 166 | console.log('Sanitizing existing specs in place...'); |
| 167 | for (const endpoint of PRODUCTION_ENDPOINTS) { |
| 168 | const path = join(specsDir, endpoint.name); |
| 169 | try { |
| 170 | const spec = JSON.parse(readFileSync(path, 'utf8')); |
| 171 | writeSpec(path, spec); |
| 172 | console.log(` ✓ ${endpoint.name}`); |
| 173 | } catch (err) { |
| 174 | console.log(` ✗ ${endpoint.name}: ${err.message}`); |
| 175 | } |
| 176 | } |
| 177 | return; |
| 178 | } |
| 179 | |
| 180 | if (usePlaceholder) { |
| 181 | console.log('Writing placeholder specs...'); |
| 182 | const placeholders = [ |
| 183 | { name: 'fxtwitter-openapi.json', title: 'FxTwitter API', desc: 'FxTwitter API v2' }, |
| 184 | { name: 'fxbluesky-openapi.json', title: 'FxBluesky API', desc: 'FxBluesky API v2' } |
| 185 | ]; |
| 186 | for (const p of placeholders) { |
| 187 | const path = join(specsDir, p.name); |
| 188 | writeSpec(path, makePlaceholder(p.title, p.desc)); |
| 189 | console.log(` → ${path}`); |
| 190 | } |
| 191 | return; |
| 192 | } |
| 193 | |
| 194 | for (const endpoint of PRODUCTION_ENDPOINTS) { |
| 195 | const label = localPort |
| 196 | ? `http://127.0.0.1:${localPort}/2/openapi.json (Host: ${endpoint.localHostHeader})` |
| 197 | : endpoint.url; |
| 198 | process.stdout.write(`Fetching ${endpoint.name} from ${label}...`); |
| 199 | try { |
| 200 | const spec = await fetchSpec(endpoint, localPort); |
| 201 | const path = join(specsDir, endpoint.name); |
| 202 | writeSpec(path, spec); |
| 203 | console.log(` ✓`); |
| 204 | } catch (err) { |
| 205 | console.log(` ✗ ${err.message}`); |
| 206 | console.log(` → Writing placeholder for ${endpoint.name}`); |
| 207 | const path = join(specsDir, endpoint.name); |
| 208 | writeSpec(path, makePlaceholder(endpoint.name.replace(/-openapi\.json$/, ''), '')); |
| 209 | } |
| 210 | } |
| 211 | } |
| 212 | |
| 213 | main().catch(err => { |
no test coverage detected