Class: Pindo::Command::Appstore::Cert

Inherits:
Pindo::Command::Appstore show all
Defined in:
lib/pindo/command/appstore/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 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.



58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
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
# File 'lib/pindo/command/appstore/cert.rb', line 58

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]
  @build_type = @options[:build_type]
  @platform_type = @options[:platform]
  @clean_flag = @options[:clean]
  @clean_git_flag = @options[:cleangit]
  @renew_cert_flag = @options[:renew]
  @match_flag = @options[:match]
  @upload_flag = @options[:upload]
  @cert_mode = @options[:cert_mode]
  @storage = @options[:storage]

  # appstore cert 命令默认值
  @cert_mode ||= 'match'           # 默认使用 Match 模式
  @storage ||= 'git'               # 默认使用 Git 存储

  # 参数优先级:--develop_id > --release > --adhoc > --dev > 用户指定的 build_type > 默认 appstore
  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 = 'appstore'
  end
  # 如果用户明确指定了 --build_type,则保持用户指定的值

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

  # 处理平台类型
  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

定义此命令使用的参数项



46
47
48
49
50
51
# File 'lib/pindo/command/appstore/cert.rb', line 46

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

命令的选项列表



54
55
56
# File 'lib/pindo/command/appstore/cert.rb', line 54

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

Instance Method Details

#runObject



115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
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
# File 'lib/pindo/command/appstore/cert.rb', line 115

def run
  # ============================================
  # 1. 前置处理:配置加载和清理逻辑
  # ============================================

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

  # 加载配置文件
  config_file_path = @config_file || File.join(Dir.pwd, "config.json")
  @config_parser = Pindo::IosConfigParser.instance
  @config_parser.load_config(config_file: config_file_path)

  # 获取配置信息
  @apple_id = @config_parser.apple_id
  @group_id = @config_parser.group_id
  @icloud_id = @config_parser.icloud_id

  # 清理本地证书
  if @clean_flag
    puts "清理本地证书..."
    Pindo::CertHelper.clean_local_certs
  end

  # 清理远程 Git 证书
  if @renew_cert_flag && @clean_git_flag
    Pindo::CertHelper.clean_git_certs(
      apple_id: @apple_id,
      pindo_dir: pindo_single_config.pindo_dir,
      deploy_cert_giturl: pindo_single_config.deploy_cert_giturl,
      dev_cert_giturl: pindo_single_config.dev_cert_giturl,
      demo_apple_id: pindo_single_config.demo_apple_id
    )
  end

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

  bundle_id_array = @config_parser.get_bundle_id_array

  if @renew_cert_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: Dir.pwd,
      match_flag: @match_flag
    )
  end

  # 验证证书信息
  if provisioning_info_array.nil? || provisioning_info_array.empty?
    raise Informative, "未找到证书信息"
  end

  @team_id_value = provisioning_info_array.first["team_id"]

  # ============================================
  # 3. 后置处理:生成上传测试平台的证书
  # ============================================

  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

  puts "✓ 证书配置完成!"
end