class Pod::Podfile::AddSubModule

Constants

UI

Attributes

current_target_definition[RW]

@return [TargetDefinition] The current target definition to which the DSL

commands apply.

Public Class Methods

new(current_target_definition) click to toggle source
# File lib/cocoapods-hbh/command/sub_module/add_submodule.rb, line 14
def initialize(current_target_definition)
  @current_target_definition = current_target_definition
end

Public Instance Methods

get_info(info, key, default) click to toggle source

从 info map里获取key的值,如果未获取到 返回 default

# File lib/cocoapods-hbh/command/sub_module/add_submodule.rb, line 19
def get_info(info, key, default)
  if info.respond_to?("has_key?") && info.has_key?(key)
    return info[key]
  else
    return default
  end
end
pod_moudle(moduleName, *requirements) click to toggle source

添加模块 模块名称为podspec的名称,路径默认为Module/下的模块,tag或者branch 优先使用tag,默认develop分支 (moduleName, submodule: true, moduleTag: nil, moduleBranch: 'develop', appspecs: nil)

# File lib/cocoapods-hbh/command/sub_module/add_submodule.rb, line 30
def pod_moudle (moduleName, *requirements)
  info = requirements.last
  # git = get_info(info, :git, nil)
  
  
  # if git.blank?
  #   hbh_git = get_info(info, :hbh_git, nil)
  #   if moduleName.include?('/')
  #     name = moduleName.split('/').first
  #     requirements.last[:git] = "#{remoteUrl}/#{name}.git"
  #   else
  #     requirements.last[:git] = "#{remoteUrl}/#{moduleName}.git"
  #   end
  #   requirements.last.delete(:hbh_git)
  # end

  is_submodule = get_info(info, :submodule, true)
  if is_submodule 
    if info.nil? then raise "请输入正确的参数" end
    return requirements unless info.is_a?(Hash) 

    moduleTag = get_info(info, :tag, nil)
    moduleBranch = get_info(info, :branch, "develop")
    appspecs = get_info(info, :appspecs, nil)
    sub_config = HBHConfig.config.submodule_env
    remoteUrl = sub_config['sub_url'] 
    if remoteUrl.blank?
      Pod::UI.puts "请配置subModule的sub_url".red
      raise "注意: 请配置subModule的sub_url"
    end
    moduleRoot = sub_config['sub_path'].blank? ? "Modules" : sub_config['sub_path']

    path_module = "./#{moduleRoot}/#{moduleName}"
    Pod::UI.puts "#{moduleName}使用本地Pod模块".yellow
    if !File.exist?("#{path_module}/#{moduleName}.podspec")
      `git submodule add #{remoteUrl}#{moduleName}.git ./Modules/#{moduleName}`
      Pod::UI.puts "本地没有#{moduleName}模块,正在下载中..."
      # 设置主项目`git pull`操作时,子git自动执行 `git pull`
      `git config submodule.recurse true`

      # 设置主项目`git push`操作时,子项目自动执行 `git push`
      # `git config push.recurseSubmodules on-demand`
      
      if system "git submodule update --init --recursive" 
        Pod::UI.puts "#{moduleName}模块下载完成...".yellow
      end
    end
    if moduleTag != nil and !moduleTag.empty?
      `cd #{path_module} && git fetch && git checkout #{moduleTag}`    
     else
      `cd #{path_module} && git fetch && git checkout #{moduleBranch} && git pull origin #{moduleBranch}`
    end
    if appspecs != nil 
      sub_hash = {:path => path_module, :appspecs => ['Example']}
      last_index = requirements.length-1
      requirements[last_index] = requirements[last_index].merge(sub_hash)
      current_target_definition.store_pod moduleName, *requirements
      # pod moduleName,
    else
      sub_hash = {:path => path_module}
      last_index = requirements.length-1
      requirements[last_index] = requirements[last_index].merge(sub_hash)
      current_target_definition.store_pod moduleName, *requirements
      # pod moduleName,
    end
  else
    Pod::UI.puts "#{moduleName}使用远程模块".yellow
    current_target_definition.store_pod moduleName, *requirements

    # if moduleTag != nil
    #     pod moduleName, :git => "#{remoteUrl}#{moduleName}.git", :tag => moduleTag
    # else
    #     pod moduleName, :git => "#{remoteUrl}#{moduleName}.git", :branch => moduleBranch
    # end
  end
end