From 96bf7af691e9047619d3c1b0154eddf63ddfb996 Mon Sep 17 00:00:00 2001 From: Ellet Date: Sun, 19 May 2024 17:49:56 +0300 Subject: [PATCH] chore(publishing): update the script that is used for updating the versions to require the new version as argument instead of using it from version.dart --- scripts/regenerate_versions.dart | 65 ++++++++++++++++++-------------- 1 file changed, 37 insertions(+), 28 deletions(-) diff --git a/scripts/regenerate_versions.dart b/scripts/regenerate_versions.dart index 8b06a832..357914f4 100644 --- a/scripts/regenerate_versions.dart +++ b/scripts/regenerate_versions.dart @@ -1,18 +1,12 @@ // ignore_for_file: avoid_print -import 'dart:io' show File; +import 'dart:io' show File, exit; import 'package:yaml_edit/yaml_edit.dart'; -import '../version.dart'; - /// The list of the packages that which will be used to update the `CHANGELOG.md` -/// and the `README.md`, always make `'./'` at the top -/// -/// since we should not update the `CHANGELOG.md` of -/// the `flutter_quill` since it used -/// in all the packages -final packages = [ +/// and `README.md` files for all the packages +final _packages = [ './', './dart_quill_delta', './flutter_quill_extensions', @@ -21,36 +15,51 @@ final packages = [ './quill_pdf_converter', ]; -/// A script that should run in the root folder of the repo and not inside -/// the scripts folder +/// A script that should run in the root folder and not inside any other folder +/// it has one task, which update the version for `pubspec.yaml` and `CHANGELOG.md` for all the packages +/// since we have only one CHANGELOG.md file and version, previously we had different `CHANGELOG.md` and `pubspec.yaml` package version +/// for each package /// -/// it will update the versions and changelogs, the versions will be all the same -/// from the `version.dart` and the changelogs will be use the same one from the -/// root folder of `flutter_quill` +/// the new version should be passed in the [args], the script accept only one argument Future main(List args) async { - for (final packagePath in packages) { - await updatePubspecYamlFile('$packagePath/pubspec.yaml'); - if (packagePath != packages.first) { + if (args.isEmpty) { + print('Missing required version argument. Usage: ./script '); + exit(1); + } + if (args.length > 1) { + print('Too many arguments. Usage: ./script '); + exit(1); + } + final newVersion = args[0]; + if (newVersion.isEmpty) { + print('The new version is empty. Usage: ./script '); + exit(1); + } + for (final packagePath in _packages) { + await updatePubspecYamlFile('$packagePath/pubspec.yaml', + newVersion: newVersion); + if (packagePath != _packages.first) { updateChangelogMD('$packagePath/CHANGELOG.md'); } } } -/// Read the `version` variable from `version.dart` -/// and update the package version -/// in `pubspec.yaml` from the [pubspecYamlPath] -Future updatePubspecYamlFile(String pubspecYamlPath) async { +/// Update the [pubspecYamlPath] file to update the `version` property from [newVersion] +Future updatePubspecYamlFile( + String pubspecYamlPath, { + required String newVersion, +}) async { final file = File(pubspecYamlPath); final yaml = await file.readAsString(); - final yamlEditor = YamlEditor(yaml)..update(['version'], version); + final yamlEditor = YamlEditor(yaml)..update(['version'], newVersion); await file.writeAsString(yamlEditor.toString()); print(yamlEditor.toString()); } -/// Copy the text from the root `CHANGELOG.md` and paste it to the one -/// from the [changeLogPath] -Future updateChangelogMD(String changeLogPath) async { - final changeLog = await File('./CHANGELOG.md').readAsString(); - final currentFile = File(changeLogPath); - await currentFile.writeAsString(changeLog); +/// Read the contents of the root `CHANGELOG.md` file and copy it +/// to the [changeLogFilePath] +Future updateChangelogMD(String changeLogFilePath) async { + final rootChangeLogFileContent = await File('./CHANGELOG.md').readAsString(); + final changeLogFile = File(changeLogFilePath); + await changeLogFile.writeAsString(rootChangeLogFileContent); }