mirror of
https://github.com/coderaiser/cloudcmd.git
synced 2026-07-18 00:47:01 +00:00
chore: lint
This commit is contained in:
parent
f1279666b5
commit
4717e035ee
173 changed files with 1388 additions and 1627 deletions
|
|
@ -1,7 +1,6 @@
|
|||
'use strict';
|
||||
|
||||
/* global CloudCmd */
|
||||
|
||||
const exec = require('execon');
|
||||
const tryToCatch = require('try-to-catch');
|
||||
const loadJS = require('load.js').js;
|
||||
|
|
@ -16,45 +15,44 @@ const noJS = (a) => a.replace(/.js$/, '');
|
|||
module.exports = function loadModule(params) {
|
||||
if (!params)
|
||||
return;
|
||||
|
||||
|
||||
const {path} = params;
|
||||
|
||||
|
||||
const name = path && noJS(pascalCase(path));
|
||||
const doBefore = params.dobefore;
|
||||
|
||||
|
||||
if (CloudCmd[name])
|
||||
return;
|
||||
|
||||
|
||||
CloudCmd[name] = async () => {
|
||||
exec(doBefore);
|
||||
|
||||
|
||||
const {DIR_MODULES} = CloudCmd;
|
||||
const pathFull = `${DIR_MODULES}/${path}.js`;
|
||||
|
||||
|
||||
await loadJS(pathFull);
|
||||
const newModule = async (f) => f && f();
|
||||
const module = CloudCmd[name];
|
||||
|
||||
|
||||
Object.assign(newModule, module);
|
||||
|
||||
|
||||
CloudCmd[name] = newModule;
|
||||
CloudCmd.log('init', name);
|
||||
|
||||
|
||||
await module.init();
|
||||
|
||||
|
||||
return newModule;
|
||||
};
|
||||
|
||||
|
||||
CloudCmd[name].show = async (...args) => {
|
||||
CloudCmd.log('show', name, args);
|
||||
const m = CloudCmd[name];
|
||||
|
||||
|
||||
const [e, a] = await tryToCatch(m);
|
||||
|
||||
|
||||
if (e)
|
||||
return console.error(e);
|
||||
|
||||
|
||||
return await a.show(...args);
|
||||
};
|
||||
};
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue