UNPKG

@jameslnewell/buildkite-pipelines

Version:
48 lines (47 loc) 1.79 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); function _export(target, all) { for(var name in all)Object.defineProperty(target, name, { enumerable: true, get: all[name] }); } _export(exports, { findSteps: function() { return findSteps; }, findFirstStep: function() { return findFirstStep; } }); const _lib = require("../lib"); function findSteps(pipelineOrSteps, predicate, { recursive = true } = {}) { // if we have a pipeline, get the steps from the pipeline, otherwise get the steps from the iterable const stepsArray = Array.from(pipelineOrSteps instanceof _lib.Pipeline ? Array.from(pipelineOrSteps.getSteps()) : pipelineOrSteps); // if recursive=true, add the child steps of any GroupSteps to the array const recursiveStepsArray = recursive ? stepsArray.reduce((acc, step)=>{ // add the step itself acc.push(step); // add the group steps if (step instanceof _lib.GroupStep) { acc.push(...step.getSteps()); } else if (isGroupSchema(step)) { var _step_steps; acc.push(...(_step_steps = step.steps) !== null && _step_steps !== void 0 ? _step_steps : []); } 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(pipelineOrSteps, predicate, options = {}) { const steps = findSteps(pipelineOrSteps, predicate, options); return steps[0]; } //# sourceMappingURL=findSteps.js.map