UNPKG

@woodpecker-ci/plugin

Version:

Utilities to create a Woodpecker-CI typescript / javascript plugin.

114 lines (111 loc) 3.97 kB
"use strict"; var __create = Object.create; var __defProp = Object.defineProperty; var __getOwnPropDesc = Object.getOwnPropertyDescriptor; var __getOwnPropNames = Object.getOwnPropertyNames; var __getProtoOf = Object.getPrototypeOf; var __hasOwnProp = Object.prototype.hasOwnProperty; var __export = (target, all) => { for (var name in all) __defProp(target, name, { get: all[name], enumerable: true }); }; var __copyProps = (to, from, except, desc) => { if (from && typeof from === "object" || typeof from === "function") { for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable }); } return to; }; var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps( // If the importer is in node compatibility mode or this is not an ESM // file that has been converted to a CommonJS file using a Babel- // compatible transform (i.e. "__esModule" has not been set), then set // "default" to the CommonJS "module.exports" for node compatibility. isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target, mod )); var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod); var __async = (__this, __arguments, generator) => { return new Promise((resolve, reject) => { var fulfilled = (value) => { try { step(generator.next(value)); } catch (e) { reject(e); } }; var rejected = (value) => { try { step(generator.throw(value)); } catch (e) { reject(e); } }; var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected); step((generator = generator.apply(__this, __arguments)).next()); }); }; // src/index.ts var index_exports = {}; __export(index_exports, { runPlugin: () => runPlugin }); module.exports = __toCommonJS(index_exports); // src/plugin.ts var import_dotenv = __toESM(require("dotenv"), 1); function runPlugin(options) { return __async(this, null, function* () { import_dotenv.default.config({ quiet: true }); const settingsValues = Object.fromEntries( Object.entries(options.settings).map(([name, setting]) => [ name, (() => { var _a; const value = process.env[`PLUGIN_${name.toUpperCase()}`]; if (setting.required && value === void 0) { throw new Error(`Missing required setting: ${name}`); } if (value === void 0 || value === null || value.trim() === "") { return setting.default || void 0; } if (setting.type === "string") { if ((_a = setting.trimWhiteSpace) != null ? _a : true) { return value.trim(); } return value; } if (setting.type === "number") { const number = Number(value); if (isNaN(number)) { throw new Error(`Invalid number setting: ${name}`); } return number; } if (setting.type === "boolean") { const _value = value.trim().toLocaleLowerCase(); if (_value === "true") { return true; } if (_value === "false") { return false; } throw new Error(`Invalid boolean setting: ${name}`); } if (setting.type === "json") { try { return JSON.parse(value); } catch (error) { throw new Error(`Invalid JSON setting: ${name}`); } } })() ]) ); yield options.run({ settings: settingsValues }); }); } // Annotate the CommonJS export names for ESM import in node: 0 && (module.exports = { runPlugin });