cli 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. #!/usr/bin/env node
  2. const { spawnSync } = require('child_process');
  3. const commands = {
  4. migrate: {
  5. description: 'Run migrations to update from openai v3 to v4',
  6. fn: () => {
  7. console.log('This automatic code migration is provided by grit.io');
  8. console.log('Visit https://app.grit.io/studio?preset=openai_v4 for more details.')
  9. const result = spawnSync(
  10. 'npx',
  11. ['-y', '@getgrit/launcher', 'apply', 'openai_v4', ...process.argv.slice(3)],
  12. { stdio: 'inherit' },
  13. );
  14. if (result.status !== 0) {
  15. process.exit(result.status);
  16. }
  17. }
  18. }
  19. }
  20. function exitWithHelp() {
  21. console.log("Usage: $0 <subcommand>");
  22. console.log();
  23. console.log('Subcommands:');
  24. for (const [name, info] of Object.entries(commands)) {
  25. console.log(` ${name} ${info.description}`);
  26. }
  27. console.log();
  28. process.exit(1);
  29. }
  30. if (process.argv.length < 3) {
  31. exitWithHelp();
  32. }
  33. const commandName = process.argv[2];
  34. const command = commands[commandName];
  35. if (!command) {
  36. console.log(`Unknown subcommand ${commandName}.`);
  37. exitWithHelp();
  38. }
  39. command.fn();