Migrator.js 805 B

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. const Generator = require('./Generator')
  2. const MigratorAPI = require('./MigratorAPI')
  3. module.exports = class Migrator extends Generator {
  4. constructor (context, {
  5. plugin,
  6. pkg = {},
  7. afterInvokeCbs = [],
  8. files = {},
  9. invoking = false
  10. } = {}) {
  11. super(context, {
  12. pkg,
  13. plugins: [],
  14. afterInvokeCbs,
  15. files,
  16. invoking
  17. })
  18. this.migratorPlugin = plugin
  19. this.invoking = invoking
  20. }
  21. async generate (...args) {
  22. const plugin = this.migratorPlugin
  23. // apply migrators from plugins
  24. const api = new MigratorAPI(
  25. plugin.id,
  26. plugin.baseVersion,
  27. this,
  28. plugin.options,
  29. this.rootOptions
  30. )
  31. await plugin.apply(api, plugin.options, this.rootOptions, this.invoking)
  32. await super.generate(...args)
  33. }
  34. }