fromUrls static method

Future<InteropProject> fromUrls({
  1. required String package,
  2. required String version,
  3. required Iterable<String> urls,
  4. required String targetPath,
  5. required String dirName,
  6. String? contextCheck,
  7. Iterable<String> distFiles = const [],
  8. List<String> uses = const [],
  9. String? targetMainFile,
  10. bool force = false,
})

Implementation

static Future<InteropProject> fromUrls(
    {required String package,
    required String version,
    required Iterable<String> urls,
    required String targetPath,
    required String dirName,
    String? contextCheck,
    Iterable<String> distFiles = const [],
    List<String> uses = const [],
    String? targetMainFile,
    bool force = false}) async {
  final transpiller = Transpiler(
      package: package,
      targetPath: targetPath,
      dirName: dirName,
      contextCheck: contextCheck,
      uses: uses,
      targetMainFile: targetMainFile,
      distFiles: distFiles.toList());
  final dir = transpiller.dir;
  final fileArgs = <String>[];

  await Directory(dir('download')).create(recursive: true);

  for (var x = 0; x < urls.length; x++) {
    final url = urls.elementAt(x);
    final uri = Uri.parse(url);
    final name = basename(uri.path);
    final filePath = dir('download/$x$name');
    final file = File(filePath);

    if (force || !file.existsSync()) {
      final buf = await http.read(uri);

      file.writeAsStringSync(buf);
    }

    fileArgs.add(filePath);
  }

  return transpiller._createProject(fileArgs: fileArgs, crawlTsFiles: false);
}