"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.action = void 0;
const upath_1 = require("upath");
const WorkersListr_1 = require("../../modules/WorkersListr");
const utils_1 = require("./utils");
const EMAILS_FOLDER = 'emails';
const WORKER = upath_1.join(__dirname, 'monorepo.worker.js');
function action(baseDir, options) {
    return runMonorepoCommand(baseDir, options);
}
exports.action = action;
function runMonorepoCommand(baseDir, options) {
    return __awaiter(this, void 0, void 0, function* () {
        const emailsFolder = upath_1.join(baseDir, EMAILS_FOLDER);
        const emailsList = options.fromAll
            ? yield utils_1.getAllEmails(emailsFolder)
            : yield utils_1.getUniqueEmails(emailsFolder, options.from);
        const listr = new WorkersListr_1.WorkersListr(WORKER);
        const monorepoTasks = emailsList.map((emailPath) => utils_1.getTask(baseDir, emailsFolder, emailPath, options));
        return listr.add(monorepoTasks).run();
    });
}
//# sourceMappingURL=action.js.map