Class: Dongjia::SchemeManager

Inherits:
Object
  • Object
show all
Defined in:
lib/dongjia_scheme_manager.rb

Class Method Summary collapse

Class Method Details

.development_team(ctx) ⇒ Object

获取主工程的 development team



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/dongjia_scheme_manager.rb', line 8

def self.development_team(ctx)
  team = nil
  project = ctx.umbrella_targets.first.user_project
  return team unless project.is_a?(Xcodeproj::Project)

  target = project.targets.find { |t|
    !t.name.include?('企业版') && !t.name.end_with?('Extension')
  }
  return team unless target.is_a?(Xcodeproj::Project::PBXNativeTarget)

  build_cfg = target.build_configurations.find { |c| c.name == 'Debug' }
  return team unless build_cfg.is_a?(Xcodeproj::Project::XCBuildConfiguration)

  team = build_cfg.build_settings['DEVELOPMENT_TEAM']
end

.setup(ctx, params) ⇒ Object



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/dongjia_scheme_manager.rb', line 24

def self.setup(ctx, params)
  visibled_appspecs = params[:visibled_appspecs]
  # return if !visibled_appspecs || visibled_appspecs.empty?
  sandbox_root = ctx.sandbox_root
  
  team = development_team(ctx)
  
  Dir.foreach(sandbox_root).select{|f| f.end_with?('xcodeproj')}.each do |name|
    proj = Xcodeproj::Project.open(File.join(sandbox_root, name))
    proj.targets.each do | target |
      # 确保是 appspec
      next unless target.name.include?('-')
      # 确保是可执行程序
      next unless target.product_type == 'com.apple.product-type.application'

      # 设置签名信息
      if team.is_a?(String)
        target.build_configurations.first.build_settings['DEVELOPMENT_TEAM'] = team
        target.build_configurations.each { |cfg|
          cfg.build_settings['DEVELOPMENT_TEAM'] = team
        }
      end

      if visibled_appspecs.include?(target.name.split('-').first)
        # 将 visibled_appspecs 中指定的 target 设为可见状态
        proj.set_target_scheme_visible(target, true)
      end
    end
    proj.save if team.is_a?(String)
  end
end