"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.logs = void 0;
const get_lerna_graph_1 = require("../utils/get-lerna-graph");
const interactive_1 = require("../utils/interactive");
const logs_1 = require("../utils/logs");
const start_1 = require("./start");
exports.logs = (cmd, logger, scheduler) => __awaiter(void 0, void 0, void 0, function* () {
    const { projectRoot, config } = yield start_1.init(logger, scheduler);
    let services = [];
    logger.log('logs').debug(config);
    if (!cmd.S) {
        const graph = yield get_lerna_graph_1.getLernaGraph(projectRoot, scheduler, config, logger, 3001);
        yield graph.bootstrap().catch((e) => {
            logger.log('logs').error(e);
            logger
                .log('logs')
                .error('Error installing microservices dependencies. Run in verbose mode (export MILA_DEBUG=*) for more infos.');
            process.exit(1);
        });
        const enabledServices = graph.getServices().filter((s) => !config.noStart.includes(s.getName()));
        yield interactive_1.interactive(enabledServices, 'Please select the microservices for which you want to see the logs', logger).then((s) => (services = s));
        const servicesName = services.map((s) => s.getName().replace('@project/', ''));
        servicesName.forEach((name) => logs_1.tailLogs(name, projectRoot, logger));
    }
    else {
        logs_1.tailLogs(cmd.S, projectRoot, logger);
    }
});
//# sourceMappingURL=logs.js.map