github.com/jfrog/frogbot@v1.1.1-0.20231221090046-821a26f50338/action/node_modules/@actions/core/lib/command.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 Object.defineProperty(exports, "__esModule", { value: true }); 22 exports.issue = exports.issueCommand = void 0; 23 const os = __importStar(require("os")); 24 const utils_1 = require("./utils"); 25 /** 26 * Commands 27 * 28 * Command Format: 29 * ::name key=value,key=value::message 30 * 31 * Examples: 32 * ::warning::This is the message 33 * ::set-env name=MY_VAR::some value 34 */ 35 function issueCommand(command, properties, message) { 36 const cmd = new Command(command, properties, message); 37 process.stdout.write(cmd.toString() + os.EOL); 38 } 39 exports.issueCommand = issueCommand; 40 function issue(name, message = '') { 41 issueCommand(name, {}, message); 42 } 43 exports.issue = issue; 44 const CMD_STRING = '::'; 45 class Command { 46 constructor(command, properties, message) { 47 if (!command) { 48 command = 'missing.command'; 49 } 50 this.command = command; 51 this.properties = properties; 52 this.message = message; 53 } 54 toString() { 55 let cmdStr = CMD_STRING + this.command; 56 if (this.properties && Object.keys(this.properties).length > 0) { 57 cmdStr += ' '; 58 let first = true; 59 for (const key in this.properties) { 60 if (this.properties.hasOwnProperty(key)) { 61 const val = this.properties[key]; 62 if (val) { 63 if (first) { 64 first = false; 65 } 66 else { 67 cmdStr += ','; 68 } 69 cmdStr += `${key}=${escapeProperty(val)}`; 70 } 71 } 72 } 73 } 74 cmdStr += `${CMD_STRING}${escapeData(this.message)}`; 75 return cmdStr; 76 } 77 } 78 function escapeData(s) { 79 return utils_1.toCommandValue(s) 80 .replace(/%/g, '%25') 81 .replace(/\r/g, '%0D') 82 .replace(/\n/g, '%0A'); 83 } 84 function escapeProperty(s) { 85 return utils_1.toCommandValue(s) 86 .replace(/%/g, '%25') 87 .replace(/\r/g, '%0D') 88 .replace(/\n/g, '%0A') 89 .replace(/:/g, '%3A') 90 .replace(/,/g, '%2C'); 91 } 92 //# sourceMappingURL=command.js.map