cli-command.ts 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. import { Project, SourceFile } from 'ts-morph';
  2. import { VendurePluginRef } from './vendure-plugin-ref';
  3. export type CommandCategory =
  4. | `Plugin`
  5. | `Plugin: UI`
  6. | `Plugin: Entity`
  7. | `Plugin: Service`
  8. | `Plugin: API`
  9. | `Plugin: Job Queue`
  10. | `Project: Codegen`
  11. | `Other`;
  12. export interface BaseCliCommandOptions {
  13. plugin?: VendurePluginRef;
  14. }
  15. export type CliCommandReturnVal<T extends Record<string, any> = Record<string, any>> = {
  16. project: Project;
  17. modifiedSourceFiles: SourceFile[];
  18. } & T;
  19. export interface CliCommandOptions<T extends BaseCliCommandOptions, R extends CliCommandReturnVal> {
  20. id: string;
  21. category: CommandCategory;
  22. description: string;
  23. run: (options?: Partial<T>) => Promise<R>;
  24. }
  25. export class CliCommand<T extends Record<string, any>, R extends CliCommandReturnVal = CliCommandReturnVal> {
  26. constructor(private options: CliCommandOptions<T, R>) {}
  27. get id() {
  28. return this.options.id;
  29. }
  30. get category() {
  31. return this.options.category;
  32. }
  33. get description() {
  34. return this.options.description;
  35. }
  36. run(options?: Partial<T>): Promise<R> {
  37. return this.options.run(options);
  38. }
  39. }