command-declarations.ts 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. import { CliCommandDefinition } from '../shared/cli-command-definition';
  2. export const cliCommands: CliCommandDefinition[] = [
  3. {
  4. name: 'add',
  5. description: 'Add a feature to your Vendure project',
  6. action: async () => {
  7. const { addCommand } = await import('./add/add');
  8. await addCommand();
  9. process.exit(0);
  10. },
  11. },
  12. {
  13. name: 'migrate',
  14. description: 'Generate, run or revert a database migration',
  15. action: async () => {
  16. const { migrateCommand } = await import('./migrate/migrate');
  17. await migrateCommand();
  18. process.exit(0);
  19. },
  20. },
  21. // Example of a command with options
  22. {
  23. name: 'example',
  24. description: 'Example command with options',
  25. options: [
  26. {
  27. flag: '-f, --file <path>',
  28. description: 'Path to the file',
  29. required: true,
  30. },
  31. {
  32. flag: '-v, --verbose',
  33. description: 'Enable verbose output',
  34. required: false,
  35. defaultValue: false,
  36. },
  37. ],
  38. action: async (options) => {
  39. // Example action implementation with options
  40. console.log('Example command executed');
  41. if (options) {
  42. // Validate required options
  43. if (!options.file) {
  44. console.error('Error: --file option is required');
  45. process.exit(1);
  46. }
  47. console.log('File path:', options.file);
  48. console.log('Verbose mode:', options.verbose);
  49. }
  50. process.exit(0);
  51. },
  52. },
  53. ];