"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const util = require("util");
const constants_1 = require("../constants");
const version_validator_helper_1 = require("./version-validator-helper");
class BundleValidatorHelper extends version_validator_helper_1.VersionValidatorHelper {
    constructor($projectData, $errors, $options) {
        super();
        this.$projectData = $projectData;
        this.$errors = $errors;
        this.$options = $options;
        this.bundlersMap = {
            webpack: "nativescript-dev-webpack"
        };
        this.$projectData.initializeProjectData();
    }
    validate(minSupportedVersion) {
        if (this.$options.bundle) {
            const bundlePluginName = this.bundlersMap[this.$options.bundle];
            const bundlerVersionInDependencies = this.$projectData.dependencies && this.$projectData.dependencies[bundlePluginName];
            const bundlerVersionInDevDependencies = this.$projectData.devDependencies && this.$projectData.devDependencies[bundlePluginName];
            if (!bundlePluginName || (!bundlerVersionInDependencies && !bundlerVersionInDevDependencies)) {
                this.$errors.fail(constants_1.BundleValidatorMessages.MissingBundlePlugin);
            }
            const currentVersion = bundlerVersionInDependencies || bundlerVersionInDevDependencies;
            const shouldThrowError = minSupportedVersion && this.isValidVersion(currentVersion) && this.isVersionLowerThan(currentVersion, minSupportedVersion);
            if (shouldThrowError) {
                this.$errors.failWithoutHelp(util.format(constants_1.BundleValidatorMessages.NotSupportedVersion, minSupportedVersion));
            }
        }
    }
}
exports.BundleValidatorHelper = BundleValidatorHelper;
$injector.register("bundleValidatorHelper", BundleValidatorHelper);
