Skip to content

Commit

Permalink
feat: add gradlew doctor check permissions (#2191)
Browse files Browse the repository at this point in the history
* feat: add gradlew doctor check permissions

* feat: add gradle to android healthchecks list

* feat: use config object to get android path
  • Loading branch information
jeferson-sb authored Dec 11, 2023
1 parent 0fe0be2 commit 1c9d669
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 0 deletions.
53 changes: 53 additions & 0 deletions packages/cli-doctor/src/tools/healthchecks/gradle.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
import fs from 'fs/promises';
import path from 'path';

import {HealthCheckInterface} from '../../types';
import {findProjectRoot} from '@react-native-community/cli-tools';
import {logError} from './common';

const label = 'Gradlew';
const description = 'Build tool required for Android builds';

const platform = process.platform as 'darwin' | 'win32' | 'linux';

export default {
label,
description,
getDiagnostics: async (_, config) => {
const projectRoot = findProjectRoot();
const filename = platform === 'win32' ? 'gradlew.bat' : 'gradlew';
const androidFolderPath =
config?.project.android?.sourceDir ?? `${projectRoot}/android`;

const gradleWrapperFile = path.join(androidFolderPath, filename);

const executableMode = fs.constants.X_OK;

try {
await fs.access(gradleWrapperFile, executableMode);
return {needsToBeFixed: false};
} catch {
return {needsToBeFixed: true};
}
},
runAutomaticFix: async ({loader, config}) => {
try {
const projectRoot = config?.root ?? findProjectRoot();
const filename = platform === 'win32' ? 'gradlew.bat' : 'gradlew';
const androidFolderPath =
config?.project.android?.sourceDir ?? `${projectRoot}/android`;

const gradleWrapperFile = path.join(androidFolderPath, filename);
const PERMISSIONS = 0o755;

await fs.chmod(gradleWrapperFile, PERMISSIONS);
} catch (error) {
logError({
healthcheck: label,
loader,
error: error as Error,
command: 'chmod +x gradlew',
});
}
},
} as HealthCheckInterface;
2 changes: 2 additions & 0 deletions packages/cli-doctor/src/tools/healthchecks/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import {Healthchecks, HealthCheckCategory} from '../../types';
import loadConfig from '@react-native-community/cli-config';
import xcodeEnv from './xcodeEnv';
import packager from './packager';
import gradle from './gradle';
import deepmerge from 'deepmerge';
import {logger} from '@react-native-community/cli-tools';

Expand Down Expand Up @@ -82,6 +83,7 @@ export const getHealthchecks = ({contributor}: Options): Healthchecks => {
jdk,
androidStudio,
androidHomeEnvVariable,
gradle,
...(contributor ? [androidNDK] : []),
],
},
Expand Down

0 comments on commit 1c9d669

Please sign in to comment.