(progress: Ora, cwd: string)
| 140 | } |
| 141 | |
| 142 | async function modifyXcodeProject(progress: Ora, cwd: string) { |
| 143 | let xcodeProject; |
| 144 | |
| 145 | // Does `ios/*.xcodeproj` exist? |
| 146 | const iosPath = path.join(cwd, 'ios'); |
| 147 | if (fs.existsSync(iosPath)) { |
| 148 | xcodeProject = fs |
| 149 | .readdirSync(iosPath) |
| 150 | .find(file => file.includes('.xcodeproj')); |
| 151 | xcodeProject = path.join(iosPath, xcodeProject || ''); |
| 152 | } |
| 153 | |
| 154 | // Otherwise, ask for path to a file |
| 155 | if (!xcodeProject) { |
| 156 | const result = (await inquirer.prompt([ |
| 157 | { |
| 158 | type: 'input', |
| 159 | name: 'entry', |
| 160 | message: 'Enter path to the .xcodeproj file', |
| 161 | validate: (pathToFile: string) => |
| 162 | fs.existsSync(pathToFile) && pathToFile.includes('.xcodeproj') |
| 163 | ? true |
| 164 | : `${pathToFile} is not a valid .xcodeproj`, |
| 165 | }, |
| 166 | ])) as { entry: string }; |
| 167 | |
| 168 | xcodeProject = path.resolve(result.entry); |
| 169 | } |
| 170 | |
| 171 | progress.start('Adding haul to your Xcode build scripts'); |
| 172 | |
| 173 | await delay(1000); |
| 174 | |
| 175 | let project = fs |
| 176 | .readFileSync(path.join(xcodeProject, 'project.pbxproj')) |
| 177 | .toString(); |
| 178 | |
| 179 | const haulSignature = 'added by Haul'; |
| 180 | |
| 181 | /* Make sure we check both project iOS and iOS-TV, that's the magic behind "2" constant */ |
| 182 | |
| 183 | const PROJECTS_COUNT = 2; |
| 184 | |
| 185 | const countOccurrences = (search: string) => { |
| 186 | return project.split(search).length - 1; |
| 187 | }; |
| 188 | |
| 189 | // Are we already integrated? |
| 190 | if (countOccurrences(haulSignature) === PROJECTS_COUNT) { |
| 191 | progress.info('Haul is already part of your build scripts'); |
| 192 | return; |
| 193 | } |
| 194 | |
| 195 | const originalTask = 'shellScript = "export NODE_BINARY=node'; |
| 196 | |
| 197 | if (countOccurrences(originalTask) !== PROJECTS_COUNT) { |
| 198 | progress.warn( |
| 199 | `Couldn't edit Xcode project. Haven't recognized 'Bundle React Native code and images' build phase.` |
no test coverage detected