From c08d02e4d994f56f07d40b87f6c6bcce28196d57 Mon Sep 17 00:00:00 2001 From: Alex Li Date: Wed, 18 Jan 2023 12:05:33 +0800 Subject: [PATCH 1/9] =?UTF-8?q?=E2=9C=A8=20Add=20the=20preparation=20tool?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pkgs/cronet_http/pubspec.yaml | 1 + .../tool/prepare_for_embedded.dart | 62 +++++++++++++++++++ 2 files changed, 63 insertions(+) create mode 100644 pkgs/cronet_http/tool/prepare_for_embedded.dart diff --git a/pkgs/cronet_http/pubspec.yaml b/pkgs/cronet_http/pubspec.yaml index a0702eef78..02be927351 100644 --- a/pkgs/cronet_http/pubspec.yaml +++ b/pkgs/cronet_http/pubspec.yaml @@ -16,6 +16,7 @@ dependencies: dev_dependencies: lints: ^1.0.0 pigeon: ^3.2.3 + xml: ^6.1.0 flutter: plugin: diff --git a/pkgs/cronet_http/tool/prepare_for_embedded.dart b/pkgs/cronet_http/tool/prepare_for_embedded.dart new file mode 100644 index 0000000000..4d35020481 --- /dev/null +++ b/pkgs/cronet_http/tool/prepare_for_embedded.dart @@ -0,0 +1,62 @@ +// Copyright (c) 2022, the Dart project authors. Please see the AUTHORS file +// for details. All rights reserved. Use of this source code is governed by a +// BSD-style license that can be found in the LICENSE file. + +import 'dart:io'; + +import 'package:http/http.dart' as http; +import 'package:xml/xml.dart'; + +void main() async { + final latestVersion = await _getLatestVersion(); + _writeImplementationToTheFile(latestVersion); +} + +Future _getLatestVersion() async { + final url = Uri.https( + 'dl.google.com', + 'android/maven2/org/chromium/net/group-index.xml', + ); + final response = await http.get(url); + final parsedXml = XmlDocument.parse(response.body); + final embeddedNode = parsedXml.children + .singleWhere((e) => e is XmlElement) + .children + .singleWhere((e) => e is XmlElement && e.name.local == 'cronet-embedded'); + final stableVersionReg = RegExp(r'^(\d+).(\d+).(\d+)$'); + final versions = embeddedNode.attributes + .singleWhere((e) => e.name.local == 'versions') + .value + .split(',') + .where((e) => stableVersionReg.stringMatch(e) == e); + return versions.last; +} + +void _writeImplementationToTheFile(String latestVersion) { + var dir = Directory.current; + if (dir.path.endsWith('tool')) { + dir = dir.parent; + } + // Update android/build.gradle + final fBuildGradle = File('${dir.path}/android/build.gradle'); + final gradleContent = fBuildGradle.readAsStringSync(); + final implementationRegExp = RegExp( + '^(\\s*)implementation [\'"]' + 'com.google.android.gms:play-services-cronet' + ':(\\d+.\\d+.\\d+)[\'"]', + multiLine: true, + ); + final newGradleContent = gradleContent.replaceAll( + implementationRegExp, + ' implementation "org.chromium.net:cronet-embedded:$latestVersion"', + ); + fBuildGradle.writeAsStringSync(newGradleContent); + // Update pubspec.yaml + final fPubspec = File('${dir.path}/pubspec.yaml'); + fPubspec.writeAsStringSync( + fPubspec.readAsStringSync().replaceAll( + RegExp(r'^name: cronet_http$'), + 'name: cronet_http_embedded', + ), + ); +} From cc61e446d6a3476b4f260ea747799a53549b02a6 Mon Sep 17 00:00:00 2001 From: Alex Li Date: Wed, 18 Jan 2023 12:06:04 +0800 Subject: [PATCH 2/9] =?UTF-8?q?=F0=9F=9A=9A=20Move=20scripts?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pkgs/cronet_http/{ => tool}/run_pigeon.sh | 1 + 1 file changed, 1 insertion(+) rename pkgs/cronet_http/{ => tool}/run_pigeon.sh (97%) mode change 100755 => 100644 diff --git a/pkgs/cronet_http/run_pigeon.sh b/pkgs/cronet_http/tool/run_pigeon.sh old mode 100755 new mode 100644 similarity index 97% rename from pkgs/cronet_http/run_pigeon.sh rename to pkgs/cronet_http/tool/run_pigeon.sh index 188a29cad2..d147e02992 --- a/pkgs/cronet_http/run_pigeon.sh +++ b/pkgs/cronet_http/tool/run_pigeon.sh @@ -1,6 +1,7 @@ #!/bin/sh # Generate the platform messages used by cronet_http. +cd ../ flutter pub run pigeon \ --input pigeons/messages.dart \ From 09cbf7fb1406771b07a33f0e3c2b4036cdf877df Mon Sep 17 00:00:00 2001 From: Alex Li Date: Thu, 19 Jan 2023 05:58:28 +0800 Subject: [PATCH 3/9] =?UTF-8?q?=F0=9F=94=A5=20Remove=20useless=20groups?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pkgs/cronet_http/tool/prepare_for_embedded.dart | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/pkgs/cronet_http/tool/prepare_for_embedded.dart b/pkgs/cronet_http/tool/prepare_for_embedded.dart index 4d35020481..fecd7e2a93 100644 --- a/pkgs/cronet_http/tool/prepare_for_embedded.dart +++ b/pkgs/cronet_http/tool/prepare_for_embedded.dart @@ -23,7 +23,7 @@ Future _getLatestVersion() async { .singleWhere((e) => e is XmlElement) .children .singleWhere((e) => e is XmlElement && e.name.local == 'cronet-embedded'); - final stableVersionReg = RegExp(r'^(\d+).(\d+).(\d+)$'); + final stableVersionReg = RegExp(r'^\d+.\d+.\d+$'); final versions = embeddedNode.attributes .singleWhere((e) => e.name.local == 'versions') .value @@ -41,9 +41,9 @@ void _writeImplementationToTheFile(String latestVersion) { final fBuildGradle = File('${dir.path}/android/build.gradle'); final gradleContent = fBuildGradle.readAsStringSync(); final implementationRegExp = RegExp( - '^(\\s*)implementation [\'"]' + '^\\s*implementation [\'"]' 'com.google.android.gms:play-services-cronet' - ':(\\d+.\\d+.\\d+)[\'"]', + ':\\d+.\\d+.\\d+[\'"]', multiLine: true, ); final newGradleContent = gradleContent.replaceAll( From 332ac10bb887468c1ffd14f791696673902f950e Mon Sep 17 00:00:00 2001 From: Alex Li Date: Tue, 14 Feb 2023 11:12:58 +0800 Subject: [PATCH 4/9] =?UTF-8?q?=F0=9F=9A=80=20Use=20`yaml=5Fedit`=20to=20u?= =?UTF-8?q?pdate=20pubspec?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pkgs/cronet_http/pubspec.yaml | 1 + pkgs/cronet_http/tool/prepare_for_embedded.dart | 17 +++++++++++------ 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/pkgs/cronet_http/pubspec.yaml b/pkgs/cronet_http/pubspec.yaml index 02be927351..334ee9d859 100644 --- a/pkgs/cronet_http/pubspec.yaml +++ b/pkgs/cronet_http/pubspec.yaml @@ -17,6 +17,7 @@ dev_dependencies: lints: ^1.0.0 pigeon: ^3.2.3 xml: ^6.1.0 + yaml_edit: ^2.0.3 flutter: plugin: diff --git a/pkgs/cronet_http/tool/prepare_for_embedded.dart b/pkgs/cronet_http/tool/prepare_for_embedded.dart index fecd7e2a93..52af22b99e 100644 --- a/pkgs/cronet_http/tool/prepare_for_embedded.dart +++ b/pkgs/cronet_http/tool/prepare_for_embedded.dart @@ -6,6 +6,7 @@ import 'dart:io'; import 'package:http/http.dart' as http; import 'package:xml/xml.dart'; +import 'package:yaml_edit/yaml_edit.dart'; void main() async { final latestVersion = await _getLatestVersion(); @@ -53,10 +54,14 @@ void _writeImplementationToTheFile(String latestVersion) { fBuildGradle.writeAsStringSync(newGradleContent); // Update pubspec.yaml final fPubspec = File('${dir.path}/pubspec.yaml'); - fPubspec.writeAsStringSync( - fPubspec.readAsStringSync().replaceAll( - RegExp(r'^name: cronet_http$'), - 'name: cronet_http_embedded', - ), - ); + final yamlEditor = YamlEditor(fPubspec.readAsStringSync()) + ..update(['name'], 'cronet_http_embedded') + ..update( + ['description'], + 'An Android Flutter plugin that ' + 'provides access to the Cronet HTTP client. ' + 'Identical to package:cronet_http except that it embeds Cronet ' + 'rather than relying on Google Play Services.', + ); + fPubspec.writeAsStringSync(yamlEditor.toString()); } From 7181f17c2c7ee8c0241f9207e9f4f15b01cb7553 Mon Sep 17 00:00:00 2001 From: Alex Li Date: Tue, 14 Feb 2023 11:13:04 +0800 Subject: [PATCH 5/9] =?UTF-8?q?=F0=9F=94=8A=20Log=20when=20patching=20the?= =?UTF-8?q?=20implementation=20version?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pkgs/cronet_http/tool/prepare_for_embedded.dart | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/pkgs/cronet_http/tool/prepare_for_embedded.dart b/pkgs/cronet_http/tool/prepare_for_embedded.dart index 52af22b99e..597f0db1ba 100644 --- a/pkgs/cronet_http/tool/prepare_for_embedded.dart +++ b/pkgs/cronet_http/tool/prepare_for_embedded.dart @@ -47,9 +47,11 @@ void _writeImplementationToTheFile(String latestVersion) { ':\\d+.\\d+.\\d+[\'"]', multiLine: true, ); + final newImplementation = 'org.chromium.net:cronet-embedded:$latestVersion'; + print('Patching $newImplementation'); final newGradleContent = gradleContent.replaceAll( implementationRegExp, - ' implementation "org.chromium.net:cronet-embedded:$latestVersion"', + ' implementation $newImplementation', ); fBuildGradle.writeAsStringSync(newGradleContent); // Update pubspec.yaml From 591d6ca0877e49622810f4954d0206c26e7646f0 Mon Sep 17 00:00:00 2001 From: Alex Li Date: Tue, 14 Feb 2023 11:22:30 +0800 Subject: [PATCH 6/9] =?UTF-8?q?=E2=9C=A8=20Add=20README=20replacement?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pkgs/cronet_http/README_EMBEDDED.md | 23 +++++++++++++++++++ .../tool/prepare_for_embedded.dart | 10 ++++++++ 2 files changed, 33 insertions(+) create mode 100644 pkgs/cronet_http/README_EMBEDDED.md diff --git a/pkgs/cronet_http/README_EMBEDDED.md b/pkgs/cronet_http/README_EMBEDDED.md new file mode 100644 index 0000000000..a222f77699 --- /dev/null +++ b/pkgs/cronet_http/README_EMBEDDED.md @@ -0,0 +1,23 @@ +An Android Flutter plugin that provides access to the +[Cronet](https://developer.android.com/guide/topics/connectivity/cronet/reference/org/chromium/net/package-summary) +HTTP client. + +Cronet embedded is available as a standalone implementation +which will brought additional 8MB for apps approximately. + +## Status: Experimental + +**NOTE**: This package is currently experimental and published under the +[labs.dart.dev](https://dart.dev/dart-team-packages) pub publisher in order to +solicit feedback. + +For packages in the labs.dart.dev publisher we generally plan to either graduate +the package into a supported publisher (dart.dev, tools.dart.dev) after a period +of feedback and iteration, or discontinue the package. These packages have a +much higher expected rate of API and breaking changes. + +Your feedback is valuable and will help us evolve this package. +For general feedback and suggestions please comment in the +[feedback issue](https://github.com/dart-lang/http/issues/764). +For bugs, please file an issue in the +[bug tracker](https://github.com/dart-lang/http/issues). diff --git a/pkgs/cronet_http/tool/prepare_for_embedded.dart b/pkgs/cronet_http/tool/prepare_for_embedded.dart index 597f0db1ba..ac43c8fa5d 100644 --- a/pkgs/cronet_http/tool/prepare_for_embedded.dart +++ b/pkgs/cronet_http/tool/prepare_for_embedded.dart @@ -11,6 +11,7 @@ import 'package:yaml_edit/yaml_edit.dart'; void main() async { final latestVersion = await _getLatestVersion(); _writeImplementationToTheFile(latestVersion); + _replaceREADME(); } Future _getLatestVersion() async { @@ -67,3 +68,12 @@ void _writeImplementationToTheFile(String latestVersion) { ); fPubspec.writeAsStringSync(yamlEditor.toString()); } + +void _replaceREADME() { + var dir = Directory.current; + if (dir.path.endsWith('tool')) { + dir = dir.parent; + } + File('${dir.path}/README.md').deleteSync(); + File('${dir.path}/README_EMBEDDED.md').renameSync('${dir.path}/README.md'); +} From 2f2f917640ec301bba01b34ca93532206c2a88b9 Mon Sep 17 00:00:00 2001 From: Alex Li Date: Wed, 15 Feb 2023 11:34:45 +0800 Subject: [PATCH 7/9] =?UTF-8?q?=F0=9F=93=9D=20Improve=20the=20README?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pkgs/cronet_http/README_EMBEDDED.md | 25 +++++++------------------ 1 file changed, 7 insertions(+), 18 deletions(-) diff --git a/pkgs/cronet_http/README_EMBEDDED.md b/pkgs/cronet_http/README_EMBEDDED.md index a222f77699..db948d821c 100644 --- a/pkgs/cronet_http/README_EMBEDDED.md +++ b/pkgs/cronet_http/README_EMBEDDED.md @@ -2,22 +2,11 @@ An Android Flutter plugin that provides access to the [Cronet](https://developer.android.com/guide/topics/connectivity/cronet/reference/org/chromium/net/package-summary) HTTP client. -Cronet embedded is available as a standalone implementation -which will brought additional 8MB for apps approximately. - -## Status: Experimental - -**NOTE**: This package is currently experimental and published under the -[labs.dart.dev](https://dart.dev/dart-team-packages) pub publisher in order to -solicit feedback. - -For packages in the labs.dart.dev publisher we generally plan to either graduate -the package into a supported publisher (dart.dev, tools.dart.dev) after a period -of feedback and iteration, or discontinue the package. These packages have a -much higher expected rate of API and breaking changes. +This package is identical to [`package:cronet_http`](https://pub.dev/packages/cronet_http) +except that it embeds +[Cronet](https://developer.android.com/guide/topics/connectivity/cronet/reference/org/chromium/net/package-summary) +rather than using the version included with +[Google Play Services](https://developers.google.com/android/guides/overview). +This increases the uncompressed size of the application by approximately 8MB. -Your feedback is valuable and will help us evolve this package. -For general feedback and suggestions please comment in the -[feedback issue](https://github.com/dart-lang/http/issues/764). -For bugs, please file an issue in the -[bug tracker](https://github.com/dart-lang/http/issues). +See more details about the cronet_http at: https://pub.dev/packages/cronet_http. From a121848009bda8a7d0def55b38941d995db403c4 Mon Sep 17 00:00:00 2001 From: Alex Li Date: Wed, 15 Feb 2023 11:49:57 +0800 Subject: [PATCH 8/9] =?UTF-8?q?=F0=9F=8E=A8=20Improve=20codes?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../tool/prepare_for_embedded.dart | 93 ++++++++++++------- 1 file changed, 58 insertions(+), 35 deletions(-) diff --git a/pkgs/cronet_http/tool/prepare_for_embedded.dart b/pkgs/cronet_http/tool/prepare_for_embedded.dart index ac43c8fa5d..efa0da32d2 100644 --- a/pkgs/cronet_http/tool/prepare_for_embedded.dart +++ b/pkgs/cronet_http/tool/prepare_for_embedded.dart @@ -1,6 +1,7 @@ // Copyright (c) 2022, the Dart project authors. Please see the AUTHORS file // for details. All rights reserved. Use of this source code is governed by a // BSD-style license that can be found in the LICENSE file. +// ignore_for_file: lines_longer_than_80_chars import 'dart:io'; @@ -8,18 +9,49 @@ import 'package:http/http.dart' as http; import 'package:xml/xml.dart'; import 'package:yaml_edit/yaml_edit.dart'; +/// The cronet_http directory is used to produce two packages: +/// - `cronet_http`, which uses the Google Play Services version of Cronet. +/// - `cronet_http_embedded`, which embeds Cronet. +/// +/// The default configuration of this code is to use the Google Play Services version of Cronet. +/// +/// The script transforms the configuration into one that embeds Cronet by: +/// 1. Modifying the Gradle build file to reference the embedded version of Cronet. +/// 2. Modifying the *name* and *description* in `pubspec.yaml`. +/// 3. Replaying `README.md` with `README_EMBEDDED.md`. +/// +/// After running this script, `flutter pub publish` can be run to update package:cronet_http_embedded. +/// +/// NOTE: This script modifies the above files in place. +late final Directory _directory; + +const String _gmsDependencyName = 'com.google.android.gms:play-services-cronet'; +const String _embeddedDependencyName = 'org.chromium.net:cronet-embedded'; +const String _packageName = 'cronet_http_embedded'; +const String _packageDescription = 'An Android Flutter plugin that ' + 'provides access to the Cronet HTTP client. ' + 'Identical to package:cronet_http except that it embeds Cronet ' + 'rather than relying on Google Play Services.'; +final Uri _cronetVersionUri = Uri.https( + 'dl.google.com', + 'android/maven2/org/chromium/net/group-index.xml', +); + void main() async { - final latestVersion = await _getLatestVersion(); - _writeImplementationToTheFile(latestVersion); - _replaceREADME(); + if (Directory.current.path.endsWith('tool')) { + _directory = Directory.current.parent; + } else { + _directory = Directory.current; + } + + final latestVersion = await _getLatestCronetVersion(); + updateCronetDependency(latestVersion); + updatePubSpec(); + updateReadme(); } -Future _getLatestVersion() async { - final url = Uri.https( - 'dl.google.com', - 'android/maven2/org/chromium/net/group-index.xml', - ); - final response = await http.get(url); +Future _getLatestCronetVersion() async { + final response = await http.get(_cronetVersionUri); final parsedXml = XmlDocument.parse(response.body); final embeddedNode = parsedXml.children .singleWhere((e) => e is XmlElement) @@ -34,46 +66,37 @@ Future _getLatestVersion() async { return versions.last; } -void _writeImplementationToTheFile(String latestVersion) { - var dir = Directory.current; - if (dir.path.endsWith('tool')) { - dir = dir.parent; - } - // Update android/build.gradle - final fBuildGradle = File('${dir.path}/android/build.gradle'); +/// Update android/build.gradle +void updateCronetDependency(String latestVersion) { + final fBuildGradle = File('${_directory.path}/android/build.gradle'); final gradleContent = fBuildGradle.readAsStringSync(); final implementationRegExp = RegExp( '^\\s*implementation [\'"]' - 'com.google.android.gms:play-services-cronet' + '$_gmsDependencyName' ':\\d+.\\d+.\\d+[\'"]', multiLine: true, ); - final newImplementation = 'org.chromium.net:cronet-embedded:$latestVersion'; + final newImplementation = '$_embeddedDependencyName:$latestVersion'; print('Patching $newImplementation'); final newGradleContent = gradleContent.replaceAll( implementationRegExp, ' implementation $newImplementation', ); fBuildGradle.writeAsStringSync(newGradleContent); - // Update pubspec.yaml - final fPubspec = File('${dir.path}/pubspec.yaml'); +} + +/// Update pubspec.yaml +void updatePubSpec() { + final fPubspec = File('${_directory.path}/pubspec.yaml'); final yamlEditor = YamlEditor(fPubspec.readAsStringSync()) - ..update(['name'], 'cronet_http_embedded') - ..update( - ['description'], - 'An Android Flutter plugin that ' - 'provides access to the Cronet HTTP client. ' - 'Identical to package:cronet_http except that it embeds Cronet ' - 'rather than relying on Google Play Services.', - ); + ..update(['name'], _packageName) + ..update(['description'], _packageDescription); fPubspec.writeAsStringSync(yamlEditor.toString()); } -void _replaceREADME() { - var dir = Directory.current; - if (dir.path.endsWith('tool')) { - dir = dir.parent; - } - File('${dir.path}/README.md').deleteSync(); - File('${dir.path}/README_EMBEDDED.md').renameSync('${dir.path}/README.md'); +/// Move README_EMBEDDED.md to replace README.md +void updateReadme() { + File('${_directory.path}/README.md').deleteSync(); + File('${_directory.path}/README_EMBEDDED.md') + .renameSync('${_directory.path}/README.md'); } From ada32093c7d89170c142d8f8503462ac7fd216c9 Mon Sep 17 00:00:00 2001 From: Alex Li Date: Fri, 17 Feb 2023 08:21:50 +0800 Subject: [PATCH 9/9] =?UTF-8?q?=F0=9F=8E=A8=20Address=20review?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pkgs/cronet_http/README_EMBEDDED.md | 2 +- .../tool/prepare_for_embedded.dart | 50 ++++++++++--------- 2 files changed, 27 insertions(+), 25 deletions(-) diff --git a/pkgs/cronet_http/README_EMBEDDED.md b/pkgs/cronet_http/README_EMBEDDED.md index db948d821c..ebc84ded77 100644 --- a/pkgs/cronet_http/README_EMBEDDED.md +++ b/pkgs/cronet_http/README_EMBEDDED.md @@ -9,4 +9,4 @@ rather than using the version included with [Google Play Services](https://developers.google.com/android/guides/overview). This increases the uncompressed size of the application by approximately 8MB. -See more details about the cronet_http at: https://pub.dev/packages/cronet_http. +See more details about cronet_http at: https://pub.dev/packages/cronet_http. diff --git a/pkgs/cronet_http/tool/prepare_for_embedded.dart b/pkgs/cronet_http/tool/prepare_for_embedded.dart index efa0da32d2..89dce19ef0 100644 --- a/pkgs/cronet_http/tool/prepare_for_embedded.dart +++ b/pkgs/cronet_http/tool/prepare_for_embedded.dart @@ -1,47 +1,49 @@ // Copyright (c) 2022, the Dart project authors. Please see the AUTHORS file // for details. All rights reserved. Use of this source code is governed by a // BSD-style license that can be found in the LICENSE file. -// ignore_for_file: lines_longer_than_80_chars - -import 'dart:io'; - -import 'package:http/http.dart' as http; -import 'package:xml/xml.dart'; -import 'package:yaml_edit/yaml_edit.dart'; /// The cronet_http directory is used to produce two packages: /// - `cronet_http`, which uses the Google Play Services version of Cronet. /// - `cronet_http_embedded`, which embeds Cronet. /// -/// The default configuration of this code is to use the Google Play Services version of Cronet. +/// The default configuration of this code is to use the +/// Google Play Services version of Cronet. /// /// The script transforms the configuration into one that embeds Cronet by: -/// 1. Modifying the Gradle build file to reference the embedded version of Cronet. +/// 1. Modifying the Gradle build file to reference the embedded Cronet. /// 2. Modifying the *name* and *description* in `pubspec.yaml`. -/// 3. Replaying `README.md` with `README_EMBEDDED.md`. +/// 3. Replacing `README.md` with `README_EMBEDDED.md`. /// -/// After running this script, `flutter pub publish` can be run to update package:cronet_http_embedded. +/// After running this script, `flutter pub publish` +/// can be run to update package:cronet_http_embedded. /// /// NOTE: This script modifies the above files in place. -late final Directory _directory; -const String _gmsDependencyName = 'com.google.android.gms:play-services-cronet'; -const String _embeddedDependencyName = 'org.chromium.net:cronet-embedded'; -const String _packageName = 'cronet_http_embedded'; -const String _packageDescription = 'An Android Flutter plugin that ' +import 'dart:io'; + +import 'package:http/http.dart' as http; +import 'package:xml/xml.dart'; +import 'package:yaml_edit/yaml_edit.dart'; + +late final Directory _packageDirectory; + +const _gmsDependencyName = 'com.google.android.gms:play-services-cronet'; +const _embeddedDependencyName = 'org.chromium.net:cronet-embedded'; +const _packageName = 'cronet_http_embedded'; +const _packageDescription = 'An Android Flutter plugin that ' 'provides access to the Cronet HTTP client. ' 'Identical to package:cronet_http except that it embeds Cronet ' 'rather than relying on Google Play Services.'; -final Uri _cronetVersionUri = Uri.https( +final _cronetVersionUri = Uri.https( 'dl.google.com', 'android/maven2/org/chromium/net/group-index.xml', ); void main() async { if (Directory.current.path.endsWith('tool')) { - _directory = Directory.current.parent; + _packageDirectory = Directory.current.parent; } else { - _directory = Directory.current; + _packageDirectory = Directory.current; } final latestVersion = await _getLatestCronetVersion(); @@ -68,7 +70,7 @@ Future _getLatestCronetVersion() async { /// Update android/build.gradle void updateCronetDependency(String latestVersion) { - final fBuildGradle = File('${_directory.path}/android/build.gradle'); + final fBuildGradle = File('${_packageDirectory.path}/android/build.gradle'); final gradleContent = fBuildGradle.readAsStringSync(); final implementationRegExp = RegExp( '^\\s*implementation [\'"]' @@ -87,7 +89,7 @@ void updateCronetDependency(String latestVersion) { /// Update pubspec.yaml void updatePubSpec() { - final fPubspec = File('${_directory.path}/pubspec.yaml'); + final fPubspec = File('${_packageDirectory.path}/pubspec.yaml'); final yamlEditor = YamlEditor(fPubspec.readAsStringSync()) ..update(['name'], _packageName) ..update(['description'], _packageDescription); @@ -96,7 +98,7 @@ void updatePubSpec() { /// Move README_EMBEDDED.md to replace README.md void updateReadme() { - File('${_directory.path}/README.md').deleteSync(); - File('${_directory.path}/README_EMBEDDED.md') - .renameSync('${_directory.path}/README.md'); + File('${_packageDirectory.path}/README.md').deleteSync(); + File('${_packageDirectory.path}/README_EMBEDDED.md') + .renameSync('${_packageDirectory.path}/README.md'); }