mirror of
https://github.com/coderaiser/cloudcmd.git
synced 2026-07-17 16:38:18 +00:00
34 lines
722 B
JavaScript
34 lines
722 B
JavaScript
import {createRequire} from 'node:module';
|
|
import {tryCatch} from 'try-catch';
|
|
|
|
const require = createRequire(import.meta.url);
|
|
|
|
const noop = (req, res, next) => {
|
|
next && next();
|
|
};
|
|
|
|
noop.listen = noop;
|
|
|
|
const _getModule = (a) => require(a);
|
|
|
|
export default (config, arg, overrides = {}) => {
|
|
const {
|
|
getModule = _getModule,
|
|
} = overrides;
|
|
|
|
if (!config('terminal'))
|
|
return noop;
|
|
|
|
const [e, terminalModule] = tryCatch(getModule, config('terminalPath'));
|
|
|
|
if (!e && !arg)
|
|
return terminalModule;
|
|
|
|
if (!e)
|
|
return terminalModule(arg);
|
|
|
|
config('terminal', false);
|
|
console.log(`cloudcmd --terminal: ${e.message}`);
|
|
|
|
return noop;
|
|
};
|