Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: adjust doctor command to work with custom ios/ folder location #1998

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 19 additions & 11 deletions packages/cli-doctor/src/tools/healthchecks/xcodeEnv.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,13 @@ import {promisify} from 'util';
import {HealthCheckInterface} from '../../types';

const xcodeEnvFile = '.xcode.env';
const pathSeparator = '/';

function removeLastPathComponent(pathString: string): string {
return path.dirname(pathString);
}

function pathHasXcodeEnvFile(pathString: string): boolean {
const xcodeEnvPath = pathString + pathSeparator + xcodeEnvFile;
const xcodeEnvPath = path.join(pathString, xcodeEnvFile);
return fs.existsSync(xcodeEnvPath);
}

Expand All @@ -29,11 +28,16 @@ export default {
description: 'File to customize Xcode environment',
getDiagnostics: async (_, config) => {
try {
const projectRoot = config?.root ?? findProjectRoot();
const missingXcodeEnvFile = findPodfilePaths(projectRoot).some((p) => {
const basePath = path.dirname(p);
return !pathHasXcodeEnvFile(basePath);
});
const iosFolderPath = config?.project.ios?.sourceDir ?? '';

const missingXcodeEnvFile = findPodfilePaths(iosFolderPath).some(
(podfilePath) => {
return !pathHasXcodeEnvFile(
removeLastPathComponent(path.join(iosFolderPath, podfilePath)),
);
},
);

return {
needsToBeFixed: missingXcodeEnvFile,
};
Expand All @@ -52,15 +56,19 @@ export default {
projectRoot,
'react-native/template/ios',
);
const src = templateIosPath + pathSeparator + templateXcodeEnv;
const src = path.join(templateIosPath, templateXcodeEnv);
const copyFileAsync = promisify(fs.copyFile);

findPodfilePaths(projectRoot)
.map(removeLastPathComponent)
const iosFolderPath = config?.project.ios?.sourceDir ?? '';

findPodfilePaths(iosFolderPath)
.map((podfilePath) =>
removeLastPathComponent(path.join(iosFolderPath, podfilePath)),
)
// avoid overriding existing .xcode.env
.filter(pathDoesNotHaveXcodeEnvFile)
.forEach(async (pathString: string) => {
const destFilePath = pathString + pathSeparator + xcodeEnvFile;
const destFilePath = path.join(pathString, xcodeEnvFile);
await copyFileAsync(src, destFilePath);
});
loader.succeed('.xcode.env file have been created!');
Expand Down