createCloneAssetsDirectory function
Creates an assets directory for a new clone and copies default assets into it.
This function first creates the ./clonify/clones/[clientId]/assets directory.
Then, it copies a predefined set of assets (specified in clonifySettings.assets)
from the main project's ./assets/images directory into the new clone's
asset directory.
clientId The ID of the client for which the assets directory is being created.
Throws a FileSystemException if the source assets directory does not exist or if files cannot be copied.
Implementation
bool createCloneAssetsDirectory(String clientId, List<String> assets) {
try {
//create assets directory for the clone
final assetsDir = Directory('./clonify/clones/$clientId/assets');
assetsDir.createSync(recursive: true);
final sourceDir = Directory('./assets/images');
final targetDir = Directory('./clonify/clones/$clientId/assets');
if (!sourceDir.existsSync()) {
throw FileSystemException(
'Assets directory does not exist',
sourceDir.path,
);
}
targetDir.createSync(recursive: true);
for (final asset in assets) {
final sourceFile = File('${sourceDir.path}/$asset');
final targetFile = File('${targetDir.path}/$asset');
sourceFile.copySync(targetFile.path);
}
logger.i('✅ Assets directory created successfully.');
return true;
} catch (e) {
logger.e('❌ Error during assets directory creation: $e');
return false;
}
}