You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
33 lines
532 B
33 lines
532 B
2 years ago
|
'use strict';
|
||
|
|
||
|
const Promise = require('bluebird');
|
||
|
|
||
|
class Deployer {
|
||
|
constructor() {
|
||
|
this.store = {};
|
||
|
}
|
||
|
|
||
|
list() {
|
||
|
return this.store;
|
||
|
}
|
||
|
|
||
|
get(name) {
|
||
|
return this.store[name];
|
||
|
}
|
||
|
|
||
|
register(name, fn) {
|
||
|
if (!name) throw new TypeError('name is required');
|
||
|
if (typeof fn !== 'function') throw new TypeError('fn must be a function');
|
||
|
|
||
|
if (fn.length > 1) {
|
||
|
fn = Promise.promisify(fn);
|
||
|
} else {
|
||
|
fn = Promise.method(fn);
|
||
|
}
|
||
|
|
||
|
this.store[name] = fn;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
module.exports = Deployer;
|