writeTo method

Future<void> writeTo(
  1. Uri directoryUri
)

Implementation

Future<void> writeTo(Uri directoryUri) async {
  final dir = Directory.fromUri(directoryUri);
  final libDir = Directory.fromUri(dir.uri.resolve("lib/"));
  final srcDir = Directory.fromUri(libDir.uri.resolve("src/"));
  if (!libDir.existsSync()) {
    libDir.createSync(recursive: true);
  }
  if (!srcDir.existsSync()) {
    srcDir.createSync(recursive: true);
  }

  final libraryFile =
      File.fromUri(libDir.uri.resolve("generated_runtime.dart"));
  await libraryFile.writeAsString(loaderSource);

  final pubspecFile = File.fromUri(dir.uri.resolve("pubspec.yaml"));
  await pubspecFile.writeAsString(pubspecSource);

  await Future.forEach(_elements, (_RuntimeElement e) async {
    final file = File.fromUri(srcDir.uri.resolveUri(e.relativeUri));
    if (!file.parent.existsSync()) {
      file.parent.createSync(recursive: true);
    }

    await file.writeAsString(e.source);
  });
}