replaceAssets function
Replaces the assets in the main project's assets directory with assets from a specific clone.
This function copies asset files from the ./clonify/clones/[clientId]/assets
directory to the main project's ./assets/images directory. This is used
to apply clone-specific branding and images to the active project.
clientId The ID of the client whose assets should be used for replacement.
Throws a FileSystemException if either the source or target asset directory does not exist. Logs errors if asset replacement fails.
Implementation
void replaceAssets(String clientId) {
try {
final sourceDir = Directory('./clonify/clones/$clientId/assets');
final targetDir = Directory('./assets/images');
if (!sourceDir.existsSync()) {
throw FileSystemException(
'Source Assets directory does not exist',
sourceDir.path,
);
}
if (!targetDir.existsSync()) {
throw FileSystemException(
'Target Assets directory does not exist',
targetDir.path,
);
}
final String splitBy = Platform.isWindows ? '\\' : '/';
for (final file in sourceDir.listSync()) {
if (file is File) {
final targetFile = File(
'${targetDir.path}/${file.path.split(splitBy).last}',
);
file.copySync(targetFile.path);
}
}
logger.i('✅ Assets replaced successfully.');
} catch (e) {
logger.e('❌ Error during asset replacement: $e');
}
}