ghaction-upx/node_modules/@actions/core/lib/command.js

78 lines
2.3 KiB
JavaScript
Raw Normal View History

2020-01-17 01:46:30 -07:00
"use strict";
2020-01-24 02:26:43 -07: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;
};
2020-01-17 01:46:30 -07:00
Object.defineProperty(exports, "__esModule", { value: true });
2020-01-24 02:26:43 -07:00
const os = __importStar(require("os"));
2020-01-17 01:46:30 -07:00
/**
* Commands
*
* Command Format:
2020-01-24 02:26:43 -07:00
* ::name key=value,key=value::message
2020-01-17 01:46:30 -07:00
*
* Examples:
2020-01-24 02:26:43 -07:00
* ::warning::This is the message
* ::set-env name=MY_VAR::some value
2020-01-17 01:46:30 -07:00
*/
function issueCommand(command, properties, message) {
const cmd = new Command(command, properties, message);
process.stdout.write(cmd.toString() + os.EOL);
}
exports.issueCommand = issueCommand;
function issue(name, message = '') {
issueCommand(name, {}, message);
}
exports.issue = issue;
const CMD_STRING = '::';
class Command {
constructor(command, properties, message) {
if (!command) {
command = 'missing.command';
}
this.command = command;
this.properties = properties;
this.message = message;
}
toString() {
let cmdStr = CMD_STRING + this.command;
if (this.properties && Object.keys(this.properties).length > 0) {
cmdStr += ' ';
let first = true;
for (const key in this.properties) {
if (this.properties.hasOwnProperty(key)) {
const val = this.properties[key];
if (val) {
if (first) {
first = false;
}
else {
cmdStr += ',';
}
2020-01-24 02:26:43 -07:00
cmdStr += `${key}=${escapeProperty(val)}`;
2020-01-17 01:46:30 -07:00
}
}
}
}
2020-01-24 02:26:43 -07:00
cmdStr += `${CMD_STRING}${escapeData(this.message)}`;
2020-01-17 01:46:30 -07:00
return cmdStr;
}
}
function escapeData(s) {
2020-01-24 02:26:43 -07:00
return (s || '')
.replace(/%/g, '%25')
.replace(/\r/g, '%0D')
.replace(/\n/g, '%0A');
2020-01-17 01:46:30 -07:00
}
2020-01-24 02:26:43 -07:00
function escapeProperty(s) {
return (s || '')
.replace(/%/g, '%25')
2020-01-17 01:46:30 -07:00
.replace(/\r/g, '%0D')
.replace(/\n/g, '%0A')
2020-01-24 02:26:43 -07:00
.replace(/:/g, '%3A')
.replace(/,/g, '%2C');
2020-01-17 01:46:30 -07:00
}
2020-01-17 01:36:42 -07:00
//# sourceMappingURL=command.js.map