writeToDirectory method
Compile all modules and write the output files under outputDir.
Missing parent directories are created automatically. Existing files are overwritten.
pubspec.yaml, pubspec.lock, and other package manifest files are
restored from the embedded __assets__ module (written by
PackageEncoder._collectResources).
Returns the list of written file paths (relative to outputDir).
Implementation
List<String> writeToDirectory(Directory outputDir) {
final files = compileToMap();
final written = <String>[];
for (final MapEntry(key: relPath, value: source) in files.entries) {
final file = File(
'${outputDir.path}${Platform.pathSeparator}'
'${relPath.replaceAll('/', Platform.pathSeparator)}',
);
file.parent.createSync(recursive: true);
file.writeAsStringSync(source);
written.add(relPath);
}
// Extract embedded assets — includes pubspec.yaml, pubspec.lock, and
// any other non-Dart files captured during encoding.
written.addAll(_extractResources(outputDir));
return written;
}