Class: Pindo::Command::Appstore::Updateid
Constant Summary
DEFAULT_OPTIONS, DEFAULT_ROOT_OPTIONS
Instance Attribute Summary
#args_help_flag
Class Method Summary
collapse
Instance Method Summary
collapse
command_name, #initialize_options, run, use_cache?
#pindo_log_instance
#pindo_single_config
Constructor Details
#initialize(argv) ⇒ Updateid
Returns a new instance of Updateid.
67
68
69
70
71
72
73
74
|
# File 'lib/pindo/command/appstore/updateid.rb', line 67
def initialize(argv)
positional_config = argv.shift_argument
@options = initialize_options(argv)
@config_path = @options[:config] || positional_config || File.join(Dir.pwd, 'config.json')
@dry_run = @options[:dry_run]
super
@additional_args = argv.remainder!
end
|
Class Method Details
.option_items ⇒ Object
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
|
# File 'lib/pindo/command/appstore/updateid.rb', line 43
def self.option_items
@option_items ||= [
Pindo::Options::OptionItem.new(
key: :config,
description: '指定config.json文件路径',
type: String,
optional: true,
example: 'pindo appstore updateid --config=config.json'
),
Pindo::Options::OptionItem.new(
key: :dry_run,
description: '预览模式,只显示差异不修改文件',
type: :boolean,
optional: true,
default_value: false,
example: 'pindo appstore updateid --dry-run'
)
]
end
|
.options ⇒ Object
63
64
65
|
# File 'lib/pindo/command/appstore/updateid.rb', line 63
def self.options
option_items.map { |item| item.to_claide_option }.concat(super)
end
|
Instance Method Details
#run ⇒ Object
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
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
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
|
# File 'lib/pindo/command/appstore/updateid.rb', line 100
def run
begin
app_info = @config_json['app_info']
apple_id = @config_json.dig('account_info', 'apple_acount_id')
puts "Login #{apple_id}..."
Spaceship.login(apple_id.to_s)
Spaceship.select_team
bundle_id = app_info['app_identifier']
puts
puts "读取 #{bundle_id} 的 Capability..."
capabilities = Pindo::BundleIdHelper.fetch_capabilities_from_portal(bundle_id: bundle_id)
if capabilities.nil?
puts "无法读取 #{bundle_id} 的 Capability,跳过"
return
end
capabilities.each do |key, value|
puts " #{key}: #{value.is_a?(String) ? "\"#{value}\"" : value}"
end
puts
extension_keys = app_info.keys.select { |k| k.start_with?("app_identifier_") }
extension_keys.each do |key|
ext_bundle_id = app_info[key]
next if ext_bundle_id.nil? || ext_bundle_id.empty? || ext_bundle_id.include?("__________")
expected_name = Pindo::BundleIdHelper.generate_bundleid_name(ext_bundle_id)
ext_app = Spaceship::Portal.app.find(ext_bundle_id)
if ext_app.nil?
puts " #{ext_bundle_id} — Portal 中未找到,跳过"
next
end
if ext_app.name != expected_name
puts "Update #{ext_bundle_id} name: #{ext_app.name} -> #{expected_name}"
begin
ext_app.update_name!(expected_name)
rescue => e
puts " Portal 更新名称失败: #{e.message},尝试通过 API Key 更新..."
begin
Pindo::BundleIdHelper.update_bundleid_name(bundle_id: ext_bundle_id, new_name: expected_name)
rescue => e2
puts " 更新名称失败: #{e2.message}"
end
end
end
end
if @dry_run
old_capabilities = app_info['capabilities'] || {}
puts
puts "[dry-run] 差异:"
has_diff = false
capabilities.each do |key, new_value|
old_value = old_capabilities[key]
if old_value.nil?
puts " + #{key}: #{new_value.is_a?(String) ? "\"#{new_value}\"" : new_value}"
has_diff = true
elsif old_value != new_value
old_display = old_value.is_a?(String) ? "\"#{old_value}\"" : old_value
new_display = new_value.is_a?(String) ? "\"#{new_value}\"" : new_value
puts " ~ #{key}: #{old_display} -> #{new_display}"
has_diff = true
end
end
old_capabilities.each do |key, old_value|
unless capabilities.key?(key)
old_display = old_value.is_a?(String) ? "\"#{old_value}\"" : old_value
puts " = #{key}: #{old_display} (保留)"
has_diff = true
end
end
puts " (无差异)" unless has_diff
puts
puts "[dry-run] 未修改任何文件"
else
app_config_dir = Pindo::GitHandler.clong_buildconfig_repo(repo_name: bundle_id)
config_repo_file = File.join(app_config_dir, "config.json")
Pindo::GitHandler.git!(%W(-C #{app_config_dir} checkout -- config.json)) rescue nil
repo_config_json = JSON.parse(File.read(config_repo_file))
repo_config_json['app_info']['capabilities'] = (repo_config_json['app_info']['capabilities'] || {}).merge(capabilities)
File.open(config_repo_file, "w") do |f|
f.write(JSON.pretty_generate(repo_config_json) + "\n")
end
if File.expand_path(@config_path) != File.expand_path(config_repo_file)
@config_json['app_info']['capabilities'] = (app_info['capabilities'] || {}).merge(capabilities)
File.open(@config_path, "w") do |f|
f.write(JSON.pretty_generate(@config_json) + "\n")
end
end
puts
Pindo::GitHandler.git_addpush_repo(
path: app_config_dir,
message: "sync capabilities from Apple Developer Portal",
commit_file_params: ["config.json"]
)
puts "capabilities 已写入 config.json 并提交"
end
rescue StandardError => e
puts "\n updateid 失败: #{e.message}"
raise e
end
end
|
#validate! ⇒ Object
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
|
# File 'lib/pindo/command/appstore/updateid.rb', line 76
def validate!
super
unless File.exist?(@config_path)
help! "配置文件不存在: #{@config_path}"
end
begin
@config_json = JSON.parse(File.read(@config_path))
rescue JSON::ParserError => e
help! "配置文件格式错误: #{e.message}"
end
app_info = @config_json['app_info']
if app_info.nil? || app_info['app_identifier'].nil? || app_info['app_identifier'].empty?
help! "config.json 中缺少 app_info.app_identifier"
end
apple_id = @config_json.dig('account_info', 'apple_acount_id')
if apple_id.nil? || apple_id.empty? || apple_id.include?("__________")
help! "config.json 中缺少有效的 Apple ID (account_info.apple_acount_id)"
end
end
|