UNPKG

@catladder/pipeline

Version:

Panter workflow for cloud CI/CD and DevOps

37 lines (36 loc) 1.33 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.registerGlobalScriptFunction = exports.globalScriptFunctions = void 0; var GlobalScriptFunction = /** @class */function () { function GlobalScriptFunction(name, script) { this.name = name; this.script = script; } GlobalScriptFunction.prototype.toBashFunction = function () { return "function ".concat(this.name, " () {\n").concat(this.script.trim(), "\n}").trim(); }; GlobalScriptFunction.prototype.invoke = function () { var args = []; for (var _i = 0; _i < arguments.length; _i++) { args[_i] = arguments[_i]; } return "".concat(this.name, " ").concat(args.join(" ")); }; return GlobalScriptFunction; }(); exports.globalScriptFunctions = new Map(); /** * registers a global script function * only use that in top-level scopes as it will attach the function to the global scope */ var registerGlobalScriptFunction = function (name, script) { if (exports.globalScriptFunctions.has(name)) { throw new Error("Global script function ".concat(name, " already exists")); } var scriptFunction = new GlobalScriptFunction(name, script); exports.globalScriptFunctions.set(name, scriptFunction); return scriptFunction; }; exports.registerGlobalScriptFunction = registerGlobalScriptFunction;