-
Notifications
You must be signed in to change notification settings - Fork 902
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: extract duplicated code to
getXcodeProjectAndDir
- Loading branch information
1 parent
49426fd
commit b4126f0
Showing
3 changed files
with
21 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
14 changes: 13 additions & 1 deletion
14
packages/cli-platform-apple/src/commands/buildCommand/getXcodeProjectAndDir.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,34 @@ | ||
import fs from 'fs'; | ||
import {IOSProjectConfig} from '@react-native-community/cli-types'; | ||
import {CLIError} from '@react-native-community/cli-tools'; | ||
import findXcodeProject from '../../config/findXcodeProject'; | ||
|
||
export function getXcodeProjectAndDir( | ||
iosProjectConfig: IOSProjectConfig | undefined, | ||
installedPods?: boolean, | ||
) { | ||
if (!iosProjectConfig) { | ||
throw new CLIError( | ||
'iOS project folder not found. Are you sure this is a React Native project?', | ||
); | ||
} | ||
|
||
const {xcodeProject, sourceDir} = iosProjectConfig; | ||
let {xcodeProject, sourceDir} = iosProjectConfig; | ||
|
||
if (!xcodeProject) { | ||
throw new CLIError( | ||
`Could not find Xcode project files in "${sourceDir}" folder`, | ||
); | ||
} | ||
|
||
// if project is freshly created, revisit Xcode project to verify Pods are installed correctly. | ||
// This is needed because ctx project is created before Pods are installed, so it might have outdated information. | ||
if (installedPods) { | ||
const recheckXcodeProject = findXcodeProject(fs.readdirSync(sourceDir)); | ||
if (recheckXcodeProject) { | ||
xcodeProject = recheckXcodeProject; | ||
} | ||
} | ||
|
||
return {xcodeProject, sourceDir}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters