Skip to content

Commit

Permalink
Use guard for checking groovy
Browse files Browse the repository at this point in the history
  • Loading branch information
antonis committed Jan 16, 2025
1 parent 59e54ce commit 7b053f5
Showing 1 changed file with 17 additions and 18 deletions.
35 changes: 17 additions & 18 deletions packages/core/plugin/src/withSentryAndroidGradlePlugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,11 @@ export function withSentryAndroidGradlePlugin(
const withSentryAppBuildGradle = (config: any): any => {
return withAppBuildGradle(config, (config: any) => {
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
if (config.modResults.language === 'groovy') {
const sentryPlugin = `apply plugin: "io.sentry.android.gradle"`;
const sentryConfig = `
if (config.modResults.language !== 'groovy') {
throw new Error('Cannot configure Sentry in android/app/build.gradle because it is not in Groovy.');
}
const sentryPlugin = `apply plugin: "io.sentry.android.gradle"`;
const sentryConfig = `
sentry {
autoUploadProguardMapping = ${autoUploadProguardMapping}
includeProguardMapping = ${includeProguardMapping}
Expand All @@ -75,24 +77,21 @@ export function withSentryAndroidGradlePlugin(
}
}`;

// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
let contents = config.modResults.contents;

// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
if (!contents.includes(sentryPlugin)) {
contents = `${sentryPlugin}\n${contents}`;
}
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
let contents = config.modResults.contents;

// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
if (!contents.includes('sentry {')) {
contents = `${contents}\n${sentryConfig}`;
}
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
if (!contents.includes(sentryPlugin)) {
contents = `${sentryPlugin}\n${contents}`;
}

// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
config.modResults.contents = contents;
} else {
throw new Error('Cannot configure Sentry in android/app/build.gradle because it is not in Groovy.');
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
if (!contents.includes('sentry {')) {
contents = `${contents}\n${sentryConfig}`;
}

// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
config.modResults.contents = contents;
return config;
});
};
Expand Down

0 comments on commit 7b053f5

Please # to comment.