| 
									
										
										
										
											2019-08-16 09:43:51 -04:00
										 |  |  | "use strict"; | 
					
						
							| 
									
										
										
										
											2020-10-01 10:45:33 -04:00
										 |  |  | var __importStar = (this && this.__importStar) || function (mod) { | 
					
						
							|  |  |  |     if (mod && mod.__esModule) return mod; | 
					
						
							|  |  |  |     var result = {}; | 
					
						
							|  |  |  |     if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k]; | 
					
						
							|  |  |  |     result["default"] = mod; | 
					
						
							|  |  |  |     return result; | 
					
						
							|  |  |  | }; | 
					
						
							| 
									
										
										
										
											2019-08-16 09:43:51 -04:00
										 |  |  | Object.defineProperty(exports, "__esModule", { value: true }); | 
					
						
							| 
									
										
										
										
											2020-10-01 10:45:33 -04:00
										 |  |  | const os = __importStar(require("os")); | 
					
						
							|  |  |  | const utils_1 = require("./utils"); | 
					
						
							| 
									
										
										
										
											2019-08-16 09:43:51 -04:00
										 |  |  | /** | 
					
						
							|  |  |  |  * Commands | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * Command Format: | 
					
						
							| 
									
										
										
										
											2020-10-01 10:45:33 -04:00
										 |  |  |  *   ::name key=value,key=value::message | 
					
						
							| 
									
										
										
										
											2019-08-16 09:43:51 -04:00
										 |  |  |  * | 
					
						
							|  |  |  |  * Examples: | 
					
						
							| 
									
										
										
										
											2020-10-01 10:45:33 -04:00
										 |  |  |  *   ::warning::This is the message | 
					
						
							|  |  |  |  *   ::set-env name=MY_VAR::some value | 
					
						
							| 
									
										
										
										
											2019-08-16 09:43:51 -04:00
										 |  |  |  */ | 
					
						
							|  |  |  | function issueCommand(command, properties, message) { | 
					
						
							|  |  |  |     const cmd = new Command(command, properties, message); | 
					
						
							|  |  |  |     process.stdout.write(cmd.toString() + os.EOL); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | exports.issueCommand = issueCommand; | 
					
						
							| 
									
										
										
										
											2020-10-01 10:45:33 -04:00
										 |  |  | function issue(name, message = '') { | 
					
						
							| 
									
										
										
										
											2019-08-16 09:43:51 -04:00
										 |  |  |     issueCommand(name, {}, message); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | exports.issue = issue; | 
					
						
							| 
									
										
										
										
											2020-10-01 10:45:33 -04:00
										 |  |  | const CMD_STRING = '::'; | 
					
						
							| 
									
										
										
										
											2019-08-16 09:43:51 -04:00
										 |  |  | class Command { | 
					
						
							|  |  |  |     constructor(command, properties, message) { | 
					
						
							|  |  |  |         if (!command) { | 
					
						
							|  |  |  |             command = 'missing.command'; | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |         this.command = command; | 
					
						
							|  |  |  |         this.properties = properties; | 
					
						
							|  |  |  |         this.message = message; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     toString() { | 
					
						
							| 
									
										
										
										
											2020-10-01 10:45:33 -04:00
										 |  |  |         let cmdStr = CMD_STRING + this.command; | 
					
						
							| 
									
										
										
										
											2019-08-16 09:43:51 -04:00
										 |  |  |         if (this.properties && Object.keys(this.properties).length > 0) { | 
					
						
							|  |  |  |             cmdStr += ' '; | 
					
						
							| 
									
										
										
										
											2020-10-01 10:45:33 -04:00
										 |  |  |             let first = true; | 
					
						
							| 
									
										
										
										
											2019-08-16 09:43:51 -04:00
										 |  |  |             for (const key in this.properties) { | 
					
						
							|  |  |  |                 if (this.properties.hasOwnProperty(key)) { | 
					
						
							|  |  |  |                     const val = this.properties[key]; | 
					
						
							|  |  |  |                     if (val) { | 
					
						
							| 
									
										
										
										
											2020-10-01 10:45:33 -04:00
										 |  |  |                         if (first) { | 
					
						
							|  |  |  |                             first = false; | 
					
						
							|  |  |  |                         } | 
					
						
							|  |  |  |                         else { | 
					
						
							|  |  |  |                             cmdStr += ','; | 
					
						
							|  |  |  |                         } | 
					
						
							|  |  |  |                         cmdStr += `${key}=${escapeProperty(val)}`; | 
					
						
							| 
									
										
										
										
											2019-08-16 09:43:51 -04:00
										 |  |  |                     } | 
					
						
							|  |  |  |                 } | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |         } | 
					
						
							| 
									
										
										
										
											2020-10-01 10:45:33 -04:00
										 |  |  |         cmdStr += `${CMD_STRING}${escapeData(this.message)}`; | 
					
						
							| 
									
										
										
										
											2019-08-16 09:43:51 -04:00
										 |  |  |         return cmdStr; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | function escapeData(s) { | 
					
						
							| 
									
										
										
										
											2020-10-01 10:45:33 -04:00
										 |  |  |     return utils_1.toCommandValue(s) | 
					
						
							|  |  |  |         .replace(/%/g, '%25') | 
					
						
							|  |  |  |         .replace(/\r/g, '%0D') | 
					
						
							|  |  |  |         .replace(/\n/g, '%0A'); | 
					
						
							| 
									
										
										
										
											2019-08-16 09:43:51 -04:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2020-10-01 10:45:33 -04:00
										 |  |  | function escapeProperty(s) { | 
					
						
							|  |  |  |     return utils_1.toCommandValue(s) | 
					
						
							|  |  |  |         .replace(/%/g, '%25') | 
					
						
							| 
									
										
										
										
											2019-08-16 09:43:51 -04:00
										 |  |  |         .replace(/\r/g, '%0D') | 
					
						
							|  |  |  |         .replace(/\n/g, '%0A') | 
					
						
							| 
									
										
										
										
											2020-10-01 10:45:33 -04:00
										 |  |  |         .replace(/:/g, '%3A') | 
					
						
							|  |  |  |         .replace(/,/g, '%2C'); | 
					
						
							| 
									
										
										
										
											2019-08-16 09:43:51 -04:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2019-06-19 09:44:17 -04:00
										 |  |  | //# sourceMappingURL=command.js.map
 |