Class: Fastlane::Helper::DotenvHelper

Inherits:
Object
  • Object
show all
Defined in:
fastlane/lib/fastlane/helper/dotenv_helper.rb

Class Method Summary collapse

Class Method Details

.find_dotenv_directoryObject

finds the first directory of [fastlane, its parent] containing dotenv files


14
15
16
17
18
19
20
21
22
# File 'fastlane/lib/fastlane/helper/dotenv_helper.rb', line 14

def self.find_dotenv_directory
  path = FastlaneCore::FastlaneFolder.path
  search_paths = [path]
  search_paths << path + "/.." unless path.nil?
  search_paths.compact!
  search_paths.find do |dir|
    Dir.glob(File.join(dir, '*.env*'), File::FNM_DOTMATCH).count > 0
  end
end

.load_dot_env(env_cl_param) ⇒ Object

Parameters:

  • env_cl_param (String)

    an optional list of dotenv environment names separated by commas, without space


5
6
7
8
9
10
11
# File 'fastlane/lib/fastlane/helper/dotenv_helper.rb', line 5

def self.load_dot_env(env_cl_param)
  base_path = find_dotenv_directory

  return unless base_path

  load_dot_envs_from(env_cl_param, base_path)
end

.load_dot_envs_from(env_cl_param, base_path) ⇒ Object

loads the dotenvs. First the .env and .env.default and then override with all speficied extra environments


26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'fastlane/lib/fastlane/helper/dotenv_helper.rb', line 26

def self.load_dot_envs_from(env_cl_param, base_path)
  require 'dotenv'

  # Making sure the default '.env' and '.env.default' get loaded
  env_file = File.join(base_path, '.env')
  env_default_file = File.join(base_path, '.env.default')
  Dotenv.load(env_file, env_default_file)

  return unless env_cl_param

  Fastlane::Actions.lane_context[Fastlane::Actions::SharedValues::ENVIRONMENT] = env_cl_param

  # multiple envs?
  envs = env_cl_param.split(",")

  # Loads .env file for the environment(s) passed in through options
  envs.each do |env|
    env_file = File.join(base_path, ".env.#{env}")
    UI.success("Loading from '#{env_file}'")
    Dotenv.overload(env_file)
  end
end