Class: Pindo::Command::Ios::Cert

Inherits:
Pindo::Command::Ios show all
Includes:
Appselect
Defined in:
lib/pindo/command/ios/cert.rb

Constant Summary

Constants inherited from Pindo::Command

DEFAULT_OPTIONS, DEFAULT_ROOT_OPTIONS

Instance Attribute Summary

Attributes inherited from Pindo::Command

#args_help_flag

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Appselect

#all_deploy_bundle_name, #all_dev_bundle_name, #all_dev_bundleid, #all_itc_bundleid, #all_release_bundleid, #all_tool_bundleid, #deploy_build_setting_json, #dev_build_setting_json, #get_deploy_repo_with_modul_name, #get_deploy_setting_repo, #get_dev_setting_repo, #get_selected_deploy_bundle_name, #get_selected_deploy_bundleid, #get_selected_dev_bundle_name, #get_selected_dev_bundleid, #get_setting_bundleid_withdir, #load_setting, #select_main_app

Methods inherited from Pindo::Command

command_name, #initialize_options, run, use_cache?

Methods included from Funlog::Mixin

#pindo_log_instance

Methods included from Pindoconfig::Mixin

#pindo_single_config

Methods included from HelpValidator

#validate!

Constructor Details

#initialize(argv) ⇒ Cert

Returns a new instance of Cert.



73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
# File 'lib/pindo/command/ios/cert.rb', line 73

def initialize(argv)
  # 使用 Options 模块初始化参数
  @options = initialize_options(argv)

  # 构建类型快捷参数
  @args_dev_flag = @options[:dev]
  @args_adhoc_flag = @options[:adhoc]
  @args_release_flag = @options[:release]
  @args_develop_id_flag = @options[:develop_id]
  @args_macos_flag = @options[:macos]

  # 证书参数
  @config_file = @options[:config]
  @clean_flag = @options[:clean]
  @cleangit_flag = @options[:cleangit]
  @renew_flag = @options[:renew]
  @match_flag = @options[:match]
  @upload_flag = @options[:upload]
  @cert_mode = @options[:cert_mode]
  @storage = @options[:storage]

  # iOS cert 命令默认使用 Custom + HTTPS 模式
  @cert_mode ||= 'custom'
  @storage ||= 'https'

  # 根据快捷参数确定构建类型
  @build_type = @options[:build_type]

  # 参数优先级:--develop_id > --release > --adhoc > --dev > 用户指定的 build_type > 默认 dev
  if @args_develop_id_flag
    @build_type = 'developer_id'
  elsif @args_release_flag
    @build_type = 'appstore'
  elsif @args_adhoc_flag
    @build_type = 'adhoc'
  elsif @args_dev_flag
    @build_type = 'dev'
  elsif @build_type.nil? || @build_type.empty?
    @build_type = 'dev'
  end
  # 如果用户明确指定了 --build_type,则保持用户指定的值

  # 标准化构建类型(dev -> development, release -> appstore)
  @build_type = Pindo::Options::BuildOptions.normalize_build_type(@build_type)

  # 处理平台类型
  @platform_type = @options[:platform]
  if @args_macos_flag
    @platform_type = 'macos'
  end

  # macOS 平台特殊处理(向后兼容:adhoc → developer_id)
  if @platform_type == 'macos' && @build_type == 'adhoc'
    @build_type = 'developer_id'
  end

  super
end

Class Method Details

.option_itemsObject

定义此命令使用的参数项



61
62
63
64
65
66
# File 'lib/pindo/command/ios/cert.rb', line 61

def self.option_items
  @option_items ||= Pindo::Options::OptionGroup.merge(
    Pindo::Options::BuildOptions.select(:build_type, :dev, :adhoc, :release, :develop_id),
    Pindo::Options::CertOptions.all
  )
end

.optionsObject

命令的选项列表



69
70
71
# File 'lib/pindo/command/ios/cert.rb', line 69

