"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 });
const content_checker_1 = require("@ewizardjs/content-checker");
const workerpool_1 = require("workerpool");
const devBuild_1 = require("../../bin/utils/devBuild");
const getDevCompilationResult_1 = require("../../bin/utils/getDevCompilationResult");
const EmailsArchiver_1 = require("../../modules/Archiver/EmailsArchiver");
const getBuildDeps_1 = require("../../utils/getBuildDeps");
const linkNodeModules_1 = require("../../utils/linkNodeModules");
(0, workerpool_1.worker)({
    validateEmail,
    linkModules,
    build,
    archive,
});
function validateEmail({ emailPath }) {
    return (0, content_checker_1.validateMandatoryFiles)(emailPath, { type: 'email' });
}
function linkModules({ baseDir, emailPath }) {
    return __awaiter(this, void 0, void 0, function* () {
        yield (0, linkNodeModules_1.linkNodeModules)(baseDir, emailPath);
    });
}
function build({ emailPath, options }) {
    return __awaiter(this, void 0, void 0, function* () {
        const multiStats = (yield (0, devBuild_1.devBuild)(emailPath));
        if (options.command === 'archive') {
            const appCompilation = (0, getDevCompilationResult_1.default)(multiStats);
            return (0, getBuildDeps_1.getBuildDeps)(emailPath, appCompilation);
        }
    });
}
function archive({ build: files, emailsFolder: archiveDest, emailPath: rootPath, options, }) {
    return __awaiter(this, void 0, void 0, function* () {
        const { target, theme, scheme } = options;
        const archiverOptions = {
            archiveDest,
            files,
            rootPath,
            target,
            theme,
            scheme,
        };
        const archiver = new EmailsArchiver_1.default(rootPath, archiverOptions);
        yield archiver.zip();
    });
}
//# sourceMappingURL=monorepo.worker.js.map