"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const utils_1 = require("../../../utils");
const helpers_1 = require("../helpers");
async function build(cmdObj, unknownOptions) {
    const { android, ios } = cmdObj;
    const env = helpers_1.getPathVariables();
    const unknownArgs = utils_1.createUnknownArgs(unknownOptions);
    const bundleCmd = 'yarn react-native bundle';
    const defaultArgs = ['--dev false', '--reset-cache', `--entry-file ${env.GRUND_ENTRYFILE}`];
    if (android) {
        await utils_1.exec(bundleCmd, [
            '--platform android',
            '--bundle-output "./android/app/src/main/assets/index.android.bundle"',
            '--sourcemap-output "./android/app/src/main/assets/index.android.bundle.map"',
            '--assets-dest "./android/app/src/main/res"',
            ...defaultArgs,
            ...unknownArgs,
        ], { env });
    }
    else if (ios) {
        await utils_1.exec(bundleCmd, [
            '--platform ios',
            '--bundle-output "./ios/main.jsbundle"',
            '--sourcemap-output "./ios/main.jsbundle.map"',
            ...defaultArgs,
            ...unknownArgs,
        ], { env });
    }
    else {
        await build({ ...cmdObj, android: true }, unknownOptions);
        await build({ ...cmdObj, ios: true }, unknownOptions);
    }
}
helpers_1.createRnCommand('rn:build', true)
    .description('Build the react-native and produce the react-native production bundles')
    .allowUnknownOption()
    .action((cmdObj, unknownOptions) => build(cmdObj, unknownOptions));
// TODO: Think about how to implement fastlane into this in order to ease the app publishing enourmously.
