({
projectRoot = findProjectRoot(),
selectedPlatform,
}: {
projectRoot?: string;
selectedPlatform?: string;
})
| 88 | * Loads CLI configuration |
| 89 | */ |
| 90 | export default function loadConfig({ |
| 91 | projectRoot = findProjectRoot(), |
| 92 | selectedPlatform, |
| 93 | }: { |
| 94 | projectRoot?: string; |
| 95 | selectedPlatform?: string; |
| 96 | }): Config { |
| 97 | let lazyProject: ProjectConfig; |
| 98 | const userConfig = readConfigFromDisk(projectRoot); |
| 99 | |
| 100 | const initialConfig: Config = { |
| 101 | root: projectRoot, |
| 102 | get reactNativePath() { |
| 103 | return userConfig.reactNativePath |
| 104 | ? path.resolve(projectRoot, userConfig.reactNativePath) |
| 105 | : resolveReactNativePath(projectRoot); |
| 106 | }, |
| 107 | get reactNativeVersion() { |
| 108 | return getReactNativeVersion(initialConfig.reactNativePath); |
| 109 | }, |
| 110 | dependencies: userConfig.dependencies, |
| 111 | commands: userConfig.commands, |
| 112 | healthChecks: userConfig.healthChecks || [], |
| 113 | platforms: userConfig.platforms, |
| 114 | assets: userConfig.assets, |
| 115 | get project() { |
| 116 | if (lazyProject) { |
| 117 | return lazyProject; |
| 118 | } |
| 119 | |
| 120 | lazyProject = {}; |
| 121 | for (const platform in finalConfig.platforms) { |
| 122 | const platformConfig = finalConfig.platforms[platform]; |
| 123 | if (platformConfig) { |
| 124 | lazyProject[platform] = platformConfig.projectConfig( |
| 125 | projectRoot, |
| 126 | userConfig.project[platform] || {}, |
| 127 | ); |
| 128 | } |
| 129 | } |
| 130 | |
| 131 | return lazyProject; |
| 132 | }, |
| 133 | }; |
| 134 | |
| 135 | const finalConfig = Array.from( |
| 136 | new Set([ |
| 137 | ...Object.keys(userConfig.dependencies), |
| 138 | ...findDependencies(projectRoot), |
| 139 | ]), |
| 140 | ).reduce((acc: Config, dependencyName) => { |
| 141 | const localDependencyRoot = |
| 142 | userConfig.dependencies[dependencyName] && |
| 143 | userConfig.dependencies[dependencyName].root; |
| 144 | try { |
| 145 | let root = |
| 146 | localDependencyRoot || |
| 147 | resolveNodeModuleDir(projectRoot, dependencyName); |
no test coverage detected