pindo 5.2.4 → 5.3.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (36) hide show
  1. checksums.yaml +4 -4
  2. data/lib/pindo/base/aeshelper.rb +23 -2
  3. data/lib/pindo/base/pindocontext.rb +259 -0
  4. data/lib/pindo/client/pgyer_feishu_oauth_cli.rb +343 -80
  5. data/lib/pindo/client/pgyerclient.rb +30 -20
  6. data/lib/pindo/command/android/autobuild.rb +52 -22
  7. data/lib/pindo/command/android/build.rb +27 -16
  8. data/lib/pindo/command/android/debug.rb +25 -15
  9. data/lib/pindo/command/dev/debug.rb +2 -51
  10. data/lib/pindo/command/dev/feishu.rb +19 -2
  11. data/lib/pindo/command/ios/adhoc.rb +2 -1
  12. data/lib/pindo/command/ios/autobuild.rb +35 -8
  13. data/lib/pindo/command/ios/debug.rb +2 -132
  14. data/lib/pindo/command/lib/lint.rb +24 -1
  15. data/lib/pindo/command/setup.rb +24 -4
  16. data/lib/pindo/command/unity/apk.rb +15 -0
  17. data/lib/pindo/command/unity/ipa.rb +16 -0
  18. data/lib/pindo/command.rb +13 -2
  19. data/lib/pindo/module/android/android_build_config_helper.rb +425 -0
  20. data/lib/pindo/module/android/apk_helper.rb +23 -25
  21. data/lib/pindo/module/android/base_helper.rb +572 -0
  22. data/lib/pindo/module/android/build_helper.rb +8 -318
  23. data/lib/pindo/module/android/gp_compliance_helper.rb +668 -0
  24. data/lib/pindo/module/android/gradle_helper.rb +746 -3
  25. data/lib/pindo/module/appselect.rb +18 -5
  26. data/lib/pindo/module/build/buildhelper.rb +120 -29
  27. data/lib/pindo/module/build/unityhelper.rb +675 -18
  28. data/lib/pindo/module/build/versionhelper.rb +146 -0
  29. data/lib/pindo/module/cert/certhelper.rb +33 -2
  30. data/lib/pindo/module/cert/xcodecerthelper.rb +3 -1
  31. data/lib/pindo/module/pgyer/pgyerhelper.rb +114 -31
  32. data/lib/pindo/module/xcode/xcodebuildconfig.rb +232 -0
  33. data/lib/pindo/module/xcode/xcodebuildhelper.rb +0 -1
  34. data/lib/pindo/version.rb +356 -86
  35. data/lib/pindo.rb +72 -3
  36. metadata +5 -1
@@ -21,72 +21,12 @@ module Pindo
21
21
  end
22
22
  end
23
23
 
24
+ # 该方法已迁移到 Pindo::AndroidBuildConfigHelper.add_test_scheme
25
+ # 保留代理方法以兼容旧调用
24
26
  def add_test_scheme(project_dir:nil, scheme_name:nil)
