github.com/jfrog/frogbot@v1.1.1-0.20231221090046-821a26f50338/action/node_modules/@actions/exec/lib/exec.js (about) 1 "use strict"; 2 var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { 3 if (k2 === undefined) k2 = k; 4 Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } }); 5 }) : (function(o, m, k, k2) { 6 if (k2 === undefined) k2 = k; 7 o[k2] = m[k]; 8 })); 9 var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { 10 Object.defineProperty(o, "default", { enumerable: true, value: v }); 11 }) : function(o, v) { 12 o["default"] = v; 13 }); 14 var __importStar = (this && this.__importStar) || function (mod) { 15 if (mod && mod.__esModule) return mod; 16 var result = {}; 17 if (mod != null) for (var k in mod) if (k !== "default" && Object.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); 18 __setModuleDefault(result, mod); 19 return result; 20 }; 21 var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { 22 function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } 23 return new (P || (P = Promise))(function (resolve, reject) { 24 function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } 25 function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } 26 function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } 27 step((generator = generator.apply(thisArg, _arguments || [])).next()); 28 }); 29 }; 30 Object.defineProperty(exports, "__esModule", { value: true }); 31 exports.getExecOutput = exports.exec = void 0; 32 const string_decoder_1 = require("string_decoder"); 33 const tr = __importStar(require("./toolrunner")); 34 /** 35 * Exec a command. 36 * Output will be streamed to the live console. 37 * Returns promise with return code 38 * 39 * @param commandLine command to execute (can include additional args). Must be correctly escaped. 40 * @param args optional arguments for tool. Escaping is handled by the lib. 41 * @param options optional exec options. See ExecOptions 42 * @returns Promise<number> exit code 43 */ 44 function exec(commandLine, args, options) { 45 return __awaiter(this, void 0, void 0, function* () { 46 const commandArgs = tr.argStringToArray(commandLine); 47 if (commandArgs.length === 0) { 48 throw new Error(`Parameter 'commandLine' cannot be null or empty.`); 49 } 50 // Path to tool to execute should be first arg 51 const toolPath = commandArgs[0]; 52 args = commandArgs.slice(1).concat(args || []); 53 const runner = new tr.ToolRunner(toolPath, args, options); 54 return runner.exec(); 55 }); 56 } 57 exports.exec = exec; 58 /** 59 * Exec a command and get the output. 60 * Output will be streamed to the live console. 61 * Returns promise with the exit code and collected stdout and stderr 62 * 63 * @param commandLine command to execute (can include additional args). Must be correctly escaped. 64 * @param args optional arguments for tool. Escaping is handled by the lib. 65 * @param options optional exec options. See ExecOptions 66 * @returns Promise<ExecOutput> exit code, stdout, and stderr 67 */ 68 function getExecOutput(commandLine, args, options) { 69 var _a, _b; 70 return __awaiter(this, void 0, void 0, function* () { 71 let stdout = ''; 72 let stderr = ''; 73 //Using string decoder covers the case where a mult-byte character is split 74 const stdoutDecoder = new string_decoder_1.StringDecoder('utf8'); 75 const stderrDecoder = new string_decoder_1.StringDecoder('utf8'); 76 const originalStdoutListener = (_a = options === null || options === void 0 ? void 0 : options.listeners) === null || _a === void 0 ? void 0 : _a.stdout; 77 const originalStdErrListener = (_b = options === null || options === void 0 ? void 0 : options.listeners) === null || _b === void 0 ? void 0 : _b.stderr; 78 const stdErrListener = (data) => { 79 stderr += stderrDecoder.write(data); 80 if (originalStdErrListener) { 81 originalStdErrListener(data); 82 } 83 }; 84 const stdOutListener = (data) => { 85 stdout += stdoutDecoder.write(data); 86 if (originalStdoutListener) { 87 originalStdoutListener(data); 88 } 89 }; 90 const listeners = Object.assign(Object.assign({}, options === null || options === void 0 ? void 0 : options.listeners), { stdout: stdOutListener, stderr: stdErrListener }); 91 const exitCode = yield exec(commandLine, args, Object.assign(Object.assign({}, options), { listeners })); 92 //flush any remaining characters 93 stdout += stdoutDecoder.end(); 94 stderr += stderrDecoder.end(); 95 return { 96 exitCode, 97 stdout, 98 stderr 99 }; 100 }); 101 } 102 exports.getExecOutput = getExecOutput; 103 //# sourceMappingURL=exec.js.map