1"use strict";
2var __importDefault = (this && this.__importDefault) || function (mod) {
3    return (mod && mod.__esModule) ? mod : { "default": mod };
4};
5Object.defineProperty(exports, "__esModule", { value: true });
6const config_plugins_1 = require("@expo/config-plugins");
7// @ts-expect-error missing types
8const app_plugin_1 = __importDefault(require("expo-dev-launcher/app.plugin"));
9// @ts-expect-error missing types
10const app_plugin_2 = __importDefault(require("expo-dev-menu/app.plugin"));
11const fs_1 = __importDefault(require("fs"));
12const path_1 = __importDefault(require("path"));
13const constants_1 = require("./constants");
14const withGeneratedAndroidScheme_1 = require("./withGeneratedAndroidScheme");
15const withGeneratedIosScheme_1 = require("./withGeneratedIosScheme");
16const pkg = require('expo-dev-client/package.json');
17const REACT_NATIVE_CONFIG_JS = `// File created by expo-dev-client/app.plugin.js
18
19module.exports = {
20  dependencies: {
21    ...require('expo-dev-client/dependencies'),
22  },
23};
24`;
25function withReactNativeConfigJs(config) {
26    config = (0, config_plugins_1.withDangerousMod)(config, ['android', addReactNativeConfigAsync]);
27    config = (0, config_plugins_1.withDangerousMod)(config, ['ios', addReactNativeConfigAsync]);
28    return config;
29}
30const addReactNativeConfigAsync = async (config) => {
31    const filename = path_1.default.join(config.modRequest.projectRoot, 'react-native.config.js');
32    try {
33        const config = fs_1.default.readFileSync(filename, 'utf8');
34        if (!config.includes('expo-dev-client/dependencies')) {
35            throw new Error(`Could not add expo-dev-client dependencies to existing file ${filename}. See expo-dev-client installation instructions to add them manually: ${constants_1.InstallationPage}`);
36        }
37    }
38    catch (error) {
39        if (error.code === 'ENOENT') {
40            // The file doesn't exist, so we create it.
41            fs_1.default.writeFileSync(filename, REACT_NATIVE_CONFIG_JS);
42        }
43        else {
44            throw error;
45        }
46    }
47    return config;
48};
49function withDevClient(config) {
50    config = (0, app_plugin_2.default)(config);
51    config = (0, app_plugin_1.default)(config);
52    config = withReactNativeConfigJs(config);
53    config = (0, withGeneratedAndroidScheme_1.withGeneratedAndroidScheme)(config);
54    config = (0, withGeneratedIosScheme_1.withGeneratedIosScheme)(config);
55    return config;
56}
57exports.default = (0, config_plugins_1.createRunOncePlugin)(withDevClient, pkg.name, pkg.version);
58