feature(cloudcmd) add plugins

This commit is contained in:
coderaiser 2016-11-28 18:21:13 +02:00
parent 39934033b8
commit 4d14071ede
8 changed files with 186 additions and 7 deletions

View file

@ -14,7 +14,9 @@ const {assign} = Object;
const pathConfig = os.homedir() + '/.cloudcmd.json';
const currentConfig = readjson.sync.try(pathConfig);
module.exports = (config, fn = config) => {
module.exports = (_config, _plugins, _fn) => {
const {config, plugins, fn} = parse(_config, _plugins, _fn);
const app = express();
const server = http.createServer(app);
const after = () => {
@ -28,6 +30,7 @@ module.exports = (config, fn = config) => {
app.use(cloudcmd({
socket,
plugins,
config: assign(defaultConfig(), config)
}));
@ -43,3 +46,25 @@ function defaultConfig() {
};
}
function parse(config, plugins, fn) {
if (typeof plugins === 'undefined')
return {
fn: config,
config: undefined,
plugins: undefined
}
if (typeof fn === 'undefined')
return {
config,
fn: plugins,
plugins: undefined
}
return {
config,
plugins,
fn
};
}