generateFilename method
Generates a validated filename based on the template and variables.
Throws ReleaseManagerException if unknown placeholders are used. Automatically sanitizes illegal filesystem characters.
Implementation
String generateFilename(String template, TemplateVariables variables) {
_validateTemplate(template);
final now = DateTime.now();
// Map placeholders to their computed values
final Map<String, String> replacements = {
'project': variables.project ?? 'unknown',
'version': variables.version ?? '0.0.0',
'flutter_build': variables.flutterBuild ?? '0',
'counter': variables.counter ?? '001',
'env': variables.env ?? 'LOCAL',
'platform': variables.platform ?? 'generic',
'artifact': variables.artifact ?? 'bin',
'branch': variables.branch ?? 'main',
'commit': variables.commit ?? '0000000',
'date': DateFormat('yyyyMMdd').format(now),
'time': DateFormat('HHmmss').format(now),
'datetime': DateFormat('yyyyMMdd_HHmmss').format(now),
'year': DateFormat('yyyy').format(now),
'month': DateFormat('MM').format(now),
'day': DateFormat('dd').format(now),
};
String result = template;
for (final entry in replacements.entries) {
result = result.replaceAll('{${entry.key}}', entry.value);
}
return _sanitizeFilename(result);
}