"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.extractPackageFile = extractPackageFile;
const hex_1 = require("../../datasource/hex");
const schema_1 = require("./schema");
const dependencySections = ['dependencies', 'dev-dependencies'];
// map gleam.toml section keys to standard renovate depType's
// this allows us to leverage renovate built-in configurations and presets
function mapSectionKey(sectionKey) {
    switch (sectionKey) {
        case 'dev-dependencies':
            return 'devDependencies';
        default:
            return sectionKey;
    }
}
function toPackageDep({ name, sectionKey, version, }) {
    return {
        depName: name,
        depType: mapSectionKey(sectionKey),
        datasource: hex_1.HexDatasource.id,
        currentValue: version,
    };
}
function toPackageDeps({ deps, sectionKey, }) {
    return Object.entries(deps ?? {}).map(([name, version]) => toPackageDep({ name, sectionKey, version }));
}
function extractGleamTomlDeps(gleamToml) {
    return dependencySections.flatMap((sectionKey) => toPackageDeps({
        deps: gleamToml[sectionKey],
        sectionKey,
    }));
}
function extractPackageFile(content) {
    const deps = extractGleamTomlDeps(schema_1.GleamToml.parse(content));
    return deps.length ? { deps } : null;
}
//# sourceMappingURL=extract.js.map