25
- puts "正在为Android项目添加自定义scheme: #{scheme_name}"
26
- puts "项目路径: #{project_dir}, 当前工作目录: #{Dir.pwd}"
27
-
28
- # 参数验证
29
- return puts "错误: 需要提供scheme名称" if scheme_name.nil?
30
- return puts "错误: 需要提供项目路径" if project_dir.nil?
31
- return puts "错误: 项目路径不存在: #{project_dir}" unless File.directory?(project_dir)
32
-
33
- # scheme_name = scheme_name.to_s.downcase.strip.gsub(/[\s\-_]/, '')
34
- scheme_name = scheme_name.to_s.gsub(/[^a-zA-Z0-9]/, '').downcase
35
- # 查找所有可能的模块
36
- main_module = get_main_module(project_dir)
37
- search_modules = ["app", "unityLibrary"]
38
- search_modules << main_module if main_module
39
- search_modules = search_modules.compact.uniq
40
-
41
- puts "搜索的模块: #{search_modules.join(', ')}"
42
-
43
- # 查找所有可能的AndroidManifest.xml文件
44
- manifest_candidates = find_manifests(project_dir, search_modules)
45
-
46
- if manifest_candidates.empty?
47
- return puts "错误: 未找到任何AndroidManifest.xml文件"
48
- end
49
-
50
- puts "找到#{manifest_candidates.size}个AndroidManifest.xml文件"
51
-
52
- # 寻找最佳的AndroidManifest.xml和Activity
53
- manifest_path, main_activity, android_prefix = find_best_activity(manifest_candidates)
54
-
55
- if manifest_path.nil? || main_activity.nil?
56
- return puts "错误: 无法找到合适的Activity"
57
- end
58
-
59
- puts "已选择 #{manifest_path} 文件中的 #{main_activity['android:name'] || '主Activity'}"
60
-
61
- # 检查scheme是否已存在
62
- scheme_exists, existing_scheme = check_scheme_exists(main_activity, android_prefix, scheme_name)
63
-
64
- # 如果scheme已存在,检查是否需要更新格式
65
- if scheme_exists
66
- activity_name = main_activity["#{android_prefix}:name"] || "主Activity"
67
- if existing_scheme != scheme_name
68
- # 格式不同,需要更新
69
- update_scheme = update_existing_scheme(manifest_path, main_activity, android_prefix, existing_scheme, scheme_name)
70
- if update_scheme
71
- puts "已将scheme从'#{existing_scheme}'更新为'#{scheme_name}'"
72
- else
73
- puts "尝试更新scheme格式失败,但scheme已存在: #{existing_scheme}"
74
- end
75
- else
76
- puts "scheme: #{scheme_name}已存在于#{activity_name}"
77
- end
78
- return
79
- end
80
-
81
- # 尝试添加scheme
82
- success = add_scheme_with_dom(manifest_path, main_activity, android_prefix, scheme_name)
83
-
84
- # 如果DOM操作失败,使用文本替换
85
- unless success
86
- add_scheme_with_text_replace(manifest_path, scheme_name)
87
- end
88
-
89
- puts "添加scheme操作完成,项目路径: #{project_dir}"
27
+ puts "Warning: add_test_scheme已迁移,请使用Pindo::AndroidBuildConfigHelper.add_test_scheme"
28
+ require_relative 'android_build_config_helper'
29
+ Pindo::AndroidBuildConfigHelper.add_test_scheme(project_dir: project_dir, scheme_name: scheme_name)
90
30
  end
91
31
 
92
32
  def auto_build_apk(project_dir, debug = false, ignore_sub = false)
@@ -180,259 +120,9 @@ module Pindo
180
120
  raise Informative, "准备项目失败: #{e.message}"
181
121
  end
182
122
 
