Class: Fastlane::Helper::FlutterVersionHelper

Inherits:
Object
  • Object
show all
Defined in:
lib/fastlane/plugin/flutter_version/helper/flutter_version_helper.rb

Class Method Summary collapse

Class Method Details

.read_version_from_pubspecObject



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/fastlane/plugin/flutter_version/helper/flutter_version_helper.rb', line 6

def self.read_version_from_pubspec
  pubspec_path = 'pubspec.yaml'
  
  # Check if pubspec.yaml exists
  unless File.exist?(pubspec_path)
    UI.user_error!("Could not find pubspec.yaml in current directory")
    return nil
  end

  begin
    # Read and parse pubspec.yaml
    pubspec = YAML.load_file(pubspec_path)
    
    version_name = pubspec['version']&.split('+')&.first
    build_number = pubspec['version']&.split('+')&.last

    if version_name.nil? || build_number.nil?
      UI.user_error!("Could not find version information in pubspec.yaml")
      return nil
    end

    Fastlane::FlutterVersion::VersionInfo.new(version_name, build_number)
  rescue => e
    UI.error("Error reading pubspec.yaml: #{e.message}")
    return nil
  end
end