-
Notifications
You must be signed in to change notification settings - Fork 905
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add gradlew doctor check permissions (#2191)
* feat: add gradlew doctor check permissions * feat: add gradle to android healthchecks list * feat: use config object to get android path
- Loading branch information
1 parent
0fe0be2
commit 1c9d669
Showing
2 changed files
with
55 additions
and
0 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
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; |
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