@@ -6,6 +6,7 @@ import 'package:melos/melos.dart' as melos;
6
6
import 'package:glob/glob.dart' ;
7
7
import 'dart:io' ;
8
8
import 'package:cli_util/cli_logging.dart' as logging;
9
+ import 'package:yaml/yaml.dart' ;
9
10
10
11
// Used to generate a simple txt file for Package.swift file to parse in order to use correct firebase-ios-sdk version
11
12
@@ -33,6 +34,8 @@ void main(List<String> args) async {
33
34
versionFile.writeAsStringSync (firebaseiOSVersion);
34
35
}
35
36
}
37
+ // Update the versions in root Package.swift
38
+ updateVersionsPackageSwift (firebaseiOSVersion);
36
39
}
37
40
38
41
Future <melos.MelosWorkspace > getMelosWorkspace () async {
@@ -69,3 +72,67 @@ String getFirebaseiOSVersion(File firebaseCoreIosSdkVersion) {
69
72
throw Exception ('firebase_sdk_version.rb file does not exist.' );
70
73
}
71
74
}
75
+
76
+ void updateVersionsPackageSwift (String firebaseiOSVersion) {
77
+ // Define the path to the pubspec.yaml file
78
+ const pubspecPath = 'packages/firebase_core/firebase_core/pubspec.yaml' ;
79
+
80
+
81
+ // Read the pubspec.yaml file
82
+ final pubspecFile = File (pubspecPath);
83
+ if (! pubspecFile.existsSync ()) {
84
+ print ('Error: pubspec.yaml file not found at $pubspecPath ' );
85
+ return ;
86
+ }
87
+
88
+
89
+ // Parse the YAML content
90
+ final pubspecContent = pubspecFile.readAsStringSync ();
91
+ final pubspecYaml = loadYaml (pubspecContent);
92
+
93
+
94
+ // Extract the version
95
+ final version = pubspecYaml['version' ];
96
+ if (version == null ) {
97
+ print ('Error: Version not found in pubspec.yaml' );
98
+ return ;
99
+ }
100
+
101
+
102
+ // Define the path to the Package.swift file
103
+ const packageSwiftPath = 'Package.swift' ;
104
+
105
+
106
+ // Read the Package.swift file
107
+ final packageSwiftFile = File (packageSwiftPath);
108
+ if (! packageSwiftFile.existsSync ()) {
109
+ print ('Error: Package.swift file not found at $packageSwiftPath ' );
110
+ return ;
111
+ }
112
+
113
+
114
+ // Read the content of Package.swift
115
+ final packageSwiftContent = packageSwiftFile.readAsStringSync ();
116
+
117
+
118
+ // Update the library_version_string with the new version
119
+ final updatedFirebaseCoreVersion = packageSwiftContent.replaceAll (
120
+ RegExp ('let firebase_core_version: String = "[^"]+"' ),
121
+ 'let firebase_core_version: String = "$version "' ,
122
+ );
123
+
124
+
125
+ final updatedFirebaseIosVersion = updatedFirebaseCoreVersion.replaceAll (
126
+ RegExp ('let firebase_ios_sdk_version: String = "[^"]+"' ),
127
+ 'let firebase_ios_sdk_version: String = "$firebaseiOSVersion "' ,
128
+ );
129
+
130
+
131
+ // Write the updated content back to Package.swift
132
+ packageSwiftFile.writeAsStringSync (updatedFirebaseIosVersion);
133
+
134
+
135
+ print (
136
+ 'Updated Package.swift with firebase_core version: $version & firebase-ios-sdk version: $firebaseiOSVersion ' ,
137
+ );
138
+ }
0 commit comments