deployer.js 574 B

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