From 40028412389e60be46c6bd637d0821d6633cc790 Mon Sep 17 00:00:00 2001 From: Sharjeel Yunus <61178058+sharjeelyunus@users.noreply.github.com> Date: Wed, 1 Jan 2025 07:26:42 +0500 Subject: [PATCH] feat: add Firebase Performance SDK integration script --- starter/scripts/firebase_performance.dart | 77 +++++++++++++++++++++++ 1 file changed, 77 insertions(+) create mode 100644 starter/scripts/firebase_performance.dart diff --git a/starter/scripts/firebase_performance.dart b/starter/scripts/firebase_performance.dart new file mode 100644 index 000000000..dfbfba179 --- /dev/null +++ b/starter/scripts/firebase_performance.dart @@ -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 arguments) { + List 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 = []; + 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); +}