|
9 | 9 | require_relative "./helpers.rb"
|
10 | 10 | require_relative "./jsengine.rb"
|
11 | 11 |
|
| 12 | + |
12 | 13 | class NewArchitectureHelper
|
13 | 14 | @@NewArchWarningEmitted = false # Used not to spam warnings to the user.
|
14 | 15 |
|
@@ -159,4 +160,40 @@ def self.extract_react_native_version(react_native_path, file_manager: File, jso
|
159 | 160 | def self.new_arch_enabled
|
160 | 161 | return ENV["RCT_NEW_ARCH_ENABLED"] == '0' ? false : true
|
161 | 162 | end
|
| 163 | + |
| 164 | + def self.set_RCTNewArchEnabled_in_info_plist(installer, new_arch_enabled) |
| 165 | + projectPaths = installer.aggregate_targets |
| 166 | + .map{ |t| t.user_project } |
| 167 | + .uniq{ |p| p.path } |
| 168 | + .map{ |p| p.path } |
| 169 | + |
| 170 | + excluded_info_plist = ["/Pods", "Tests", "metainternal", ".bundle"] |
| 171 | + projectPaths.each do |projectPath| |
| 172 | + projectFolderPath = File.dirname(projectPath) |
| 173 | + infoPlistFiles = `find #{projectFolderPath} -name "Info.plist"` |
| 174 | + infoPlistFiles = infoPlistFiles.split("\n").map { |f| f.strip } |
| 175 | + |
| 176 | + infoPlistFiles.each do |infoPlistFile| |
| 177 | + # If infoPlistFile contains Pods or tests, skip it |
| 178 | + should_skip = false |
| 179 | + excluded_info_plist.each do |excluded| |
| 180 | + if infoPlistFile.include? excluded |
| 181 | + should_skip = true |
| 182 | + end |
| 183 | + end |
| 184 | + next if should_skip |
| 185 | + |
| 186 | + # Read the file as a plist |
| 187 | + info_plist = Xcodeproj::Plist.read_from_path(infoPlistFile) |
| 188 | + # Check if it contains the RCTNewArchEnabled key |
| 189 | + if info_plist["RCTNewArchEnabled"] and info_plist["RCTNewArchEnabled"] == new_arch_enabled |
| 190 | + next |
| 191 | + end |
| 192 | + |
| 193 | + # Add the key and value to the plist |
| 194 | + info_plist["RCTNewArchEnabled"] = new_arch_enabled ? true : false |
| 195 | + Xcodeproj::Plist.write_to_path(info_plist, infoPlistFile) |
| 196 | + end |
| 197 | + end |
| 198 | + end |
162 | 199 | end
|
0 commit comments