mergeFlavorAssets method
Merges flavor-specific assets with the main assets directory.
If a flavor is specified and the flavor directory exists, copies flavor-specific assets to the main assets directory before processing.
Parameters:
config: The asset configuration
Returns validation result indicating success or failure.
Implementation
ValidationResult mergeFlavorAssets(AssetConfig config) {
if (config.flavor == null || config.flavor!.isEmpty) {
return ValidationResult.success();
}
final flavorPath = config.getFlavorPath();
if (flavorPath == null || !exists(flavorPath)) {
return ValidationResult.success(
warnings: [
ValidationWarning(
message:
'Flavor directory not found: ${flavorPath ?? config.flavorDir}/${config.flavor}',
type: ValidationWarningType.general,
),
],
suggestions: [
'Create the flavor directory: ${config.flavorDir}/${config.flavor}',
'Ensure the flavor name is correct',
'Check that flavor_dir is properly configured in morpheme.yaml',
],
);
}
try {
final assetsPath = config.getAssetsPath();
copyTree(flavorPath, assetsPath, overwrite: true);
return ValidationResult.success();
} catch (e) {
return ValidationResult.failure(
errors: [
ValidationError(
message: 'Failed to merge flavor assets: $e',
type: ValidationErrorType.fileSystem,
),
],
suggestions: [
'Check file permissions for flavor and assets directories',
'Ensure sufficient disk space is available',
'Verify that both source and destination paths are valid',
],
);
}
}