183
- # 查找所有可能的AndroidManifest.xml文件
184
- def find_manifests(project_dir, modules)
185
- manifest_candidates = []
186
-
187
- # 搜索每个模块中的AndroidManifest.xml
188
- modules.each do |mod|
189
- mod_path = mod.is_a?(String) && !mod.start_with?(project_dir) ? File.join(project_dir, mod) : mod
190
-
191
- # 标准位置
192
- standard_manifest = File.join(mod_path, "src", "main", "AndroidManifest.xml")
193
- manifest_candidates << standard_manifest if File.exist?(standard_manifest)
194
-
195
- # 根目录
196
- root_manifest = File.join(mod_path, "AndroidManifest.xml")
197
- manifest_candidates << root_manifest if File.exist?(root_manifest)
198
- end
199
-
200
- # 项目根目录
201
- manifest_candidates << File.join(project_dir, "AndroidManifest.xml") if File.exist?(File.join(project_dir, "AndroidManifest.xml"))
202
- manifest_candidates << File.join(project_dir, "src/main/AndroidManifest.xml") if File.exist?(File.join(project_dir, "src/main/AndroidManifest.xml"))
203
-
204
- manifest_candidates.uniq
205
- end
206
-
207
- # 查找最佳的Activity
208
- def find_best_activity(manifest_candidates)
209
- require 'nokogiri'
210
-
211
- best_manifest = nil
212
- best_activity = nil
213
- android_prefix = nil
214
-
215
- manifest_candidates.each do |manifest_path|
216
- begin
217
- puts "检查: #{manifest_path}"
218
- doc = Nokogiri::XML(File.read(manifest_path))
219
-
220
- # 处理命名空间
221
- android_ns = 'http://schemas.android.com/apk/res/android'
222
- prefix = nil
223
-
224
- doc.root.namespace_definitions.each do |ns|
225
- if ns.href == android_ns
226
- prefix = ns.prefix
227
- break
228
- end
229
- end
230
-
231
- prefix ||= 'android'
232
-
233
- # 构建XPath查询
234
- ns_xpath = lambda do |xpath|
235
- xpath.gsub(/@android:/, "@#{prefix}:")
236
- .gsub(/\[@android:/, "[@#{prefix}:")
237
- end
238
-
239
- # 查找LAUNCHER Activity
240
- launcher_activities = doc.xpath(ns_xpath.call('//activity[intent-filter/category[@android:name="android.intent.category.LAUNCHER"]]'))
241
-
242
- if !launcher_activities.empty?
243
- best_manifest = manifest_path
244
- best_activity = launcher_activities.first
245
- android_prefix = prefix
246
- puts "找到带有LAUNCHER的Activity: #{best_activity['android:name']}"
247
- break
248
- elsif best_activity.nil?
249
- activities = doc.xpath('//activity')
250
- if !activities.empty?
251
- best_manifest = manifest_path
252
- best_activity = activities.first
253
- android_prefix = prefix
254
- puts "找到Activity(无LAUNCHER): #{best_activity['android:name']}"
255
- end
256
- end
257
- rescue => e
258
- puts "解析失败: #{e.message}"
259
- end
260
- end
261
-
262
- [best_manifest, best_activity, android_prefix]
263
- end
264
-
265
- # 检查scheme是否已存在
266
- def check_scheme_exists(activity, android_prefix, scheme_name)
267
- scheme_exists = false
268
- existing_scheme = nil
269
-
270
- # 首先检查完全一致的scheme
271
- activity.xpath("intent-filter/data[@#{android_prefix}:scheme='#{scheme_name}']").each do |node|
272
- scheme_exists = true
273
- existing_scheme = scheme_name
274
- break
275
- end
276
-
277
- # 如果没有找到完全一致的,检查可能格式不同的scheme
278
- if !scheme_exists
279
- # 查找所有scheme属性
280
- activity.xpath("intent-filter/data[@#{android_prefix}:scheme]").each do |node|
281
- current_scheme = node["#{android_prefix}:scheme"]
282
- normalized_current = current_scheme.to_s.downcase.strip.gsub(/[\s\-_]/, '')
283
-
284
- if normalized_current == scheme_name
285
- scheme_exists = true
286
- existing_scheme = current_scheme
287
- puts "发现格式不同但实质相同的scheme: '#{current_scheme}'"
288
- break
289
- end
290
- end
291
- end
292
-
293
- [scheme_exists, existing_scheme]
294
- end
295
-
296
- # 使用DOM操作添加scheme
297
- def add_scheme_with_dom(manifest_path, activity, android_prefix, scheme_name)
298
- begin
299
- doc = Nokogiri::XML(File.read(manifest_path))
300
-
301
- # 创建intent-filter
302
- intent_filter = doc.create_element('intent-filter')
303
-
304
- # 添加子元素
305
- intent_filter.add_child(create_element(doc, 'action', "#{android_prefix}:name", 'android.intent.action.VIEW'))
306
- intent_filter.add_child(create_element(doc, 'category', "#{android_prefix}:name", 'android.intent.category.DEFAULT'))
307
- intent_filter.add_child(create_element(doc, 'category', "#{android_prefix}:name", 'android.intent.category.BROWSABLE'))
308
- intent_filter.add_child(create_element(doc, 'data', "#{android_prefix}:scheme", scheme_name))
309
-
310
- # 添加空白和缩进
311
- activity.add_child(doc.create_text_node("\n "))
312
- activity.add_child(intent_filter)
313
- activity.add_child(doc.create_text_node("\n "))
314
-
315
- # 保存修改
316
- xml_content = doc.to_xml(indent: 2, encoding: 'UTF-8')
317
-
318
- # 验证修改是否成功
319
- if xml_content.include?("android:scheme=\"#{scheme_name}\"")
320
- File.write(manifest_path, xml_content)
321
- puts "DOM操作成功添加了scheme: #{scheme_name}"
322
- return true
323
- end
324
-
325
- puts "DOM操作未能添加scheme"
326
- return false
327
- rescue => e
328
- puts "DOM操作失败: #{e.message}"
329
- return false
330
- end
331
- end
332
-
333
- # 创建XML元素并设置属性
334
- def create_element(doc, name, attr_name, attr_value)
335
- element = doc.create_element(name)
336
- element[attr_name] = attr_value
337
- element
338
- end
339
-
340
- # 使用文本替换添加scheme
341
- def add_scheme_with_text_replace(manifest_path, scheme_name)
342
- begin
343
- # 读取原始内容
344
- xml_content = File.read(manifest_path)
345
-
346
- # 定义要添加的intent-filter
347
- scheme_intent_filter = %Q{
348
- <intent-filter>
349
- <action android:name="android.intent.action.VIEW"/>
350
- <category android:name="android.intent.category.DEFAULT"/>
351
- <category android:name="android.intent.category.BROWSABLE"/>
352
- <data android:scheme="#{scheme_name}"/>
353
- </intent-filter>}
354
-
355
- # 在</activity>前添加intent-filter
356
- if xml_content.match(/<\/activity>/)
357
- modified_xml = xml_content.gsub(/<\/activity>/) do |match|
358
- "#{scheme_intent_filter}\n #{match}"
359
- end
360
-
361
- # 保存修改
362
- File.write(manifest_path, modified_xml)
363
- puts "文本替换成功添加了scheme: #{scheme_name}"
364
- return true
365
- else
366
- puts "在XML中找不到</activity>标签"
367
- return false
368
- end
369
- rescue => e
370
- puts "文本替换失败: #{e.message}"
371
- return false
372
- end
373
- end
374
-
375
- def update_existing_scheme(manifest_path, activity, android_prefix, existing_scheme, scheme_name)
376
- begin
377
- doc = Nokogiri::XML(File.read(manifest_path))
378
-
379
- # 查找所有intent-filter
380
- intent_filters = doc.xpath("//intent-filter")
381
-
382
- intent_filters.each do |intent_filter|
383
- # 检查intent-filter中的scheme
384
- intent_filter.xpath("data[@#{android_prefix}:scheme]").each do |data|
385
- current_scheme = data["#{android_prefix}:scheme"]
386
- if current_scheme == existing_scheme
387
- # 找到intent-filter,更新scheme
388
- data["#{android_prefix}:scheme"] = scheme_name
389
- end
390
- end
391
- end
392
-
393
- # 保存修改
394
- xml_content = doc.to_xml(indent: 2, encoding: 'UTF-8')
395
-
396
- # 验证修改是否成功
397
- if xml_content.include?("android:scheme=\"#{scheme_name}\"")
398
- File.write(manifest_path, xml_content)
399
- puts "DOM操作成功更新了scheme: #{scheme_name}"
400
- return true
401
- end
402
-
403
- puts "DOM操作未能更新scheme,尝试文本替换方法"
404
- return update_scheme_with_text_replace(manifest_path, existing_scheme, scheme_name)
405
- rescue => e
406
- puts "DOM操作失败: #{e.message},尝试文本替换方法"
407
- return update_scheme_with_text_replace(manifest_path, existing_scheme, scheme_name)
408
- end
409
- end
410
-
411
- # 使用文本替换方法更新scheme
412
- def update_scheme_with_text_replace(manifest_path, existing_scheme, scheme_name)
413
- begin
414
- # 读取原始内容
415
- xml_content = File.read(manifest_path)
416
-
417
- # 使用正则表达式替换scheme值
418
- attribute_pattern = /android:scheme=["']#{Regexp.escape(existing_scheme)}["']/
419
-
420
- if xml_content.match(attribute_pattern)
421
- modified_xml = xml_content.gsub(attribute_pattern, "android:scheme=\"#{scheme_name}\"")
422
-
423
- # 保存修改
424
- File.write(manifest_path, modified_xml)
425
- puts "文本替换成功更新scheme: #{scheme_name}"
426
- return true
427
- else
428
- puts "在XML中找不到匹配的scheme属性"
429
- return false
430
- end
431
- rescue => e
432
- puts "文本替换更新失败: #{e.message}"
433
- return false
434
- end
435
- end
123
+ # 相关辅助方法已迁移到 Pindo::AndroidBuildConfigHelper
124
+ # find_manifests, find_best_activity, check_scheme_exists等方法已被移除
125
+ # 请使用 AndroidBuildConfigHelper 中的相应方法
436
126
  end
437
127
  end
438
128