migrator.js 532 B

1234567891011121314151617181920212223242526272829303132
  1. 'use strict';
  2. const Promise = require('bluebird');
  3. class Migrator {
  4. constructor() {
  5. this.store = {};
  6. }
  7. list() {
  8. return this.store;
  9. }
  10. get(name) {
  11. return this.store[name];
  12. }
  13. register(name, fn) {
  14. if (!name) throw new TypeError('name is required');
  15. if (typeof fn !== 'function') throw new TypeError('fn must be a function');
  16. if (fn.length > 1) {
  17. fn = Promise.promisify(fn);
  18. } else {
  19. fn = Promise.method(fn);
  20. }
  21. this.store[name] = fn;
  22. }
  23. }
  24. module.exports = Migrator;