exportActiveVersion method
Copies the current complete publication to a new static-host directory.
destination must not exist and must not overlap the artifact store.
Implementation
Future<void> exportActiveVersion(Directory destination) async {
final active = await activeVersion;
if (active == null) throw StateError('No artifact version is published.');
final source = _versionDir(active).absolute;
final target = destination.absolute;
final sourcePath = _normalizedFileSystemPath(source.path);
final targetPath = _normalizedFileSystemPath(target.path);
final rootPath = _normalizedFileSystemPath(root.absolute.path);
if (_isSameOrInside(sourcePath, targetPath) ||
_isSameOrInside(targetPath, sourcePath) ||
_isSameOrInside(targetPath, rootPath) ||
_isSameOrInside(rootPath, targetPath)) {
throw ArgumentError('Export destination must not overlap the store.');
}
if (await target.exists()) {
throw StateError('Export destination already exists.');
}
await target.create(recursive: true);
final entries = await _loadRouteArtifacts(source);
if (entries.isNotEmpty) {
for (final entry in entries.values) {
final objFile = File(
'${_objectsDir.path}${Platform.pathSeparator}${entry.objectHash}.html',
);
if (await objFile.exists()) {
final content = await objFile.readAsString();
await _writeFile(_artifactFile(target, entry.path), content);
}
}
final sitemap = File(
'${source.path}${Platform.pathSeparator}sitemap.xml',
);
if (await sitemap.exists()) {
await sitemap.copy(
'${target.path}${Platform.pathSeparator}sitemap.xml',
);
}
final manifest = File(
'${source.path}${Platform.pathSeparator}route-manifest.json',
);
if (await manifest.exists()) {
await manifest.copy(
'${target.path}${Platform.pathSeparator}route-manifest.json',
);
}
} else {
await _copyPublicDirectory(source, target);
}
}