|
| 1 | +/// Bumps the version of the analysis options file. |
| 2 | +/// |
| 3 | +/// This script will: |
| 4 | +/// - Copy the most recent yaml to a new one with the new desired version. |
| 5 | +/// - Include that file on the main yaml file `lib/analysis_options.yaml. |
| 6 | +/// |
| 7 | +/// ## Usage |
| 8 | +/// |
| 9 | +/// Run this script (from project root): |
| 10 | +/// |
| 11 | +/// ```sh |
| 12 | +/// dart tool/bump_version/main.dart <new_version> |
| 13 | +/// ``` |
| 14 | +/// |
| 15 | +/// Where `<new_version>` is the new version to bump to in the format `x.y.z`. |
| 16 | +/// For example: `7.0.0`. |
| 17 | +library; |
| 18 | + |
| 19 | +import 'dart:io'; |
| 20 | + |
| 21 | +/// A regular expression to match the latest analysis options version. |
| 22 | +/// |
| 23 | +/// Given the following: |
| 24 | +/// |
| 25 | +/// ```sh |
| 26 | +/// include: package:very_good_analysis/analysis_options.6.0.0.yaml |
| 27 | +/// ``` |
| 28 | +/// |
| 29 | +/// It is expected that the first matched group will be `6.0.0`. |
| 30 | +final _latestAnalysisVersionRegExp = |
| 31 | + RegExp(r'analysis_options\.(\d+\.\d+\.\d+)\.yaml'); |
| 32 | + |
| 33 | +void main(List<String> args) { |
| 34 | + final analysisOptionsFile = File('lib/analysis_options.yaml'); |
| 35 | + final content = analysisOptionsFile.readAsStringSync(); |
| 36 | + final latestVersion = |
| 37 | + _latestAnalysisVersionRegExp.firstMatch(content)?.group(1); |
| 38 | + |
| 39 | + final latestAnalysisOptionsFile = |
| 40 | + File('lib/analysis_options.$latestVersion.yaml'); |
| 41 | + |
| 42 | + final newVersion = args[0]; |
| 43 | + final newAnalysisOptionsFile = File('lib/analysis_options.$newVersion.yaml'); |
| 44 | + latestAnalysisOptionsFile.copySync(newAnalysisOptionsFile.path); |
| 45 | + |
| 46 | + final newContent = content.replaceFirst( |
| 47 | + _latestAnalysisVersionRegExp, |
| 48 | + 'analysis_options.$newVersion.yaml', |
| 49 | + ); |
| 50 | + analysisOptionsFile.writeAsStringSync(newContent); |
| 51 | +} |
0 commit comments