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
|