yf-fpm-server
Version:
yf fast-platform api server
55 lines (46 loc) • 1.38 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.execShell = exports.doCommand = undefined;
var _child_process = require('child_process');
var _fs = require('fs');
var _fs2 = _interopRequireDefault(_fs);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
const os = process.platform;
const OPTIONS = {
encoding: 'utf8',
timeout: 0,
maxBuffer: 200 * 1024,
killSignal: 'SIGTERM',
setsid: false,
cwd: null,
env: null
};
const doCommand = async (command, options = {}) => {
return new Promise((resolve, reject) => {
(0, _child_process.exec)(command, Object.assign(OPTIONS, options), (e, stdout, stderr) => {
if (e) {
reject({ data: stderr });
} else {
resolve({ data: stdout });
}
});
});
};
const execShell = async (shellPath, params, options = {}) => {
if (!_fs2.default.existsSync(shellPath)) {
return Promise.reject({ message: `shell script file not found ${shellPath}` });
}
return new Promise((resolve, reject) => {
(0, _child_process.execFile)(shellPath, params || [], Object.assign(OPTIONS, options), (e, stdout, stderr) => {
if (e) {
reject({ data: stderr });
} else {
resolve({ data: stdout });
}
});
});
};
exports.doCommand = doCommand;
exports.execShell = execShell;