write static method
Write bundle under baseDir. Immutable objects (b/<version>/…) are
written only if absent — re-publishing identical content is a no-op.
The channel head is written last (after every immutable object), so a
reader never sees a head pointing at an incomplete bundle.
Implementation
static BundleWriteResult write(String baseDir, Bundle bundle) {
final versionDir = p.join(baseDir, 'b', bundle.version);
final manifestPath = p.join(versionDir, 'manifest.json');
final alreadyPublished = File(manifestPath).existsSync();
final written = <String>[];
if (!alreadyPublished) {
Directory(versionDir).createSync(recursive: true);
File(manifestPath).writeAsStringSync(bundle.manifestJson);
written.add(p.join(bundle.versionDir, 'manifest.json'));
for (final l in bundle.locales) {
File(p.join(versionDir, l.file)).writeAsStringSync(l.content);
written.add(p.join(bundle.versionDir, l.file));
}
}
final headPath = p.join(baseDir, 'manifest.json');
final head = bundle.channelHeadJson;
final headChanged =
!File(headPath).existsSync() ||
File(headPath).readAsStringSync() != head;
if (headChanged) {
Directory(baseDir).createSync(recursive: true);
File(headPath).writeAsStringSync(head);
}
return BundleWriteResult(
alreadyPublished: alreadyPublished,
filesWritten: written,
headUpdated: headChanged,
);
}