"use strict";
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
    function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
    return new (P || (P = Promise))(function (resolve, reject) {
        function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
        function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
        function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
        step((generator = generator.apply(thisArg, _arguments || [])).next());
    });
};
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;
    }
    prepareNodeModules({ platformData, projectData, }) {
        return __awaiter(this, void 0, void 0, function* () {
            const dependencies = this.$nodeModulesDependenciesBuilder.getProductionDependencies(projectData.projectDir, projectData.ignoredDependencies);
            yield 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];
                yield this.$pluginsService.preparePluginNativeCode({
                    pluginData,
                    platform: platformData.normalizedPlatformName.toLowerCase(),
                    projectData,
                });
                this.$logger.debug(`Successfully prepared plugin ${pluginData.name} for ${platformData.normalizedPlatformName.toLowerCase()}.`);
            }
        });
    }
}
exports.NodeModulesBuilder = NodeModulesBuilder;
yok_1.injector.register("nodeModulesBuilder", NodeModulesBuilder);
