"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.NodeModulesBuilder = void 0;
const _ = require("lodash");
const yok_1 = require("../../common/yok");
class NodeModulesBuilder {
    constructor($logger, $nodeModulesDependenciesBuilder, $pluginsService) {
        this.$logger = $logger;
        this.$nodeModulesDependenciesBuilder = $nodeModulesDependenciesBuilder;
        this.$pluginsService = $pluginsService;
    }
    async prepareNodeModules({ platformData, projectData, }) {
        let dependencies = this.$nodeModulesDependenciesBuilder.getProductionDependencies(projectData.projectDir, projectData.ignoredDependencies);
        dependencies = await platformData.platformProjectService.beforePrepareAllPlugins(projectData, dependencies);
        const pluginsData = this.$pluginsService.getAllProductionPlugins(projectData, platformData.platformNameLowerCase, dependencies);
        if (_.isEmpty(pluginsData)) {
            return;
        }
        for (let i = 0; i < pluginsData.length; i++) {
            const pluginData = pluginsData[i];
            await this.$pluginsService.preparePluginNativeCode({
                pluginData,
                platform: platformData.normalizedPlatformName.toLowerCase(),
                projectData,
            });
            this.$logger.trace(`Successfully prepared plugin ${pluginData.name} for ${platformData.normalizedPlatformName.toLowerCase()}.`);
        }
    }
}
exports.NodeModulesBuilder = NodeModulesBuilder;
yok_1.injector.register("nodeModulesBuilder", NodeModulesBuilder);
