Sha256: a6418d90c3f7fa2570be60ca8db4564484f968f410fbe1469a1d588019951f05

Contents?: true

Size: 1.66 KB

Versions: 568

Compression:

Stored size: 1.66 KB

Contents

module Fastlane
  module Helper
    class DotenvHelper
      # @param env_cl_param [String] an optional list of dotenv environment names separated by commas, without space
      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

      # finds the first directory of [fastlane, its parent] containing dotenv files
      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

      # loads the dotenvs. First the .env and .env.default and
      # then override with all speficied extra environments
      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
    end
  end
end

Version data entries

568 entries across 568 versions & 5 rubygems

Version Path
fastlane-2.95.0.beta.20180508050130 fastlane/lib/fastlane/helper/dotenv_helper.rb
fastlane-2.95.0.beta.20180507050125 fastlane/lib/fastlane/helper/dotenv_helper.rb
fastlane-2.95.0.beta.20180506050030 fastlane/lib/fastlane/helper/dotenv_helper.rb
fastlane-2.95.0.beta.20180505050019 fastlane/lib/fastlane/helper/dotenv_helper.rb
fastlane-2.95.0.beta.20180504050050 fastlane/lib/fastlane/helper/dotenv_helper.rb
fastlane-2.95.0.beta.20180503050136 fastlane/lib/fastlane/helper/dotenv_helper.rb
fastlane-2.95.0.beta.20180502050125 fastlane/lib/fastlane/helper/dotenv_helper.rb
fastlane-2.94.0 fastlane/lib/fastlane/helper/dotenv_helper.rb
fastlane-2.94.0.beta.20180501050030 fastlane/lib/fastlane/helper/dotenv_helper.rb
fastlane-2.94.0.beta.20180430050033 fastlane/lib/fastlane/helper/dotenv_helper.rb
fastlane-2.94.0.beta.20180429050039 fastlane/lib/fastlane/helper/dotenv_helper.rb
fastlane-2.94.0.beta.20180428050023 fastlane/lib/fastlane/helper/dotenv_helper.rb
fastlane-2.94.0.beta.20180427050031 fastlane/lib/fastlane/helper/dotenv_helper.rb
fastlane-2.94.0.beta.20180426050049 fastlane/lib/fastlane/helper/dotenv_helper.rb
fastlane-2.94.0.beta.20180425050017 fastlane/lib/fastlane/helper/dotenv_helper.rb
fastlane-2.93.1 fastlane/lib/fastlane/helper/dotenv_helper.rb
fastlane-2.94.0.beta.20180424050050 fastlane/lib/fastlane/helper/dotenv_helper.rb
fastlane-2.93.0 fastlane/lib/fastlane/helper/dotenv_helper.rb
fastlane-2.93.0.beta.20180423050019 fastlane/lib/fastlane/helper/dotenv_helper.rb
fastlane-2.93.0.beta.20180422050034 fastlane/lib/fastlane/helper/dotenv_helper.rb