Class: Pindo::Command::Appstore::Autoresign

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

Methods included from Funlog::Mixin

#pindo_log_instance

Methods included from Pindoconfig::Mixin

#pindo_single_config

Constructor Details

#initialize(argv) ⇒ Autoresign

Returns a new instance of Autoresign.



116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
# File 'lib/pindo/command/appstore/autoresign.rb', line 116

def initialize(argv)
  # 首先获取位置参数(向后兼容)
  positional_ipa = argv.shift_argument

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

  # 优先使用选项参数,如果没有则使用位置参数
  @args_ipa_file = @options[:ipa] || positional_ipa
  @args_build_type = (@options[:type] || 'adhoc').downcase
  @args_upload_flag = @options[:send] || @options[:upload]
  @args_send_flag = @options[:send]
  @args_proj_name = @options[:proj]

  super
  @additional_args = argv.remainder!
end

Class Method Details

.option_itemsObject

定义此命令使用的参数项



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
# File 'lib/pindo/command/appstore/autoresign.rb', line 67

def self.option_items
  @option_items ||= begin
    items = []

    # 添加 --ipa 参数
    items << Pindo::Options::OptionItem.new(
      key: :ipa,
      description: '指定要重签名的 IPA 文件路径',
      type: String,
      optional: true,
      verify_block: proc do |value|
        unless value.end_with?('.ipa')
          raise "IPA 文件路径格式错误: #{value},必须以 .ipa 结尾"
        end
        unless File.exist?(value)
          raise "IPA 文件不存在: #{value}"
        end
      end,
      example: 'pindo appstore autoresign --ipa=path/to/demo.ipa'
    )

    # 添加 --type 参数
    items << Pindo::Options::OptionItem.new(
      key: :type,
      description: '构建类型(dev/adhoc,默认 adhoc)。dev=使用dev证书+测试BundleID,adhoc=使用adhoc证书+发布BundleID',
      type: String,
      default_value: 'adhoc',
      optional: true,
      verify_block: proc do |value|
        valid_types = ['dev', 'adhoc']
        unless valid_types.include?(value.to_s.downcase)
          raise "构建类型错误: #{value},必须是 dev 或 adhoc"
        end
      end,
      example: 'pindo appstore autoresign --type=dev'
    )

    # 合并 JPSOptions
    items.concat(Pindo::Options::JPSOptions.select(:proj, :upload, :send))

    items
  end
end

.optionsObject

命令的选项列表



112
113
114
# File 'lib/pindo/command/appstore/autoresign.rb', line 112

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

.use_cache?Boolean

启用缓存机制

Returns:

  • (Boolean)


24
25
26
# File 'lib/pindo/command/appstore/autoresign.rb', line 24

def self.use_cache?
  true
end

Instance Method Details

#runObject



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
# File 'lib/pindo/command/appstore/autoresign.rb', line 138

def run
  begin
    # 加载 JPS 配置(如果存在)
    Pindo::BuildHelper.share_instance.load_jps_build_config(Dir.pwd)

    # 1. 查找或指定 IPA 文件
    ipa_file_path = find_ipa_file()

    unless ipa_file_path && File.exist?(ipa_file_path)
      raise Informative, "未找到需要重签名的 IPA 文件"
    end

    # 2. 选择 Bundle ID(根据 build_type)
    bundle_id = select_bundle_id()

    # 3. 拉取应用配置
    pull_app_config(bundle_id)

    # 4. 准备 JPS 配置(如果需要上传)
    app_info_obj, workflow_info = prepare_jps_config()

    # 5. 计算重签名后的 IPA 文件名
    resigned_ipa_file = calculate_resigned_ipa_name(ipa_file_path)

    # 6. 创建任务
    tasks = create_resign_tasks(
      ipa_file_path: ipa_file_path,
      resigned_ipa_file: resigned_ipa_file,
      bundle_id: bundle_id,
      app_info_obj: app_info_obj,
      workflow_info: workflow_info
    )

    # 7. 执行任务
    task_manager = Pindo::TaskSystem::TaskManager.instance
    task_manager.clear_all
    tasks.each { |task| task_manager.add_task(task) }
    task_manager.start

  ensure
    # 清除命令状态(如果启用了缓存,这里会自动保存)
    Pindo::Options::GlobalOptionsState.instance.clear
  end
end

#validate!Object



134
135
136
# File 'lib/pindo/command/appstore/autoresign.rb', line 134

def validate!
  super
end