Module: Pindo::Options::BundleIdSelector

Defined in:
lib/pindo/options/helpers/bundleid_selector.rb

Class Method Summary collapse

Class Method Details

.load_bundleid_groupHash

加载 all_bundleid_group 映射表

Returns:

  • (Hash)

    group_name => bundle_id 的映射,如 => “com.heroneverdie101.fancyapptest”



99
100
101
102
103
104
105
106
107
108
109
110
# File 'lib/pindo/options/helpers/bundleid_selector.rb', line 99

def self.load_bundleid_group
  config_file = File.join(pindo_env_configdir, 'bundleid_config.json')
  return {} unless File.exist?(config_file)

  begin
    config = JSON.parse(File.read(config_file))
    config['all_bundleid_group'] || {}
  rescue => e
    puts "加载 bundleid_config.json 失败: #{e.message}"
    {}
  end
end

.load_deploy_bundleidsObject

加载发布环境的 Bundle ID 列表



80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
# File 'lib/pindo/options/helpers/bundleid_selector.rb', line 80

def self.load_deploy_bundleids
  bundleids = []

  # 从配置文件加载
  config_file = File.join(pindo_env_configdir, 'bundleid_config.json')
  if File.exist?(config_file)
    begin
      config = JSON.parse(File.read(config_file))
      bundleids |= config['all_release_bundleid'] if config['all_release_bundleid']
    rescue => e
      puts "加载 bundleid_config.json 失败: #{e.message}"
    end
  end

  bundleids
end

.load_dev_bundleidsObject

加载开发环境的 Bundle ID 列表



61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
# File 'lib/pindo/options/helpers/bundleid_selector.rb', line 61

def self.load_dev_bundleids
  bundleids = []

  # 从配置文件加载
  config_file = File.join(pindo_env_configdir, 'bundleid_config.json')
  if File.exist?(config_file)
    begin
      config = JSON.parse(File.read(config_file))
      bundleids |= config['all_dev_bundleid'] if config['all_dev_bundleid']
      bundleids |= config['all_tool_bundleid'] if config['all_tool_bundleid']
    rescue => e
      puts "加载 bundleid_config.json 失败: #{e.message}"
    end
  end

  bundleids
end

.pindo_env_configdirObject

获取 pindo 环境配置目录



123
124
125
126
127
128
# File 'lib/pindo/options/helpers/bundleid_selector.rb', line 123

def self.pindo_env_configdir
  require_relative '../../config/pindoconfig'
  Pindoconfig.instance.pindo_env_configdir
rescue
  File.join(Dir.home, '.pindo', 'config')
end

.resolve_bundleid_by_group_name(group_name) ⇒ String?

通过 group name 查找真实 bundle ID

Parameters:

  • group_name (String)

    组名(如 “fancyapptest”、“wildcarddevelopmentid”)

Returns:

  • (String, nil)

    真实 bundle ID(如 “com.heroneverdie101.fancyapptest”),未找到返回 nil



115
116
117
118
119
120
# File 'lib/pindo/options/helpers/bundleid_selector.rb', line 115

def self.resolve_bundleid_by_group_name(group_name)
  return nil if group_name.nil? || group_name.empty?

  group = load_bundleid_group
  group[group_name]
end

.select_bundleid(build_type) ⇒ String?

选择 Bundle ID(根据构建类型)

Parameters:

  • build_type (String)

    构建类型(支持标准化和未标准化的值)

Returns:

  • (String, nil)

    选择的 Bundle ID



9
10
11
12
13
14
15
16
17
18
19
# File 'lib/pindo/options/helpers/bundleid_selector.rb', line 9

def self.select_bundleid(build_type)
  build_type_lower = build_type.to_s.downcase

  # 判断是否为开发环境(development/dev)
  if build_type_lower == 'development' || build_type_lower == 'dev'
    select_dev_bundleid
  else
    # adhoc、appstore、release、developer_id 都使用发布 bundle id
    select_deploy_bundleid
  end
end

.select_deploy_bundleidString

选择发布环境的 Bundle ID

Returns:

  • (String)

    选择的 Bundle ID



32
33
34
35
36
37
# File 'lib/pindo/options/helpers/bundleid_selector.rb', line 32

def self.select_deploy_bundleid
  all_bundleid = load_deploy_bundleids
  return nil if all_bundleid.empty?

  select_from_list(all_bundleid, "发布环境")
end

.select_dev_bundleidString

选择开发环境的 Bundle ID

Returns:

  • (String)

    选择的 Bundle ID



23
24
25
26
27
28
# File 'lib/pindo/options/helpers/bundleid_selector.rb', line 23

def self.select_dev_bundleid
  all_bundleid = load_dev_bundleids
  return nil if all_bundleid.empty?

  select_from_list(all_bundleid, "开发环境")
end

.select_from_list(bundleid_list, env_name) ⇒ Object

从列表中选择 Bundle ID



42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/pindo/options/helpers/bundleid_selector.rb', line 42

def self.select_from_list(bundleid_list, env_name)
  cli = HighLine.new
  puts
  puts "可用的Bundle Id如下::"

  bundleid_list.each_with_index do |bundleid, index|
    puts "#{index + 1}. #{bundleid}"
  end

  choice = cli.ask("请选择使用的Bundle Id,请输入选项(1/2/3...):", Integer) do |q|
    q.in = 1..bundleid_list.size
  end

  selected = bundleid_list[choice - 1]
  puts "已选择 #{env_name} Bundle ID: #{selected}\n"
  selected
end