"use strict";
var __importStar = (this && this.__importStar) || function (mod) {
    if (mod && mod.__esModule) return mod;
    var result = {};
    if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k];
    result["default"] = mod;
    return result;
};
Object.defineProperty(exports, "__esModule", { value: true });
const GeneratorConfigJson = __importStar(require("./generator-config.json"));
exports.GeneratorConfig = toGeneratorConfig(GeneratorConfigJson);
function getDependencyVersionFromGroup(name) {
    const groups = GeneratorConfigJson.dependencyGroups;
    if (!(name in groups)) {
        throw new Error(`INTERNAL GENERATOR ERROR: missing dependency group "${name}"`);
    }
    return groups[name];
}
exports.getDependencyVersionFromGroup = getDependencyVersionFromGroup;
function toGeneratorConfig(config) {
    return {
        dependencies: config.dependencies.map((dep) => {
            return {
                name: dep.name,
                type: dep.type,
                version: dep.version ? dep.version : getDependencyVersionFromGroup(dep.group),
                constraint: dep.constraint,
                overwrite: dep.overwrite
            };
        }),
        cordovaDependencies: config.cordovaDependencies.map((dep) => {
            let spec = dep.spec;
            if (!spec) {
                if (dep.group) {
                    spec = getDependencyVersionFromGroup(dep.group);
                }
                else if (dep.version) {
                    spec = dep.version;
                }
            }
            if (!spec) {
                throw new Error(`No cordova plugin version found for package: ${dep.package}`);
            }
            return {
                version: dep.version,
                constraint: dep.constraint,
                id: dep.id,
                package: dep.package,
                spec,
                prefixVersionWithPackage: dep.prefixVersionWithPackage
            };
        })
    };
}
//# sourceMappingURL=config-dependencies.js.map