UNPKG

1.21 kBJavaScriptView Raw
1"use strict";exports.__esModule=!0;var tslib_1=require("tslib"),LarkLogger_1=require("@kemao/lark/Server/Log/LarkLogger/LarkLogger"),child_process_1=require("child_process"),Path=require("path"),logger=new LarkLogger_1.LarkLogger("ShellHelper"),ShellHelper=function(){function r(){}return r.exec=function(e,r){void 0===r&&(r=Path.resolve("./")),logger.log("start","cwd:",r,"cli:",e);try{var t=child_process_1.execSync(e,{cwd:r});return logger.log("output",t.toString()),t}catch(r){logger.error("stdout",r.stdout.toString()),logger.error("stderr",r.stderr.toString());var o=" 执行失败,请检查代码或命令:"+e+",stdout:"+r.stdout.toString()+",stderr:"+r.stderr.toString();throw new Error(o)}},r.spawn=function(o,i,l,n){return void 0===l&&(l=Path.resolve("./")),void 0===n&&(n=""),tslib_1.__awaiter(this,void 0,void 0,function(){return tslib_1.__generator(this,function(r){return[2,new Promise(function(e,t){var r=child_process_1.spawn(o,i,{cwd:l});r.stdout.on("data",function(r){logger.log(n+".stdout: "+r)}),r.stderr.on("data",function(r){logger.log(n+".stderr: "+r),t()}),r.on("close",function(r){logger.log(n+".child process exited with code "+r),e(r)})})]})})},r}();exports.ShellHelper=ShellHelper;
\No newline at end of file