"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.extractPackageFile = void 0;
const tslib_1 = require("tslib");
const is_1 = tslib_1.__importDefault(require("@sindresorhus/is"));
const logger_1 = require("../../../logger");
const ignore_1 = require("../../../util/ignore");
const regex_1 = require("../../../util/regex");
const github_tags_1 = require("../../datasource/github-tags");
const nodeVersioning = tslib_1.__importStar(require("../../versioning/node"));
const upgradeableTooling = {
    nodejs: {
        depName: 'node',
        datasource: github_tags_1.GithubTagsDatasource.id,
        packageName: 'nodejs/node',
        versioning: nodeVersioning.id,
    },
};
function extractPackageFile(content) {
    logger_1.logger.trace('asdf.extractPackageFile()');
    const regex = (0, regex_1.regEx)(/^(?<toolName>(\w+)) (?<version>[^\s#]+)(?: [^\s#]+)* *(?: #(?<comment>.*))?$/gm);
    const deps = [];
    for (const groups of [...content.matchAll(regex)]
        .map((m) => m.groups)
        .filter(is_1.default.truthy)) {
        const supportedTool = upgradeableTooling[groups.toolName];
        if (supportedTool) {
            const dep = {
                currentValue: groups.version.trim(),
                ...supportedTool,
            };
            if ((0, ignore_1.isSkipComment)((groups.comment ?? '').trim())) {
                dep.skipReason = 'ignored';
            }
            deps.push(dep);
        }
        else {
            const dep = {
                depName: groups.toolName.trim(),
                skipReason: 'unsupported-datasource',
            };
            deps.push(dep);
        }
    }
    return deps.length ? { deps } : null;
}
exports.extractPackageFile = extractPackageFile;
//# sourceMappingURL=extract.js.map