require 'cocoapods' require 'cocoapods-tdf-bin/native/podfile_env' module Pod class Podfile # TREAT_DEVELOPMENTS_AS_NORMAL = 'treat_developments_as_normal'.freeze module DSL def allow_prerelease! set_internal_hash_value(ALLOW_PRERELEASE, true) end def batch_pod_local(pods, path = "../../") pod_hash = Hash.new pods.each do |name| pod_hash[name] = [ :path => "#{path}#{name}" ] end if get_batch_local_pods.nil? set_internal_hash_value(BATCH_POD_LOCAL, pod_hash) else set_internal_hash_value(BATCH_POD_LOCAL, get_internal_hash_value(BATCH_POD_LOCAL).merge(pod_hash)) end end def batch_pod_remote(pods, branch , group = 'ios') pod_hash = Hash.new pods.each do |name| pod_hash[name] = [ :git => "git@git.2dfire.net:#{group}/#{name}.git", :branch => "#{branch}" ] end if get_batch_remote_pods.nil? set_internal_hash_value(BATCH_POD_REMOTE, pod_hash) else set_internal_hash_value(BATCH_POD_REMOTE, get_internal_hash_value(BATCH_POD_REMOTE).merge(pod_hash)) end end def pod(name = nil, *requirements) unless name raise StandardError, 'A dependency requires a name.' end local_pod_hash = get_batch_local_pods remote_pod_hash = get_batch_remote_pods if remote_pod_hash != nil requirements = remote_pod_hash[name].nil? ? requirements : remote_pod_hash[name]; end if local_pod_hash != nil requirements = local_pod_hash[name].nil? ? requirements : local_pod_hash[name]; end current_target_definition.store_pod(name, *requirements) end def use_binaries!(flag = true) set_internal_hash_value(USE_BINARIES, flag) end def use_binaries_with_spec_selector!(&block) raise Informative, '必须提供选择需要二进制组件的 block !' unless block_given? set_internal_hash_value(USE_BINARIES_SELECTOR, block) end def set_use_source_pods(pods) hash_pods_use_source = get_internal_hash_value(USE_SOURCE_PODS) || [] hash_pods_use_source += Array(pods) set_internal_hash_value(USE_SOURCE_PODS, hash_pods_use_source) end # 0 dev # 1 debug_iphoneos # 2 release_iphoneos # 需要在podfile_env 先定义 CONFIGURATION_ENV def set_configuration_env(env = "dev") set_internal_hash_value(CONFIGURATION_ENV, env) end end alias old_plugins plugins def plugins if ENV[USE_PLUGINS] env_plugins = ENV[USE_PLUGINS].split(',').each_with_object({}) do |name, result| result[name] = {} end env_plugins.merge!(old_plugins) else old_plugins end end def use_binaries_selector get_internal_hash_value(USE_BINARIES_SELECTOR, nil) end def allow_prerelease? get_internal_hash_value(ALLOW_PRERELEASE, false) || ENV[ALLOW_PRERELEASE] == 'true' end def use_binaries? get_internal_hash_value(USE_BINARIES, false) || ENV[USE_BINARIES] == 'true' end def get_batch_local_pods get_internal_hash_value(BATCH_POD_LOCAL) end def get_batch_remote_pods get_internal_hash_value(BATCH_POD_REMOTE) end def use_source_pods get_internal_hash_value(USE_SOURCE_PODS, []) + String(ENV[USE_SOURCE_PODS]).split('|').uniq end def configuration_env get_internal_hash_value(CONFIGURATION_ENV, "dev") || ENV[CONFIGURATION_ENV] == "dev" end private def valid_bin_plugin unless plugins.keys.include?('cocoapods-tdf-bin') raise Pod::Informative, 'You should add `plugin \'cocoapods-tdf-bin\'` before using its DSL' end end # set_hash_value 有 key 限制 def set_internal_hash_value(key, value) valid_bin_plugin internal_hash[key] = value end def get_internal_hash_value(key, default = nil) internal_hash.fetch(key, default) end end end