Skip to content

Commit

Permalink
fix: properly create .xcode.env file with doctors auto fix (#1668)
Browse files Browse the repository at this point in the history
* fix: properly create .xcode.env file with doctors auto fix

* fix: try-catch runAutomaticFix call for xcodeEnv healthcheck
  • Loading branch information
adamTrz authored Aug 17, 2022
1 parent b49924d commit b3812ea
Showing 1 changed file with 32 additions and 22 deletions.
54 changes: 32 additions & 22 deletions packages/cli-doctor/src/tools/healthchecks/xcodeEnv.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import {HealthCheckInterface} from '../../types';
import fs from 'fs';
import path from 'path';
import {promisify} from 'util';
import {findProjectRoot} from '@react-native-community/cli-tools';
import {
findProjectRoot,
resolveNodeModuleDir,
} from '@react-native-community/cli-tools';
import {findPodfilePaths} from '@react-native-community/cli-platform-ios';

const xcodeEnvFile = '.xcode.env';
Expand All @@ -29,33 +31,41 @@ export default {
getDiagnostics: async () => {
const projectRoot = findProjectRoot();
const allPathsHasXcodeEnvFile = findPodfilePaths(projectRoot)
.map((pathString) => {
.map((pathString: string) => {
const basePath = removeLastPathComponent(pathString);
return pathHasXcodeEnvFile(basePath);
})
.reduce((previousValue, currentValue) => previousValue && currentValue);
.reduce(
(previousValue: boolean, currentValue: boolean) =>
previousValue && currentValue,
);
return {
needsToBeFixed: !allPathsHasXcodeEnvFile,
};
},
runAutomaticFix: async () => {
const templateXcodeEnv = '_xcode.env';
const projectRoot = findProjectRoot();

const templateIosPath = path.dirname(
require.resolve('react-native/template/ios'),
);

const src = templateIosPath + templateXcodeEnv;
const copyFileAsync = promisify(fs.copyFile);
runAutomaticFix: async ({loader}) => {
try {
loader.stop();
const templateXcodeEnv = '_xcode.env';
const projectRoot = findProjectRoot();
const templateIosPath = resolveNodeModuleDir(
projectRoot,
'react-native/template/ios',
);
const src = templateIosPath + pathSeparator + templateXcodeEnv;
const copyFileAsync = promisify(fs.copyFile);

findPodfilePaths(projectRoot)
.map(removeLastPathComponent)
// avoid overriding existing .xcode.env
.filter(pathDoesNotHaveXcodeEnvFile)
.forEach(async (pathString) => {
const destFilePath = pathString + pathSeparator + xcodeEnvFile;
await copyFileAsync(src, destFilePath);
});
findPodfilePaths(projectRoot)
.map(removeLastPathComponent)
// avoid overriding existing .xcode.env
.filter(pathDoesNotHaveXcodeEnvFile)
.forEach(async (pathString: string) => {
const destFilePath = pathString + pathSeparator + xcodeEnvFile;
await copyFileAsync(src, destFilePath);
});
loader.succeed('.xcode.env file have been created!');
} catch (e) {
loader.fail(e);
}
},
} as HealthCheckInterface;

0 comments on commit b3812ea

Please sign in to comment.