update.d.mts 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. import * as magicast from 'magicast';
  2. /**
  3. * @experimental Update a config file or create a new one.
  4. */
  5. declare function updateConfig(opts: UpdateConfigOptions): Promise<UpdateConfigResult>;
  6. interface UpdateConfigResult {
  7. configFile?: string;
  8. created?: boolean;
  9. }
  10. type MaybePromise<T> = T | Promise<T>;
  11. type MagicAstOptions = Exclude<Parameters<(typeof magicast)["parseModule"]>[1], undefined>;
  12. interface UpdateConfigOptions {
  13. /**
  14. * Current working directory
  15. */
  16. cwd: string;
  17. /**
  18. * Config file name
  19. */
  20. configFile: string;
  21. /**
  22. * Extension used for new config file.
  23. */
  24. createExtension?: string;
  25. /**
  26. * Magicast options
  27. */
  28. magicast?: MagicAstOptions;
  29. /**
  30. * Update function.
  31. */
  32. onUpdate?: (config: any) => MaybePromise<void>;
  33. /**
  34. * Handle default config creation.
  35. *
  36. * Tip: you can use this option as a hook to prompt users about config creation.
  37. *
  38. * Context object:
  39. * - path: determined full path to the config file
  40. *
  41. * Returns types:
  42. * - string: custom config template
  43. * - true: write the template
  44. * - false: abort the operation
  45. */
  46. onCreate?: (ctx: {
  47. configFile: string;
  48. }) => MaybePromise<string | boolean>;
  49. }
  50. export { updateConfig };
  51. export type { UpdateConfigOptions, UpdateConfigResult };