Module: Env

Defined in:
lib/autosparkle/environment/environment.rb

Overview

Environment module to load the environment variables It contains the app state

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.storageObject

Returns the value of attribute storage.



25
26
27
# File 'lib/autosparkle/environment/environment.rb', line 25

def storage
  @storage
end

.variablesObject

Returns the value of attribute variables.



25
26
27
# File 'lib/autosparkle/environment/environment.rb', line 25

def variables
  @variables
end

.verbose_enabledObject

Returns the value of attribute verbose_enabled.



25
26
27
# File 'lib/autosparkle/environment/environment.rb', line 25

def verbose_enabled
  @verbose_enabled
end

Class Method Details

.initialize(options, command) ⇒ Object



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/autosparkle/environment/environment.rb', line 27

def initialize(options, command)
  project_path = options.project_path
  workspace_path = options.workspace_path

  project_directory_path = File.dirname(workspace_path || project_path) if workspace_path || project_path
  ENV['PROJECT_DIRECTORY_PATH'] = project_directory_path

  load_environment(project_directory_path, options.env)

  @variables = DefaultEnvironmentVariables.new

  case command
  when Command::EXPORT
    initialize_export(options)
  when Command::PACKAGE
    initialize_package(options)
  when Command::DISTRIBUTE
    initialize_distribute(options)
  when Command::AUTOMATE
    initialize_automate(options)
  end

  puts_if_verbose "Running the script with the #{options.env} environment...\n"
end

.initialize_automate(options) ⇒ Object



69
70
71
72
73
74
# File 'lib/autosparkle/environment/environment.rb', line 69

def self.initialize_automate(options)
  retrieve_variables_from_xcode(options.project_path, options.workspace_path)

  @storage = retrieve_storage
  retreive_versions_variables_form_appcast(options)
end

.initialize_distribute(options) ⇒ Object



61
62
63
64
65
66
67
# File 'lib/autosparkle/environment/environment.rb', line 61

def self.initialize_distribute(options)
  ENV['APP_DISPLAY_NAME'] = options.app_display_name
  ENV['MINIMUM_MACOS_VERSION'] = options.minimum_macos_version

  @storage = retrieve_storage
  retreive_versions_variables_form_appcast(options)
end

.initialize_export(options) ⇒ Object



53
54
55
# File 'lib/autosparkle/environment/environment.rb', line 53

def self.initialize_export(options)
  retrieve_variables_from_xcode(options.project_path, options.workspace_path)
end

.initialize_package(options) ⇒ Object



57
58
59
# File 'lib/autosparkle/environment/environment.rb', line 57

def self.initialize_package(options)
  ENV['APP_DISPLAY_NAME'] = options.app_display_name
end

.load_environment(project_directory_path, env) ⇒ Object



76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
# File 'lib/autosparkle/environment/environment.rb', line 76

def self.load_environment(project_directory_path, env)
  env_is_file = File.file?(env)
  if !project_directory_path && !env_is_file
    raise 'Cannot find the project directory path to load the environment variables'
  end

  env_file_path = if env_is_file
                    env
                  else
                    File.join(project_directory_path, ".env.autosparkle.#{env}")
                  end

  ENV['ENV_FILE_PATH'] = env_file_path
  puts_if_verbose "Loading the environment variables from #{env_file_path}..."
  Dotenv.load(env_file_path)
end

.retreive_versions_variables_form_appcast(options) ⇒ Object



113
114
115
116
117
118
# File 'lib/autosparkle/environment/environment.rb', line 113

def self.retreive_versions_variables_form_appcast(options)
  marketing_version, current_project_version = AppcastXML.retreive_versions(@storage.deployed_appcast_xml)

  ENV['MARKETING_VERSION'] = options.marketing_version || marketing_version
  ENV['CURRENT_PROJECT_VERSION'] = options.current_project_version || current_project_version
end

.retrieve_storageObject



93
94
95
96
97
98
99
100
101
102
103
# File 'lib/autosparkle/environment/environment.rb', line 93

def self.retrieve_storage
  storage_type = ENV.fetch('STORAGE_TYPE', nil)
  raise 'Storage type is not defined in the environment' if storage_type.nil? || storage_type.empty?

  case storage_type
  when 'aws-s3'
    AwsS3Storage.new
  else
    raise "Storage type #{storage_type} is not supported"
  end
end

.retrieve_variables_from_xcode(project_path, workspace_path) ⇒ Object



105
106
107
108
109
110
111
# File 'lib/autosparkle/environment/environment.rb', line 105

def self.retrieve_variables_from_xcode(project_path, workspace_path)
  puts_if_verbose 'Fetching the minimum macOS version from the Xcode project...'
  ENV['MINIMUM_MACOS_VERSION'] = Xcodeproj.get_minimum_deployment_macos_version(project_path, workspace_path)

  puts_if_verbose 'Fetching the app display name from the Xcode project...'
  ENV['APP_DISPLAY_NAME'] = Xcodeproj.get_app_display_name(project_path, workspace_path)
end