Skip to content

Commit

Permalink
feat: add Firebase Performance SDK integration script
Browse files Browse the repository at this point in the history
  • Loading branch information
sharjeelyunus committed Jan 1, 2025
1 parent 642e1d1 commit 4002841
Showing 1 changed file with 77 additions and 0 deletions.
77 changes: 77 additions & 0 deletions starter/scripts/firebase_performance.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
import 'dart:io';

import 'utils.dart';
import 'utils/firebase_utils.dart';

// Adds the Firebase Performance SDK to the project
void main(List<String> arguments) {
List<String> platforms = getPlatforms(arguments);

try {
addDependency('firebase_performance', '^0.10.0+11');

if (platforms.contains('android')) {
addClasspathDependency(
"classpath 'com.google.firebase:perf-plugin:1.4.2'");
addPluginDependency("apply plugin: 'com.google.firebase.firebase-perf'");
}

// Configure iOS-specific settings
if (platforms.contains('ios')) {
addPod('FirebasePerformance');
}

print(
'Firebase Performance SDK enabled successfully for ${platforms.join(', ')}! 🎉');
exit(0);
} catch (e) {
print('Starter Error: $e');
exit(1);
}
}

void addPod(String pod) {
final podfile = File('ios/Podfile');
if (!podfile.existsSync()) {
throw 'ios/Podfile not found';
}

final lines = podfile.readAsLinesSync();
final newLines = <String>[];
bool added = false;

for (var line in lines) {
newLines.add(line);
if (line.contains('use_frameworks!')) {
newLines.add(" pod '$pod'");
added = true;
}
}

if (!added) {
throw 'use_frameworks! not found in ios/Podfile';
}

podfile.writeAsStringSync(newLines.join('\n'));
}

void addDependency(String dependency, String version) {
final pubspec = File('pubspec.yaml');
if (!pubspec.existsSync()) {
throw 'pubspec.yaml not found';
}

// find dependencies section with regex, don't do it with lines
final content = pubspec.readAsStringSync();
final dependencies =
RegExp(r'dependencies:', multiLine: true).firstMatch(content);

if (dependencies == null) {
throw 'dependencies section not found in pubspec.yaml';
}

final newContent = content.replaceFirst(dependencies.group(0)!,
'${dependencies.group(0)}\n $dependency: $version\n');

pubspec.writeAsStringSync(newContent);
}

0 comments on commit 4002841

Please sign in to comment.