pindo 5.1.2 → 5.1.4

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.
@@ -48,6 +48,7 @@ module Pindo
48
48
  # 命令选项
49
49
  def self.options
50
50
  [
51
+ ['--bundleid', '指定打包的bundleID'],
51
52
  ['--proj', '指定上传到测试平台的项目名称'],
52
53
  ['--upload', '上传编译后的IPA到测试平台'],
53
54
  ['--send', '上传成功后发送测试通知'],
@@ -65,7 +66,7 @@ module Pindo
65
66
  @args_deploy_flag = argv.flag?('deploy', false)
66
67
  @args_base_flag = argv.flag?('base', false)
67
68
  @force_select_unity = argv.flag?('unity-version', false)
68
-
69
+ @args_bundle_id = argv.option('bundleid')
69
70
 
70
71
  if @args_send_flag
71
72
  @args_upload_flag = true
@@ -84,13 +85,13 @@ module Pindo
84
85
  unless unity_helper.unity_project?(pindo_project_dir)
85
86
  raise Informative, "当前目录不是Unity工程,请在Unity工程根目录下执行此命令"
86
87
  end
87
-
88
+
89
+ build_helper = Pindo::BuildHelper.share_instance
88
90
  if @args_upload_flag
89
- build_helper = Pindo::BuildHelper.share_instance
90
- is_need_add_tag,tag_action_parms = build_helper.check_is_need_add_tag?(pindo_project_dir)
91
- if is_need_add_tag
92
- Pindo::Command::Dev::Tag::run(tag_action_parms)
93
- end
91
+ is_need_add_tag,tag_action_parms = build_helper.check_is_need_add_tag?(pindo_project_dir)
92
+ if is_need_add_tag
93
+ Pindo::Command::Dev::Tag::run(tag_action_parms)
94
+ end
94
95
  end
95
96
 
96
97
  project_unity_version = unity_helper.get_unity_version(pindo_project_dir)
@@ -107,10 +108,14 @@ module Pindo
107
108
  end
108
109
 
109
110
  mainapp_bundleid= nil
110
- if @args_deploy_flag
111
- mainapp_bundleid = get_selected_deploy_bundleid()
111
+ if @args_bundle_id
112
+ mainapp_bundleid = @args_bundle_id
112
113
  else
113
- mainapp_bundleid = get_selected_dev_bundleid()
114
+ if @args_deploy_flag
115
+ mainapp_bundleid = get_selected_deploy_bundleid()
116
+ else
117
+ mainapp_bundleid = get_selected_dev_bundleid()
118
+ end
114
119
  end
115
120
 
116
121
  isLibrary = @args_base_flag
@@ -0,0 +1,152 @@
1
+ require 'highline/import'
2
+ require 'xcodeproj'
3
+ require 'find'
4
+ require 'fileutils'
5
+ require 'pindo/base/executable'
6
+ require 'pindo/module/build/unityhelper'
7
+ require 'pindo/module/build/buildhelper'
8
+
9
+ module Pindo
10
+ class Command
11
+ class Unity < Command
12
+ class Web < Unity
13
+
14
+ include Appselect
15
+
16
+ include Pindo::Githelper
17
+ # Unity IPA包编译和上传命令
18
+ self.summary = '编译Unity工程生成iOS IPA并支持上传到测试平台'
19
+
20
+ # 详细说明
21
+ self.description = <<-DESC
22
+ 编译Unity工程生成iOS IPA并支持上传到测试平台。
23
+
24
+ 支持功能:
25
+
26
+ * 编译生成IPA
27
+
28
+ * 上传到测试平台
29
+
30
+ * 发送测试通知
31
+
32
+ 使用示例:
33
+
34
+ $ pindo unity ipa # 编译IPA
35
+
36
+ $ pindo unity ipa --upload # 编译并上传
37
+
38
+ $ pindo unity ipa --send # 编译上传并发送通知
39
+
40
+ $ pindo unity ipa --proj=myapp # 指定项目名称
41
+ DESC
42
+
43
+ # 命令参数
44
+ self.arguments = [
45
+ # 暂无参数
46
+ ]
47
+
48
+ # 命令选项
49
+ def self.options
50
+ [
51
+ ['--proj', '指定上传到测试平台的项目名称'],
52
+ ['--upload', '上传编译后的IPA到测试平台'],
53
+ ['--send', '上传成功后发送测试通知'],
54
+ ['--base', 'Unity工程编译lib模式'],
55
+ ['--unity-version', '切换Unity版本']
56
+ ].concat(super)
57
+ end
58
+
59
+
60
+ def initialize(argv)
61
+
62
+ @args_proj_name = argv.option('proj')
63
+ @args_upload_flag = argv.flag?('upload', false)
64
+ @args_send_flag = argv.flag?('send', false)
65
+ @args_deploy_flag = argv.flag?('deploy', false)
66
+ @args_base_flag = argv.flag?('base', false)
67
+ @force_select_unity = argv.flag?('unity-version', false)
68
+
69
+
70
+ if @args_send_flag
71
+ @args_upload_flag = true
72
+ end
73
+
74
+ super
75
+ end
76
+
77
+
78
+ def run
79
+
80
+ pindo_project_dir = Dir.pwd
81
+
82
+ # 检查是否是Unity工程
83
+ unity_helper = Pindo::Client::UnityHelper.share_instance
84
+ unless unity_helper.unity_project?(pindo_project_dir)
85
+ raise Informative, "当前目录不是Unity工程,请在Unity工程根目录下执行此命令"
86
+ end
87
+
88
+ if @args_upload_flag
89
+ build_helper = Pindo::BuildHelper.share_instance
90
+ is_need_add_tag,tag_action_parms = build_helper.check_is_need_add_tag?(pindo_project_dir)
91
+ if is_need_add_tag
92
+ Pindo::Command::Dev::Tag::run(tag_action_parms)
93
+ end
94
+ end
95
+
96
+ project_unity_version = unity_helper.get_unity_version(pindo_project_dir)
97
+ puts
98
+ puts "工程的Unity版本: #{project_unity_version}"
99
+ unity_exe_path = unity_helper.find_unity_path(project_unity_version:project_unity_version, force_change_version: @force_select_unity)
100
+ puts "选择的Unity路径: #{unity_exe_path}"
101
+ puts
102
+
103
+ app_info_obj = nil
104
+ if @args_upload_flag
105
+ proj_name = @args_proj_name
106
+ app_info_obj = PgyerHelper.share_instace.prepare_upload(working_directory:Dir.pwd, proj_name:proj_name)
107
+ end
108
+
109
+ mainapp_bundleid= nil
110
+ if @args_deploy_flag
111
+ mainapp_bundleid = get_selected_deploy_bundleid()
112
+ else
113
+ mainapp_bundleid = get_selected_dev_bundleid()
114
+ end
115
+
116
+ isLibrary = @args_base_flag
117
+
118
+ ios_export_lib_dir = File.join(pindo_project_dir, "GoodPlatform/BaseiOS")
119
+ if File.directory?(ios_export_lib_dir)
120
+ isLibrary = true
121
+ end
122
+
123
+ pindo_ios_project_dir = File.join(pindo_project_dir, "GoodPlatform/iOS")
124
+ if isLibrary
125
+ pindo_ios_project_dir = ios_export_lib_dir
126
+ end
127
+ unity_helper.build_project(unity_exe_full_path:unity_exe_path, project_path:pindo_project_dir, platform:'iOS', isLibrary:isLibrary)
128
+
129
+
130
+ args_temp = []
131
+ args_temp << "--bundleid=#{mainapp_bundleid}"
132
+
133
+ if @args_upload_flag
134
+ args_temp << "--proj=#{app_info_obj["appName"]}"
135
+ args_temp << "--upload"
136
+ end
137
+ if @args_send_flag
138
+ args_temp << "--send"
139
+ end
140
+
141
+ Dir.chdir(pindo_ios_project_dir)
142
+
143
+ Pindo::Command::Ios::Autobuild::run(args_temp)
144
+
145
+
146
+ end
147
+
148
+
149
+ end
150
+ end
151
+ end
152
+ end
@@ -2,7 +2,7 @@
2
2
 
3
3
  require 'pindo/command/unity/ipa'
4
4
  require 'pindo/command/unity/apk'
5
-
5
+ require 'pindo/command/unity/autobuild'
6
6
 
7
7
  module Pindo
8
8
  class Command
@@ -7,6 +7,7 @@ require 'pindo/module/build/buildhelper'
7
7
  require 'pindo/module/webserver/brotli_file_handler'
8
8
  require 'pindo/module/webserver/webgl_page_handler'
9
9
  require 'pindo/module/webserver/responsive_preview_handler'
10
+ require 'pindo/module/webserver/webgl_server_helper'
10
11
  require 'webrick' # 添加WebRick HTTP服务器
11
12
  require 'socket'
12
13
 
@@ -66,170 +67,6 @@ module Pindo
66
67
  end
67
68
  end
68
69
 
69
-
70
- # 获取本机局域网IP地址
71
- def get_local_ip
72
- ip = nil
73
- Socket.ip_address_list.each do |addr_info|
74
- if addr_info.ipv4? && !addr_info.ipv4_loopback?
75
- ip = addr_info.ip_address
76
- break
77
- end
78
- end
79
- return ip || 'localhost'
80
- end
81
-
82
- # 启动HTTP服务器
83
- def start_http_server(webgl_dir, port)
84
- begin
85
- # 确保目录存在
86
- unless File.directory?(webgl_dir)
87
- UI.puts("错误: WebGL目录不存在: #{webgl_dir}")
88
- return nil
89
- end
90
-
91
- # 检查index.html是否存在
92
- if !File.exist?(File.join(webgl_dir, "index.html"))
93
- UI.puts("警告: WebGL目录中未找到index.html文件")
94
- end
95
-
96
- # 创建自定义日志格式器,只记录错误
97
- custom_log = [
98
- [:error, WEBrick::AccessLog::COMMON_LOG_FORMAT],
99
- ]
100
-
101
- # 采用直接的方法配置服务器
102
- server = WEBrick::HTTPServer.new(
103
- :Port => port,
104
- :DocumentRoot => webgl_dir,
105
- :Logger => WEBrick::Log.new(nil, WEBrick::Log::ERROR),
106
- :AccessLog => @args_debug ? nil : [],
107
- :DoNotReverseLookup => true,
108
- :BindAddress => '0.0.0.0' # 绑定到所有网络接口,使其在局域网可访问
109
- )
110
-
111
- # 挂载一个特殊的处理器专门处理原始的index.html
112
- server.mount_proc("/rawindex.html") { |req, res|
113
- index_path = File.join(webgl_dir, "index.html")
114
- if File.exist?(index_path)
115
- # 读取原始HTML内容
116
- original_html = File.read(index_path)
117
-
118
- # 添加base标签以修复相对路径问题
119
- if !original_html.include?('<base href=')
120
- # 在<head>标签后插入base标签
121
- modified_html = original_html.gsub(/<head>/, '<head><base href="./">')
122
- res.body = modified_html
123
- else
124
- res.body = original_html
125
- end
126
-
127
- res.content_type = "text/html"
128
- res.status = 200
129
- else
130
- res.status = 404
131
- res.body = "WebGL index.html not found"
132
- end
133
- }
134
-
135
- # 设置根路径重定向处理器
136
- server.mount_proc("/") { |req, res|
137
- # 仅对根路径请求进行重定向
138
- if req.path == "/" || req.path == "/index.html"
139
- res.set_redirect(WEBrick::HTTPStatus::Found, "/responsive")
140
- else
141
- # 对于非根路径,使用普通的静态文件处理
142
- path = req.path
143
- file_path = File.join(webgl_dir, path[1..-1])
144
-
145
- if File.exist?(file_path) && !File.directory?(file_path)
146
- # 确定内容类型
147
- ext = File.extname(file_path)
148
- content_type = case ext
149
- when ".html" then "text/html"
150
- when ".js" then "application/javascript"
151
- when ".css" then "text/css"
152
- when ".png" then "image/png"
153
- when ".jpg", ".jpeg" then "image/jpeg"
154
- when ".gif" then "image/gif"
155
- when ".ico" then "image/x-icon"
156
- when ".wasm" then "application/wasm"
157
- when ".data" then "application/octet-stream"
158
- when ".json" then "application/json"
159
- else "application/octet-stream"
160
- end
161
-
162
- # 设置Brotli压缩相关的响应头
163
- if file_path.end_with?('.br')
164
- res.header["Content-Encoding"] = "br"
165
- file_content = File.binread(file_path)
166
- else
167
- file_content = File.read(file_path)
168
- end
169
-
170
- res.content_type = content_type
171
- res.body = file_content
172
- res.status = 200
173
- else
174
- res.status = 404
175
- res.body = "File not found: #{path}"
176
- end
177
- end
178
- }
179
-
180
- # 挂载响应式预览页面处理器
181
- server.mount("/responsive", Pindo::WebServer::ResponsivePreviewHandler, webgl_dir, port, @args_debug)
182
-
183
- # 挂载Brotli处理器(后缀为.br的文件)
184
- paths_with_br = []
185
- Find.find(webgl_dir) do |path|
186
- if path.end_with?('.br') && File.file?(path)
187
- rel_path = path.sub(webgl_dir, '')
188
- paths_with_br << rel_path
189
- end
190
- end
191
-
192
- # 挂载每个.br文件
193
- paths_with_br.each do |br_path|
194
- server.mount(br_path, Pindo::WebServer::BrotliFileHandler, webgl_dir, @args_debug)
195
- end
196
-
197
- # 只在调试模式下显示详细信息
198
- if @args_debug
199
- UI.puts("找到.br文件: #{paths_with_br.join(', ')}")
200
-
201
- UI.puts("WebGL目录内容:")
202
- Dir.entries(webgl_dir).each do |entry|
203
- next if entry == "." || entry == ".."
204
- UI.puts(" - #{entry}")
205
-
206
- # 递归显示子目录中的文件(限制为一级)
207
- entry_path = File.join(webgl_dir, entry)
208
- if File.directory?(entry_path)
209
- Dir.entries(entry_path).each do |subentry|
210
- next if subentry == "." || subentry == ".."
211
- UI.puts(" - #{entry}/#{subentry}")
212
- end
213
- end
214
- end
215
- end
216
-
217
- # 启动服务器并返回
218
- local_ip = get_local_ip
219
- UI.puts("启动WebGL HTTP服务器,端口: #{port},目录: #{webgl_dir}")
220
-
221
- UI.puts("本地访问地址: http://localhost:#{port}/")
222
- UI.puts("局域网访问地址: http://#{local_ip}:#{port}/")
223
- UI.puts("原始WebGL地址: http://localhost:#{port}/index.html")
224
-
225
- return server
226
- rescue Exception => e
227
- UI.puts("启动HTTP服务器失败: #{e.message}")
228
- UI.debug(e.backtrace.join("\n"), @args_debug)
229
- return nil
230
- end
231
- end
232
-
233
70
  def run
234
71
  pindo_project_dir = Dir.pwd
235
72
  build_helper = Pindo::BuildHelper.share_instance
@@ -248,12 +85,22 @@ module Pindo
248
85
  UI.debug("WebGL资源目录: #{webgl_res_dir}", @args_debug)
249
86
  UI.debug("目录存在: #{File.directory?(webgl_res_dir)}", @args_debug)
250
87
 
251
- # 启动HTTP服务器而不是简单打开目录
252
- server = start_http_server(webgl_res_dir, @args_port)
88
+ # 使用WebGlServerHelper启动HTTP服务器
89
+ server = Pindo::WebServer::WebGlServerHelper.start_http_server(webgl_res_dir, @args_port, @args_debug)
253
90
 
254
91
  if server
255
- # 打开浏览器展示WebGL内容 - 使用根路径,会自动重定向到响应式预览
256
- system("open http://localhost:#{@args_port}/")
92
+ # 获取本地IP地址
93
+ local_ip = Pindo::WebServer::WebGlServerHelper.get_local_ip
94
+
95
+ # 显示访问地址
96
+ UI.puts("启动WebGL HTTP服务器,端口: #{@args_port},目录: #{webgl_res_dir}")
97
+ UI.puts("原始WebGL本地预览地址: http://localhost:#{@args_port}/")
98
+ UI.puts("模拟设备本地预览地址: http://localhost:#{@args_port}/responsive")
99
+ UI.puts("原始WebGL局域网预览地址: http://#{local_ip}:#{@args_port}/")
100
+ UI.puts("模拟设备局域网预览地址: http://#{local_ip}:#{@args_port}/responsive")
101
+
102
+ # 打开浏览器展示WebGL内容 - 直接打开预览页面
103
+ system("open http://localhost:#{@args_port}/responsive")
257
104
 
258
105
  # 捕获Ctrl+C信号来优雅地关闭服务器
259
106
  trap('INT') { server.shutdown }