createTimestampedBackup static method
Create a timestamped backup (for multiple backups)
Implementation
static Future<String?> createTimestampedBackup() async {
try {
final pubspecFile = File(FileConfig.pubspecFile);
if (!pubspecFile.existsSync()) {
throw Exception('${FileConfig.pubspecFile} not found');
}
// Create timestamped backup filename
final timestamp = DateTime.now()
.toIso8601String()
.replaceAll(':', '-')
.replaceAll('.', '-');
final timestampedBackupPath =
'${FileConfig.pubspecFile}.backup.$timestamp';
// Create backup
await pubspecFile.copy(timestampedBackupPath);
return timestampedBackupPath;
} catch (e) {
return null;
}
}