UNPKG

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