Skip to content

Commit

Permalink
update template, check already added to pubspec
Browse files Browse the repository at this point in the history
  • Loading branch information
denrase committed Dec 9, 2024
1 parent 7844198 commit 9e8fecd
Show file tree
Hide file tree
Showing 2 changed files with 69 additions and 19 deletions.
86 changes: 68 additions & 18 deletions src/flutter/code-tools.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,26 +47,76 @@ export async function patchPubspec(pubspecFile: string | null, project: string,
}
let pubspecContent = fs.readFileSync(pubspecFile, 'utf8');

const dependenciesIndex = getDependenciesLocation(pubspecContent);

// TODO: Check if already added sentry:

const sentryFlutterVersion = await fetchSdkVersion("sentry.dart.flutter") ?? "any";
pubspecContent = pubspecContent.slice(0, dependenciesIndex) +
` sentry_flutter: ${sentryFlutterVersion ? `^${sentryFlutterVersion}` : "any"}\n` +
pubspecContent.slice(dependenciesIndex);

const devDependenciesIndex = getDevDependenciesLocation(pubspecContent);

// TODO: Check if already added sentry-dart-plugin:
pubspecContent = pubspecContent.slice(0, devDependenciesIndex) +
' sentry_dart_plugin: any\n' + // TODO: There is no sentry dart plugin in https://release-registry.services.sentry.io/sdks
pubspecContent.slice(devDependenciesIndex);
if (!pubspecContent.includes('sentry_flutter:')) {
const dependenciesIndex = getDependenciesLocation(pubspecContent);

const sentryDartFlutterVersion = await fetchSdkVersion("sentry.dart.flutter") ?? "any";
pubspecContent = pubspecContent.slice(0, dependenciesIndex) +
` sentry_flutter: ${sentryDartFlutterVersion ? `^${sentryDartFlutterVersion}` : "any"}\n` +
pubspecContent.slice(dependenciesIndex);

clack.log.success(
chalk.greenBright(
`${chalk.bold(
'sentry_flutter',
)} added to pubspec.yaml`,
),
);
} else {
clack.log.success(
chalk.greenBright(
`${chalk.bold(
'sentry_flutter',
)} is already included in pubspec.yaml`,
),
);
}

if (!pubspecContent.includes('sentry_dart_plugin:')) {
const devDependenciesIndex = getDevDependenciesLocation(pubspecContent);

const sentryDartPluginVersion = await fetchSdkVersion("sentry.dart.plugin") ?? "any";
pubspecContent = pubspecContent.slice(0, devDependenciesIndex) +
` sentry_dart_plugin: ${sentryDartPluginVersion ? `^${sentryDartPluginVersion}` : "any"}\n` +
pubspecContent.slice(devDependenciesIndex);

// TODO: Check if already added sentry:
clack.log.success(
chalk.greenBright(
`${chalk.bold(
'sentry_dart_plugin',
)} added to pubspec.yaml`,
),
);
} else {
clack.log.success(
chalk.greenBright(
`${chalk.bold(
'sentry_dart_plugin',
)} is already included in pubspec.yaml`,
),
);
}

if (!pubspecContent.includes('sentry:')) {
pubspecContent += '\n'
pubspecContent += pubspecOptions(project, org);

pubspecContent += '\n'
pubspecContent += pubspecOptions(project, org);
clack.log.success(
chalk.greenBright(
`${chalk.bold(
'sentry plugin configuration',
)} added to pubspec.yaml`,
),
);
} else {
clack.log.success(
chalk.greenBright(
`${chalk.bold(
'sentry plugin configuration',
)} is already included in pubspec.yaml`,
),
);
}

fs.writeFileSync(pubspecFile, pubspecContent, 'utf8');

Expand Down
2 changes: 1 addition & 1 deletion src/flutter/templates.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,6 @@ export function initSnippet(dsn: string, runApp: string): string {
appRunner: () => runApp(${runApp}),
);
// TODO: Remove this line after sending the first sample event to sentry.
Sentry.captureMessage('This is a sample exception.');
await Sentry.captureMessage('This is a sample exception.');
`
}

0 comments on commit 9e8fecd

Please sign in to comment.