Skip to content
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: 12 additions & 18 deletions packages/cli-clean/src/clean.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,18 +37,6 @@ function cleanDir(directory: string): Promise<void> {
return rmdirAsync(directory, {maxRetries: 3, recursive: true});
}

function findPath(startPath: string, files: string[]): string | undefined {
// TODO: Find project files via `@react-native-community/cli`
for (const file of files) {
const filename = path.resolve(startPath, file);
if (fileExists(filename)) {
return filename;
}
}

return undefined;
}

async function promptForCaches(
groups: CleanGroups,
): Promise<string[] | undefined> {
Expand All @@ -68,7 +56,7 @@ async function promptForCaches(

export async function clean(
_argv: string[],
_config: CLIConfig,
ctx: CLIConfig,
cleanOptions: Args,
): Promise<void> {
const {include, projectRoot, verifyCache} = cleanOptions;
Expand All @@ -83,12 +71,18 @@ export async function clean(
{
label: 'Clean Gradle cache',
action: async () => {
const candidates =
const gradlew =
os.platform() === 'win32'
? ['android/gradlew.bat', 'gradlew.bat']
: ['android/gradlew', 'gradlew'];
const gradlew = findPath(projectRoot, candidates);
if (gradlew) {
? path.join(
ctx.project.android?.sourceDir ?? 'android',
'gradlew.bat',
)
: path.join(
ctx.project.android?.sourceDir ?? 'android',
'gradlew',
);

if (fileExists(gradlew)) {
const script = path.basename(gradlew);
await execa(
os.platform() === 'win32' ? script : `./${script}`,
Expand Down