"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.passedMultipleWorkspaces = exports.areWorkspacesPassed = exports.validateNameOption = exports.validateMonorepo = exports.isMonorepo = void 0;
const content_checker_1 = require("@ewizardjs/content-checker");
const fs_extra_1 = require("fs-extra");
const upath_1 = require("@ewizardjs/upath");
const I18n_1 = require("../../modules/I18n");
const Logger_1 = require("../../modules/Logger");
function isMonorepo(contentPath) {
    return __awaiter(this, void 0, void 0, function* () {
        try {
            const packageJson = yield (0, fs_extra_1.readJson)((0, upath_1.resolve)(contentPath, 'package.json'));
            return !!packageJson.monorepo;
        }
        catch (_a) {
            return false;
        }
    });
}
exports.isMonorepo = isMonorepo;
function validateMonorepo(baseDir) {
    const mandatoryFolder = (0, upath_1.join)(baseDir, 'emails');
    return Promise.all([
        (0, content_checker_1.validateInstalledDependencies)(baseDir),
        validatePathExists(mandatoryFolder),
    ]);
}
exports.validateMonorepo = validateMonorepo;
function validatePathExists(path) {
    return __awaiter(this, void 0, void 0, function* () {
        if (!(yield (0, fs_extra_1.pathExists)(path))) {
            throw new Error(`Path ${path} does not exist`);
        }
    });
}
function validateNameOption(options) {
    if (options.name && passedMultipleWorkspaces(options)) {
        Logger_1.default.info(I18n_1.default.info('MULTIPLE_LAYOUTS_NOT_SUPPORTED', '--name'));
        delete options.name;
    }
}
exports.validateNameOption = validateNameOption;
function areWorkspacesPassed({ from, fromAll, }) {
    return fromAll !== null && fromAll !== void 0 ? fromAll : (from === null || from === void 0 ? void 0 : from.length) > 0;
}
exports.areWorkspacesPassed = areWorkspacesPassed;
function passedMultipleWorkspaces({ from, fromAll }) {
    return fromAll !== null && fromAll !== void 0 ? fromAll : (from === null || from === void 0 ? void 0 : from.length) > 1;
}
exports.passedMultipleWorkspaces = passedMultipleWorkspaces;
//# sourceMappingURL=validateMonorepo.js.map