@catladder/cli
Version:
Panter cli tool for cloud CI/CD and DevOps
32 lines • 1.09 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.registerGlobalScriptFunction = exports.globalScriptFunctions = void 0;
class GlobalScriptFunction {
constructor(name, script) {
this.name = name;
this.script = script;
}
toBashFunction() {
return `function ${this.name} () {
${this.script.trim()}
}`.trim();
}
invoke(...args) {
return `${this.name} ${args.join(" ")}`;
}
}
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
*/
const registerGlobalScriptFunction = (name, script) => {
if (exports.globalScriptFunctions.has(name)) {
throw new Error(`Global script function ${name} already exists`);
}
const scriptFunction = new GlobalScriptFunction(name, script);
exports.globalScriptFunctions.set(name, scriptFunction);
return scriptFunction;
};
exports.registerGlobalScriptFunction = registerGlobalScriptFunction;
//# sourceMappingURL=index.js.map