FlutterReleaseXAppConfigModel.fromYaml constructor
FlutterReleaseXAppConfigModel.fromYaml(
- dynamic yamlPath
Implementation
factory FlutterReleaseXAppConfigModel.fromYaml(dynamic yamlPath) {
final yamlMap = Map<String, dynamic>.from(yamlPath);
// Parse legacy pipeline_steps
List<PipelineStepModel>? legacySteps;
if (yamlMap['pipeline_steps'] != null) {
try {
legacySteps = List<PipelineStepModel>.from(
(yamlMap['pipeline_steps'] as List).map(
(step) =>
PipelineStepModel.fromYaml(Map<String, dynamic>.from(step)),
),
);
} catch (e) {
print('⚠️ Warning: Failed to parse "pipeline_steps": $e');
print(
' Ensure pipeline_steps is a list of steps, each with "name" and "command".');
}
}
// Parse new pipelines map
Map<String, PipelineModel>? namedPipelines;
if (yamlMap['pipelines'] != null) {
try {
final pipelinesYaml =
Map<String, dynamic>.from(yamlMap['pipelines'] as Map);
namedPipelines = {};
for (final entry in pipelinesYaml.entries) {
final pipelineData = Map<String, dynamic>.from(entry.value as Map);
namedPipelines[entry.key] =
PipelineModel.fromYaml(entry.key, pipelineData);
}
} catch (e) {
print('⚠️ Warning: Failed to parse "pipelines": $e');
print(
' Ensure pipelines is a map of named pipelines, each with "steps".');
print(' Example:');
print(' pipelines:');
print(' build:');
print(' description: "Build the app"');
print(' steps:');
print(' - name: "Build APK"');
print(' command: "flutter build apk --release"');
}
}
// Show helpful message if both formats are detected
if (legacySteps != null && namedPipelines != null) {
print(
'💡 Both "pipeline_steps" and "pipelines" found in config. Using "pipelines" (the new format).');
print(
' Consider migrating your "pipeline_steps" to the "pipelines" format for better organization.');
}
// Parse hooks config
HooksConfigModel? hooksConfig;
if (yamlMap['hooks'] != null) {
try {
hooksConfig = HooksConfigModel.fromYaml(yamlMap['hooks'] as Map? ?? {});
} catch (e) {
print('⚠️ Warning: Failed to parse "hooks": $e');
print(
' Ensure hooks is a map of hook names (e.g. pre-commit) with steps.');
}
}
return FlutterReleaseXAppConfigModel(
flutterPath: yamlMap['flutter_path'],
uploadOptions: UploadOptionsModel.fromYaml(yamlMap['upload_options']),
qrCode: QrCodeModel.fromYaml(yamlMap['qr_code']),
pipelineSteps: legacySteps,
pipelines: namedPipelines,
hooks: hooksConfig,
);
}