getPubDevPlugins function

Future<List<Map<String, String>>> getPubDevPlugins (
  1. String url
)

Implementation

Future<List<Map<String, String>>> getPubDevPlugins(String url) async {
  // Config.ppLogger.v('getPubDevPlugins $url');
  // url ??= 'https://pub.dartlang.org/api/packages?q=_dartrix';
  url ??= 'https://pub.dev/dart/packages?q=dartrix';
  // response is map of two keys, next_url and packages
  var response = await http.get(url);
  // print('Response status: ${response.statusCode}');
  // print('Response body: ${response.body}');

  //RegExp
  var regexp = RegExp(r'packages/(.*?)(?=_dartrix)');
  // Iterable<RegExpMatch>
  var matches = regexp.allMatches(response.body);
  var pkgs = [
    for (var match in matches) match.group(1),
  ];
  var pset = Set.from(pkgs);
  if (Config.debug) {
    Config.logger.d('found ${pset.length} plugins on pub.dev');
  }

  // Config.ppLogger.v('$pset');
  //List<Map<String,String>>
  var result = await downloadPkgSpecs(pset);
  if (Config.debug) {
    Config.ppLogger.d('downloaded: $result');
  }

  return result;
  // var body = json.decode(response.body);
  // var pkgs = body['packages'];
  // // print('body: ${response.body}');
  // print('Response pkg count: ${pkgs.length}');
  // print('pkg 37: ${pkgs[37]}');
  // pkgs.forEach((pkg) => print(pkg['name']));
  // pkgs.retainWhere((pkg) {
  //   return pkg['name'].endsWith('_dartrix') ? true : false;
  // });
  // print('dartrix pkgs $pkgs,  rtt: ${pkgs.runtimeType}');
  // // pkgs.toList().sort((a, b) => (a.name.compareTo(b.name)) as int);
  // pkgs.forEach((pkg) => print('pkg $pkg'));
  // if (body['next_url'] != null) {
  //   getPubDevPlugins(body['next_url'+ '?q=dartrix']);
  // }
  // return pkgs;
}