"use strict";
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
    var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
    if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
    else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
    return c > 3 && r && Object.defineProperty(target, key, r), r;
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.TestInitializationService = void 0;
const path = require("path");
const fs = require("fs");
const decorators_1 = require("../common/decorators");
const _ = require("lodash");
const yok_1 = require("../common/yok");
class TestInitializationService {
    constructor($errors, $fs) {
        this.$errors = $errors;
        this.$fs = $fs;
        this.configsPath = path.join(__dirname, "..", "..", "config");
    }
    getDependencies(selectedFramework) {
        const dependenciesPath = path.join(this.configsPath, "test-dependencies.json");
        const allDependencies = this.$fs.readJson(dependenciesPath);
        const dependenciesVersionsPath = path.join(this.configsPath, "test-deps-versions-generated.json");
        const dependenciesVersions = this.$fs.readJson(dependenciesVersionsPath);
        const targetFrameworkDependencies = allDependencies
            .filter((dependency) => !dependency.framework || dependency.framework === selectedFramework)
            .map((dependency) => {
            const dependencyVersion = dependenciesVersions[dependency.name];
            if (!dependencyVersion) {
                this.$errors.fail(`'${dependency}' is not a registered dependency.`);
            }
            return Object.assign(Object.assign({}, dependency), { version: dependencyVersion });
        });
        return targetFrameworkDependencies;
    }
    getFrameworkNames() {
        const configsPath = path.join(__dirname, "..", "..", "config");
        const dependenciesPath = path.join(configsPath, "test-dependencies.json");
        const allDependencies = JSON.parse(fs.readFileSync(dependenciesPath, { encoding: "utf-8" }));
        const frameworks = _.uniqBy(allDependencies, "framework")
            .map((item) => item && item.framework)
            .filter((item) => item);
        return frameworks;
    }
}
__decorate([
    (0, decorators_1.cache)()
], TestInitializationService.prototype, "getDependencies", null);
__decorate([
    (0, decorators_1.cache)()
], TestInitializationService.prototype, "getFrameworkNames", null);
exports.TestInitializationService = TestInitializationService;
yok_1.injector.register("testInitializationService", TestInitializationService);
