setup-maven-cached/node_modules/@actions/core/lib/command.js

92 lines
3.0 KiB
JavaScript
Raw Permalink Normal View History

2019-12-07 21:09:20 +08:00
"use strict";
2022-10-10 17:17:09 +08:00
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
o["default"] = v;
});
var __importStar = (this && this.__importStar) || function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
2022-10-10 17:17:09 +08:00
if (mod != null) for (var k in mod) if (k !== "default" && Object.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
__setModuleDefault(result, mod);
return result;
};
2019-12-07 21:09:20 +08:00
Object.defineProperty(exports, "__esModule", { value: true });
2022-10-10 17:17:09 +08:00
exports.issue = exports.issueCommand = void 0;
const os = __importStar(require("os"));
const utils_1 = require("./utils");
2019-12-07 21:09:20 +08:00
/**
* Commands
*
* Command Format:
* ::name key=value,key=value::message
2019-12-07 21:09:20 +08:00
*
* Examples:
* ::warning::This is the message
* ::set-env name=MY_VAR::some value
2019-12-07 21:09:20 +08: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;
2019-12-07 21:09:20 +08:00
for (const key in this.properties) {
if (this.properties.hasOwnProperty(key)) {
const val = this.properties[key];
if (val) {
if (first) {
first = false;
}
else {
cmdStr += ',';
}
cmdStr += `${key}=${escapeProperty(val)}`;
2019-12-07 21:09:20 +08:00
}
}
}
}
cmdStr += `${CMD_STRING}${escapeData(this.message)}`;
2019-12-07 21:09:20 +08:00
return cmdStr;
}
}
function escapeData(s) {
return utils_1.toCommandValue(s)
.replace(/%/g, '%25')
.replace(/\r/g, '%0D')
.replace(/\n/g, '%0A');
2019-12-07 21:09:20 +08:00
}
function escapeProperty(s) {
return utils_1.toCommandValue(s)
.replace(/%/g, '%25')
2019-12-07 21:09:20 +08:00
.replace(/\r/g, '%0D')
.replace(/\n/g, '%0A')
.replace(/:/g, '%3A')
.replace(/,/g, '%2C');
2019-12-07 21:09:20 +08:00
}
//# sourceMappingURL=command.js.map