"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.getAndroidFlavors = exports.getIosFlavors = exports.loadConfig = void 0;
const tslib_1 = require("tslib");
const path_1 = tslib_1.__importDefault(require("path"));
const utils_1 = require("./utils");
const fs_1 = tslib_1.__importDefault(require("fs"));
const configFileName = 'rn-incrementalrc.json';
function getDefaultConfig() {
    return {
        ios: {},
        android: {
            flavors: {
                dev: {
                    gradleFlavor: 'debug',
                },
            },
        },
    };
}
function loadConfig() {
    const configPath = path_1.default.join((0, utils_1.getProjectRootDir)(), configFileName);
    const destinationFolder = (0, utils_1.getRootDestinationFolder)();
    if (!fs_1.default.existsSync(destinationFolder)) {
        fs_1.default.mkdirSync(destinationFolder);
    }
    if (fs_1.default.existsSync(configPath)) {
        const config = JSON.parse(fs_1.default.readFileSync(configPath, 'utf8'));
        return config;
    }
    else {
        return getDefaultConfig();
    }
}
exports.loadConfig = loadConfig;
const config = loadConfig();
function getIosFlavors(flavorName) {
    var _a, _b;
    if (!flavorName) {
        return {
            scheme: (0, utils_1.getAppName)(),
            config: 'Debug',
            flavorDir: (0, utils_1.getAppName)(),
        };
    }
    const flavorConfig = (_b = (_a = config === null || config === void 0 ? void 0 : config.ios) === null || _a === void 0 ? void 0 : _a.flavors) === null || _b === void 0 ? void 0 : _b[flavorName];
    if (flavorConfig) {
        return flavorConfig;
    }
    else {
        return {
            scheme: flavorName,
            config: 'Debug',
            flavorDir: flavorName,
        };
    }
}
exports.getIosFlavors = getIosFlavors;
function getAndroidFlavors(flavorName) {
    var _a, _b;
    if (!flavorName) {
        return {
            gradleFlavor: flavorName,
        };
    }
    const flavorConfig = (_b = (_a = config === null || config === void 0 ? void 0 : config.android) === null || _a === void 0 ? void 0 : _a.flavors) === null || _b === void 0 ? void 0 : _b[flavorName];
    if (flavorConfig) {
        return flavorConfig;
    }
    else {
        return {
            gradleFlavor: flavorName,
        };
    }
}
exports.getAndroidFlavors = getAndroidFlavors;
exports.default = config;
