UNPKG

jenkins-cli-node

Version:
65 lines 2.68 kB
"use strict"; var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } return new (P || (P = Promise))(function (resolve, reject) { function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } step((generator = generator.apply(thisArg, _arguments || [])).next()); }); }; Object.defineProperty(exports, "__esModule", { value: true }); const inquirer = require("inquirer"); const SearchCheckbox = require("inquirer-search-checkbox"); inquirer.registerPrompt("SearchCheckbox", SearchCheckbox); const cache_1 = require("../utils/cache"); const utils_1 = require("../utils"); const LAST_KEY = "<LAST>"; function getJobByKey(key, job) { return __awaiter(this, void 0, void 0, function* () { if (key.includes(LAST_KEY)) { const lastJob = cache_1.lastJobCache.getJob(); if (lastJob.length === 0) { return Promise.resolve(null); } else { key = cache_1.lastJobCache.getJob(); utils_1.printInfo(`Building job: ${key.join(", ")}`); } } cache_1.lastJobCache.refreshJob(key); const outputJob = key.reduce((pValue, cValue) => { if (typeof job[cValue] !== "undefined") { pValue[cValue] = job[cValue]; } return pValue; }, {}); return Promise.resolve(outputJob); }); } exports.getJobByKey = getJobByKey; function readCustomEntry(jobs, rootPath) { return __awaiter(this, void 0, void 0, function* () { let keys = [LAST_KEY].concat(jobs); const answers = yield inquirer.prompt([ { type: "SearchCheckbox", name: "key", message: `Select your jenkins job (${keys.length})`, choices: keys.map(name => ({ name })), pageSize: 8, validate(answer) { if (answer.length < 1) { return "You must choose at least one job."; } return true; } } ]); return getJobByKey(answers.key, jobs); }); } exports.readCustomEntry = readCustomEntry; //# sourceMappingURL=readCustomEntry.js.map