UNPKG

@jameslnewell/buildkite-pipelines

Version:
39 lines 1.69 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.findSteps = findSteps; exports.findFirstStep = findFirstStep; const lib_1 = require("../lib"); function findSteps(pipelineGroupOrSteps, predicate, { recursive = true } = {}) { // if we have a pipeline or a group, get its child steps; otherwise get the steps from the iterable const stepsArray = Array.from(pipelineGroupOrSteps instanceof lib_1.Pipeline || pipelineGroupOrSteps instanceof lib_1.GroupStep ? Array.from(pipelineGroupOrSteps.getSteps()) : pipelineGroupOrSteps); // if recursive=true, add the child steps of any GroupSteps to the array const recursiveStepsArray = recursive ? stepsArray.reduce((acc, step) => { var _a; // add the step itself acc.push(step); // add the group steps if (step instanceof lib_1.GroupStep) { acc.push(...step.getSteps()); } else if (isGroupSchema(step)) { acc.push(...((_a = step.steps) !== null && _a !== void 0 ? _a : [])); } return acc; }, []) : stepsArray; // filter the steps based on the predicate const filteredStepsArray = recursiveStepsArray.filter((step, stepIndexInAllSteps, allSteps) => predicate(step, stepIndexInAllSteps, allSteps)); return filteredStepsArray; } function isGroupSchema(step) { return step.group || step.steps; } function findFirstStep(pipelineGroupOrSteps, predicate, options = {}) { const steps = findSteps(pipelineGroupOrSteps, predicate, options); return steps[0]; } //# sourceMappingURL=findSteps.js.map