"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.archive = exports.build = exports.updateSettings = exports.validateLayout = void 0;
const system_settings_1 = require("@ewizardjs/system-settings");
const fs_extra_1 = require("fs-extra");
const ramda_1 = require("ramda");
const upath_1 = require("upath");
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 validateLayoutPath_1 = require("../../utils/validateLayoutPath");
const utils_1 = require("./utils");
function validateLayout({ layoutPath }) {
    return validateLayoutPath_1.validateLayoutPath(layoutPath);
}
exports.validateLayout = validateLayout;
function updateSettings({ dest, options }) {
    return __awaiter(this, void 0, void 0, function* () {
        const { target, theme, scheme } = options;
        const settingsPath = upath_1.join(dest, yield system_settings_1.getByPath(dest, 'path.settings'));
        const settings = yield fs_extra_1.readJson(settingsPath);
        const updatedValues = {
            theme: {},
        };
        target && utils_1.updateTargetCLM(updatedValues, target);
        theme && utils_1.updateTheme(settings, updatedValues, theme, scheme);
        scheme && utils_1.updateScheme(settings, updatedValues, theme, scheme);
        return fs_extra_1.writeJson(settingsPath, ramda_1.mergeDeepRight(settings, updatedValues), {
            encoding: 'utf8',
            spaces: 2,
        });
    });
}
exports.updateSettings = updateSettings;
function build({ dest, options }) {
    return __awaiter(this, void 0, void 0, function* () {
        const multiStats = (yield devBuild_1.devBuild(dest));
        if (options.archive) {
            const appCompilation = getDevCompilationResult_1.default(multiStats);
            return getBuildDeps_1.getBuildDeps(dest, appCompilation);
        }
    });
}
exports.build = build;
function archive({ build: files, buildDir, dest: rootPath, options }) {
    return __awaiter(this, void 0, void 0, function* () {
        const { archiveDest = buildDir, name } = options;
        const archiver = new EmailsArchiver_1.default(rootPath, {
            rootPath,
            files,
            name,
            archiveDest,
        });
        yield archiver.zip();
        yield fs_extra_1.remove(rootPath);
    });
}
exports.archive = archive;
//# sourceMappingURL=common.worker.js.map