|
| 1 | +// Copyright 2024 Google LLC |
| 2 | +// |
| 3 | +// Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | +// you may not use this file except in compliance with the License. |
| 5 | +// You may obtain a copy of the License at |
| 6 | +// |
| 7 | +// http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | +// |
| 9 | +// Unless required by applicable law or agreed to in writing, software |
| 10 | +// distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | +// See the License for the specific language governing permissions and |
| 13 | +// limitations under the License. |
| 14 | + |
| 15 | +import 'dart:io' show Directory, File; |
| 16 | +import 'package:path/path.dart' show joinAll; |
| 17 | +import 'package:yaml/yaml.dart' show YamlMap, loadYaml; |
| 18 | + |
| 19 | +Future<void> main() async { |
| 20 | + final outputPath = joinAll( |
| 21 | + [ |
| 22 | + Directory.current.path, |
| 23 | + 'packages', |
| 24 | + 'firebase_ai', |
| 25 | + 'firebase_ai', |
| 26 | + 'lib', |
| 27 | + 'src', |
| 28 | + 'firebaseai_version.dart', |
| 29 | + ], |
| 30 | + ); |
| 31 | + |
| 32 | + final pubspecPath = joinAll( |
| 33 | + [ |
| 34 | + Directory.current.path, |
| 35 | + 'packages', |
| 36 | + 'firebase_data_connect', |
| 37 | + 'firebase_data_connect', |
| 38 | + 'pubspec.yaml', |
| 39 | + ], |
| 40 | + ); |
| 41 | + final yamlMap = loadYaml(File(pubspecPath).readAsStringSync()) as YamlMap; |
| 42 | + final currentVersion = yamlMap['version'] as String; |
| 43 | + final fileContents = File(outputPath).readAsStringSync(); |
| 44 | + |
| 45 | + final lines = fileContents.split('\n'); |
| 46 | + |
| 47 | + const versionLinePrefix = 'const packageVersion = '; |
| 48 | + bool versionLineFound = false; |
| 49 | + for (int i = 0; i < lines.length; i++) { |
| 50 | + if (lines[i].startsWith(versionLinePrefix)) { |
| 51 | + lines[i] = "$versionLinePrefix'$currentVersion';"; |
| 52 | + versionLineFound = true; |
| 53 | + break; |
| 54 | + } |
| 55 | + } |
| 56 | + |
| 57 | + if (!versionLineFound) { |
| 58 | + lines.add("$versionLinePrefix'$currentVersion';"); |
| 59 | + } |
| 60 | + |
| 61 | + // Join the lines back into a single string |
| 62 | + final newFileContents = lines.join('\n'); |
| 63 | + |
| 64 | + await File(outputPath).writeAsString(newFileContents); |
| 65 | +} |
0 commit comments