Skip to content
Merged
Changes from 1 commit
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
34 changes: 23 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,18 @@ 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
? config?.project.ios.sourceDir
: '';

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

return {
needsToBeFixed: missingXcodeEnvFile,
};
Expand All @@ -52,15 +58,21 @@ 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
? 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