"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.getIdentifier = exports.getAssets = exports.createRnCommand = exports.getPathVariables = void 0;
const commander_1 = require("commander");
const path_1 = require("@grund/path");
const utils_1 = require("../../utils");
function getPathVariables() {
    const relativeAppPath = path_1.path.relative(path_1.ROOT_DIR, utils_1.CURRENT_DIR);
    const GRUND_ROOT = path_1.path.relative(utils_1.CURRENT_DIR, path_1.ROOT_DIR);
    const GRUND_ENTRYFILE = path_1.path.join(relativeAppPath, 'index.ts');
    return { GRUND_ROOT, GRUND_ENTRYFILE };
}
exports.getPathVariables = getPathVariables;
function createRnCommand(cmdString, includePlatforms = false) {
    const cmd = commander_1.program.command(cmdString);
    if (includePlatforms) {
        cmd.option('--ios', 'Run command targeting ios').option('--android', 'Run command targeting ios');
    }
    return cmd;
}
exports.createRnCommand = createRnCommand;
function getAssets() {
    var _a;
    const currentConfig = utils_1.CONFIGS.RN_CONFIG.config;
    const appConfig = utils_1.CONFIGS.APP_CONFIG.config;
    const currentAssets = (currentConfig === null || currentConfig === void 0 ? void 0 : currentConfig.assets) || [];
    const fonts = ((_a = appConfig === null || appConfig === void 0 ? void 0 : appConfig.assets) === null || _a === void 0 ? void 0 : _a.fonts) || [];
    const set = new Set([...currentAssets, ...fonts]);
    const assets = [...set];
    return assets;
}
exports.getAssets = getAssets;
async function getIdentifier() {
    var _a;
    const res = await utils_1.exec('yarn react-native config', [], { stdio: 'pipe' });
    const lines = res.stdout.split('\n');
    const packageNameLine = (_a = lines.find((line) => line.includes('packageName'))) === null || _a === void 0 ? void 0 : _a.trim();
    const packageName = packageNameLine === null || packageNameLine === void 0 ? void 0 : packageNameLine.replace('packageName', '').replace(/("|:|,)/g, '').trim();
    return packageName;
}
exports.getIdentifier = getIdentifier;
