"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.extractPackageFile = extractPackageFile;
const tslib_1 = require("tslib");
const is_1 = tslib_1.__importDefault(require("@sindresorhus/is"));
const logger_1 = require("../../../logger");
const yaml_1 = require("../../../util/yaml");
const schema_1 = require("./schema");
const utils_1 = require("./utils");
function extractPackageFile(content, packageFile) {
    const deps = [];
    try {
        const parsed = (0, yaml_1.parseSingleYaml)(content, {
            customSchema: schema_1.BitriseFile,
        });
        const workflows = Object.values(parsed.workflows);
        for (const workflow of workflows) {
            const steps = workflow.steps.flatMap((step) => Object.keys(step));
            for (const step of steps) {
                const dep = (0, utils_1.parseStep)(step, parsed.default_step_lib_source);
                if (!is_1.default.nullOrUndefined(dep)) {
                    deps.push(dep);
                }
            }
        }
    }
    catch (err) {
        logger_1.logger.debug({ err, packageFile }, `Failed to parse Bitrise YAML config`);
    }
    if (!deps.length) {
        return null;
    }
    return { deps };
}
//# sourceMappingURL=extract.js.map