def self.options
  option_items.map { |item| item.to_claide_option }.concat(super)
end

Instance Method Details

#runObject



133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
# File 'lib/pindo/command/ios/cert.rb', line 133

def run
  # ============================================
  # 1. 前置处理:获取 Bundle ID 和拉取配置
  # ============================================

  # 根据构建类型选择 Bundle ID
  mainapp_bundleid = nil
  if @build_type == 'development'
    mainapp_bundleid = get_selected_dev_bundleid()
  else
    # adhoc、appstore、developer_id 使用发布 bundle id
    mainapp_bundleid = get_selected_deploy_bundleid()
  end

  # 拉取应用配置
  require 'pindo/config/build_info_manager'
  Pindo::BuildInfoManager.share_instance.pull_appconfig_with_reponame(
    repo_name: mainapp_bundleid,
    target_dir: Dir.pwd
  )

  project_dir = Dir.pwd
  Dir.chdir(project_dir)

  # 加载配置到 IosConfigParser
  require 'pindo/config/ios_config_parser'
  config_json_file = @config_file || File.join(project_dir, "config.json")
  Pindo::IosConfigParser.instance.load_config(config_file: config_json_file)

  # 处理 entitlements 配置
  Pindo::XcodeBuildConfig.update_entitlements_config(project_dir: project_dir)

  # 获取配置信息
  apple_id = Pindo::IosConfigParser.instance.apple_id
  bundle_id_array = Pindo::IosConfigParser.instance.get_bundle_id_array

  # ============================================
  # 2. 确定平台类型
  # ============================================

  # 如果用户没有指定平台类型,则自动检测
  if @platform_type.nil? || @platform_type.empty?
    @platform_type = detect_platform_type(project_dir)
  end

  # ============================================
  # 3. 清理操作(可选)
  # ============================================

  if @clean_flag
    Funlog.instance.fancyinfo("清理本地证书...")
    Pindo::CertHelper.clean_local_certs
  end

  if @renew_flag && @cleangit_flag
    pindo_config = Pindoconfig.instance
    Pindo::CertHelper.clean_git_certs(
      apple_id: apple_id,
      pindo_dir: pindo_config.pindo_dir,
      deploy_cert_giturl: pindo_config.deploy_cert_giturl,
      dev_cert_giturl: pindo_config.dev_cert_giturl,
      demo_apple_id: pindo_config.demo_apple_id
    )
  end

  # ============================================
  # 4. 执行证书操作(通过 CertHelper 门面)
  # ============================================

  # @build_type 已在 initialize 中标准化
  cert_type = @build_type

  if @renew_flag
    # 创建证书模式
    provisioning_info_array = Pindo::CertHelper.create_and_install_certs(
      cert_mode: @cert_mode,
      storage: @storage,
      apple_id: apple_id,
      bundle_id_array: bundle_id_array,
      cert_type: cert_type,
      platform_type: @platform_type,
      match_flag: @match_flag
    )
  else
    # 获取证书模式(默认)
    provisioning_info_array = Pindo::CertHelper.fetch_and_install_certs(
      cert_mode: @cert_mode,
      storage: @storage,
      apple_id: apple_id,
      bundle_id_array: bundle_id_array,
      cert_type: cert_type,
      platform_type: @platform_type,
      project_dir: project_dir,
      match_flag: @match_flag
    )
  end

  # ============================================
  # 5. 后置处理:生成上传测试平台的证书(可选)
  # ============================================

  if @upload_flag
    Pindo::CertHelper.create_upload_cert_info(
      apple_id: apple_id,
      cert_type: cert_type,
      platform_type: @platform_type
    )
    Pindo::CertHelper.create_upload_provisioning_info(
      apple_id: apple_id,
      cert_type: cert_type,
      platform_type: @platform_type,
      provisioning_info_array: provisioning_info_array
    )
  end

  Funlog.instance.fancyinfo_success("证书安装和配置完成!")
end