Created
October 9, 2019 16:22
-
-
Save spidgorny/ed475cbbe303e1c09c0f6c9f9f57dcad to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import 'dart:convert'; | |
import "dart:io"; | |
import 'package:html/dom.dart'; | |
import 'package:html/parser.dart' as parser; | |
import "package:http/http.dart" as http; | |
import 'package:http/http.dart'; | |
import "package:yaml/yaml.dart"; | |
main() async { | |
File file = new File('pubspec.yaml'); | |
String yamlString = file.readAsStringSync(); | |
Map yaml = loadYaml(yamlString); | |
YamlMap dependencies = yaml['dependencies']; | |
// print(dependencies); | |
for (var key in dependencies.keys) { | |
var version = dependencies[key]; | |
if (version is String) { | |
var versionNumber = version.replaceFirst('^', ''); | |
print(key + ': ' + versionNumber); | |
Response html = await http.get('https://pub.dev/packages/' + key); | |
Document document = parser.parse(html.body); | |
var jsonScript = | |
document.querySelector('script[type="application/ld+json"]'); | |
var json = jsonDecode(jsonScript.innerHtml); | |
// print(json['version']); | |
if (json['version'].toString().compareTo(versionNumber) > 0) { | |
print(' => ' + json['version']); | |
} | |
} | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
It reads pubspec.yaml and check for the latest version of each dependency. | |
Example: | |
cupertino_icons: 0.1.2 | |
location: 2.3.5 | |
flutter_local_notifications: 0.8.4 | |
http: 0.12.0+1 | |
=> 0.12.0+2 | |
haversine: 1.0.2 | |
flutter_map: 0.1.4 | |
=> 0.7.3 | |
map_native: 0.0.11 | |
url_launcher: 5.1.4 | |
flutter_html_view: 0.5.12 | |
flutter_html: 0.8.2 | |
background_fetch: 0.2.0 | |
=> 0.3.2 | |
package_info: 0.4.0+2 | |
=> 0.4.0+6 | |
liquid_pull_to_refresh: 1.1.1 | |
provider: 3.0.0 | |
=> 3.1.0 | |
yaml: any | |
google_maps_flutter: 0.5.21+7 |
I've modified a little bit your script:
- you can specify a
pubspec.yml
file you want - prints changelog URL
- checks
dev_dependencies
too
Just puts the script into project/bin/outdated.dart
and run dart bin/outdated.dart pubspec.yml
/// @refs https://gist.github.com/spidgorny/ed475cbbe303e1c09c0f6c9f9f57dcad
import 'dart:convert';
import "dart:io";
import 'package:html/dom.dart';
import 'package:html/parser.dart' as parser;
import "package:http/http.dart" as http;
import 'package:http/http.dart';
import "package:yaml/yaml.dart";
main(List<String> arguments) async {
exitCode = 0;
String pubspec = arguments[0] ?? "pubspec.yml";
final Map yaml = loadYaml(File(pubspec).readAsStringSync());
final YamlMap dependencies = yaml["dependencies"];
final YamlMap devDependencies = yaml["dev_dependencies"];
await _check(dependencies);
if (devDependencies != null) await _check(devDependencies);
}
_check(YamlMap tree) async {
tree.forEach((name, version) async {
final String verNum = version.toString().replaceFirst('^', '');
String pubNum;
try {
pubNum = await _pubGet(name);
} catch(e) {
print("⚠️ Failed to check $name");
return;
}
if (verNum == pubNum) return;
print("$name $verNum => $pubNum (${_changeLogUrl(name)})");
});
}
Future<String> _pubGet(String name) async {
final Response html = await http.get("https://pub.dev/packages/$name");
final Document document = parser.parse(html.body);
final Element jsonScript = document.querySelector('script[type="application/ld+json"]');
final dynamic json = jsonDecode(jsonScript.innerHtml);
return json["version"].toString();
}
String _changeLogUrl(String name) {
return "https://pub.dev/packages/$name#-changelog-tab-";
}
Outputs:
cupertino_icons 0.1.2 => 0.1.3 (https://pub.dev/packages/cupertino_icons#-changelog-tab-)
simple_animations 1.3.8 => 1.3.9 (https://pub.dev/packages/simple_animations#-changelog-tab-)
percent_indicator 2.1.1 => 2.1.1+1 (https://pub.dev/packages/percent_indicator#-changelog-tab-)
flutter_secure_storage 3.3.1 => 3.3.1+1 (https://pub.dev/packages/flutter_secure_storage#-changelog-tab-)
shared_preferences 0.5.6 => 0.5.6+2 (https://pub.dev/packages/shared_preferences#-changelog-tab-)
crypto 2.1.3 => 2.1.4 (https://pub.dev/packages/crypto#-changelog-tab-)
flutter_i18n 0.10.0 => 0.10.1 (https://pub.dev/packages/flutter_i18n#-changelog-tab-)
pull_to_refresh 1.5.7 => 1.5.8 (https://pub.dev/packages/pull_to_refresh#-changelog-tab-)
⚠️ Failed to check flutter_test
test any => 1.14.2 (https://pub.dev/packages/test#-changelog-tab-)
⚠️ Failed to check flutter
⚠️ Failed to check flutter_driver
@shlima Great upgrade. Thank you.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This is free and unencumbered software released into the public domain.
Anyone is free to copy, modify, publish, use, compile, sell, or
distribute this software, either in source code form or as a compiled
binary, for any purpose, commercial or non-commercial, and by any
means.
In jurisdictions that recognize copyright laws, the author or authors
of this software dedicate any and all copyright interest in the
software to the public domain. We make this dedication for the benefit
of the public at large and to the detriment of our heirs and
successors. We intend this dedication to be an overt act of
relinquishment in perpetuity of all present and future rights to this
software under copyright law.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
OTHER DEALINGS IN THE SOFTWARE.
For more information, please refer to http://unlicense.org/