cloudflare/cloudflare-typescript
Publicmirrored fromhttps://github.com/cloudflare/cloudflare-typescriptAvailable
bin/cli
52lines · modecode
| 1 | #!/usr/bin/env node |
| 2 | |
| 3 | const { spawnSync } = require('child_process'); |
| 4 | |
| 5 | const commands = { |
| 6 | migrate: { |
| 7 | description: 'Run migrations to update to the latest major SDK version', |
| 8 | fn: () => { |
| 9 | const result = spawnSync( |
| 10 | 'npx', |
| 11 | [ |
| 12 | '-y', |
| 13 | 'https://github.com/stainless-api/migrate-ts/releases/download/0.0.2/stainless-api-migrate-0.0.2-6.tgz', |
| 14 | '--migrationConfig', |
| 15 | require.resolve('./migration-config.json'), |
| 16 | ...process.argv.slice(3), |
| 17 | ], |
| 18 | { stdio: 'inherit' }, |
| 19 | ); |
| 20 | if (result.status !== 0) { |
| 21 | process.exit(result.status); |
| 22 | } |
| 23 | }, |
| 24 | }, |
| 25 | }; |
| 26 | |
| 27 | function exitWithHelp() { |
| 28 | console.log(`Usage: cloudflare <subcommand>`); |
| 29 | console.log(); |
| 30 | console.log('Subcommands:'); |
| 31 | |
| 32 | for (const [name, info] of Object.entries(commands)) { |
| 33 | console.log(` ${name} ${info.description}`); |
| 34 | } |
| 35 | |
| 36 | console.log(); |
| 37 | process.exit(1); |
| 38 | } |
| 39 | |
| 40 | if (process.argv.length < 3) { |
| 41 | exitWithHelp(); |
| 42 | } |
| 43 | |
| 44 | const commandName = process.argv[2]; |
| 45 | |
| 46 | const command = commands[commandName]; |
| 47 | if (!command) { |
| 48 | console.log(`Unknown subcommand ${commandName}.`); |
| 49 | exitWithHelp(); |
| 50 | } |
| 51 | |
| 52 | command.fn(); |
| 53 | |