pindo 5.1.1 → 5.1.3
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.
- checksums.yaml +4 -4
- data/lib/pindo/command/android/autobuild.rb +13 -0
- data/lib/pindo/command/unity/autobuild.rb +200 -0
- data/lib/pindo/command/unity/web.rb +152 -0
- data/lib/pindo/command/unity.rb +1 -1
- data/lib/pindo/command/web/run.rb +18 -178
- data/lib/pindo/module/android/build_helper.rb +325 -0
- data/lib/pindo/module/webserver/brotli_file_handler.rb +57 -0
- data/lib/pindo/module/webserver/preview/preview.css +433 -0
- data/lib/pindo/module/webserver/preview/preview.html +73 -0
- data/lib/pindo/module/webserver/preview/preview.js +595 -0
- data/lib/pindo/module/webserver/responsive_preview_handler.rb +104 -0
- data/lib/pindo/module/webserver/webgl_page_handler.rb +45 -0
- data/lib/pindo/module/webserver/webgl_server_helper.rb +190 -0
- data/lib/pindo/version.rb +1 -1
- metadata +11 -2
@@ -0,0 +1,104 @@
|
|
1
|
+
require 'webrick'
|
2
|
+
require 'json'
|
3
|
+
require 'fileutils'
|
4
|
+
|
5
|
+
module Pindo
|
6
|
+
module WebServer
|
7
|
+
|
8
|
+
# 响应式预览页面处理器
|
9
|
+
class ResponsivePreviewHandler < WEBrick::HTTPServlet::AbstractServlet
|
10
|
+
def initialize(server, root_dir, port, debug=false)
|
11
|
+
super(server)
|
12
|
+
@root_dir = root_dir
|
13
|
+
@preview_source_dir = File.join(File.dirname(__FILE__), 'preview') # 预览文件源目录
|
14
|
+
@port = port
|
15
|
+
@debug = debug
|
16
|
+
|
17
|
+
# 更详细的调试输出
|
18
|
+
puts "预览处理器初始化: WebGL目录=#{@root_dir}, 预览目录=#{@preview_source_dir}" if @debug
|
19
|
+
|
20
|
+
# 检查预览源目录是否存在
|
21
|
+
if File.directory?(@preview_source_dir)
|
22
|
+
puts "预览源目录存在: #{@preview_source_dir}" if @debug
|
23
|
+
puts "源目录中的文件: #{Dir.glob(File.join(@preview_source_dir, '*')).join(', ')}" if @debug
|
24
|
+
else
|
25
|
+
puts "错误: 预览源目录不存在: #{@preview_source_dir}" if @debug
|
26
|
+
end
|
27
|
+
|
28
|
+
# 挂载自定义处理器来处理预览文件
|
29
|
+
mount_preview_files_handler(server)
|
30
|
+
end
|
31
|
+
|
32
|
+
def do_GET(req, res)
|
33
|
+
# 重定向到预览页面,使用特殊的预览处理器路径前缀
|
34
|
+
res.set_redirect(WEBrick::HTTPStatus::Found, "/preview_page/preview.html")
|
35
|
+
end
|
36
|
+
|
37
|
+
private
|
38
|
+
|
39
|
+
# 挂载自定义处理器来处理预览文件
|
40
|
+
def mount_preview_files_handler(server)
|
41
|
+
# 创建一个处理器来处理/preview_page/路径下的请求,直接从源目录提供文件
|
42
|
+
server.mount_proc("/preview_page") do |req, res|
|
43
|
+
# 从请求路径中去除"/preview_page"前缀
|
44
|
+
request_path = req.path.sub("/preview_page", "")
|
45
|
+
request_path = "/preview.html" if request_path == "" || request_path == "/"
|
46
|
+
|
47
|
+
# 输出请求路径信息
|
48
|
+
puts "收到预览页面请求: #{req.path}, 处理为: #{request_path}" if @debug
|
49
|
+
|
50
|
+
# 构建实际文件路径(直接从源目录)
|
51
|
+
file_path = File.join(@preview_source_dir, request_path[1..-1])
|
52
|
+
puts "查找文件: #{file_path}" if @debug
|
53
|
+
puts "文件存在: #{File.exist?(file_path)}" if @debug
|
54
|
+
|
55
|
+
if File.exist?(file_path) && !File.directory?(file_path)
|
56
|
+
# 确定内容类型
|
57
|
+
ext = File.extname(file_path)
|
58
|
+
content_type = case ext
|
59
|
+
when ".html" then "text/html"
|
60
|
+
when ".js" then "application/javascript"
|
61
|
+
when ".css" then "text/css"
|
62
|
+
when ".png" then "image/png"
|
63
|
+
when ".jpg", ".jpeg" then "image/jpeg"
|
64
|
+
when ".gif" then "image/gif"
|
65
|
+
when ".ico" then "image/x-icon"
|
66
|
+
else "application/octet-stream"
|
67
|
+
end
|
68
|
+
|
69
|
+
# 读取文件内容
|
70
|
+
if [".png", ".jpg", ".jpeg", ".gif", ".ico"].include?(ext)
|
71
|
+
file_content = File.binread(file_path)
|
72
|
+
else
|
73
|
+
file_content = File.read(file_path)
|
74
|
+
|
75
|
+
# 对HTML和JS文件进行路径修正
|
76
|
+
if ext == ".html"
|
77
|
+
# 修改HTML中的相对路径引用
|
78
|
+
file_content = file_content.gsub('href="./preview.css"', 'href="/preview_page/preview.css"')
|
79
|
+
file_content = file_content.gsub('src="./preview.js"', 'src="/preview_page/preview.js"')
|
80
|
+
file_content = file_content.gsub('src="./rawindex.html"', 'src="/rawindex.html"')
|
81
|
+
elsif ext == ".js"
|
82
|
+
# 修改JS中的WebGL路径
|
83
|
+
file_content = file_content.gsub("const webglDirPath = './';", "const webglDirPath = '/';")
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
87
|
+
res.content_type = content_type
|
88
|
+
res.body = file_content
|
89
|
+
res.status = 200
|
90
|
+
|
91
|
+
puts "提供文件: #{file_path}, 内容类型: #{content_type}, 大小: #{file_content.length}字节" if @debug
|
92
|
+
else
|
93
|
+
res.status = 404
|
94
|
+
res.body = "Preview file not found: #{request_path}"
|
95
|
+
puts "找不到预览文件: #{file_path}" if @debug
|
96
|
+
end
|
97
|
+
end
|
98
|
+
|
99
|
+
puts "已挂载预览文件处理器: /preview_page/*,直接从源目录提供文件: #{@preview_source_dir}" if @debug
|
100
|
+
end
|
101
|
+
end
|
102
|
+
|
103
|
+
end
|
104
|
+
end
|
@@ -0,0 +1,45 @@
|
|
1
|
+
require 'webrick'
|
2
|
+
|
3
|
+
module Pindo
|
4
|
+
module WebServer
|
5
|
+
# 自定义前端页面处理器,处理Unity WebGL的特殊文件加载需求
|
6
|
+
|
7
|
+
# 自定义前端页面处理器,处理Unity WebGL的特殊文件加载需求
|
8
|
+
class WebGLPageHandler < WEBrick::HTTPServlet::AbstractServlet
|
9
|
+
def initialize(server, root_dir, debug=false)
|
10
|
+
super(server)
|
11
|
+
@root_dir = root_dir
|
12
|
+
@debug = debug
|
13
|
+
end
|
14
|
+
|
15
|
+
def do_GET(req, res)
|
16
|
+
path = req.path
|
17
|
+
path = "/index.html" if path == "/"
|
18
|
+
|
19
|
+
file_path = File.join(@root_dir, path[1..-1])
|
20
|
+
|
21
|
+
if File.exist?(file_path)
|
22
|
+
# 确定内容类型
|
23
|
+
ext = File.extname(file_path)
|
24
|
+
content_type = case ext
|
25
|
+
when ".html" then "text/html"
|
26
|
+
when ".js" then "application/javascript"
|
27
|
+
when ".css" then "text/css"
|
28
|
+
when ".png" then "image/png"
|
29
|
+
when ".jpg", ".jpeg" then "image/jpeg"
|
30
|
+
when ".gif" then "image/gif"
|
31
|
+
when ".ico" then "image/x-icon"
|
32
|
+
else "application/octet-stream"
|
33
|
+
end
|
34
|
+
|
35
|
+
res.content_type = content_type
|
36
|
+
res.body = File.read(file_path)
|
37
|
+
res.status = 200
|
38
|
+
else
|
39
|
+
res.status = 404
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
end
|
45
|
+
end
|
@@ -0,0 +1,190 @@
|
|
1
|
+
require 'webrick'
|
2
|
+
require 'socket'
|
3
|
+
require 'find'
|
4
|
+
require_relative 'responsive_preview_handler'
|
5
|
+
require_relative 'brotli_file_handler'
|
6
|
+
require_relative 'webgl_page_handler'
|
7
|
+
|
8
|
+
module Pindo
|
9
|
+
module WebServer
|
10
|
+
# WebGL服务器辅助类
|
11
|
+
# 用于配置和启动WebGL预览服务器
|
12
|
+
class WebGlServerHelper
|
13
|
+
# 启动HTTP服务器
|
14
|
+
def self.start_http_server(webgl_dir, port, debug = false)
|
15
|
+
begin
|
16
|
+
# 确保目录存在
|
17
|
+
unless File.directory?(webgl_dir)
|
18
|
+
puts("错误: WebGL目录不存在: #{webgl_dir}")
|
19
|
+
return nil
|
20
|
+
end
|
21
|
+
|
22
|
+
# 检查index.html是否存在
|
23
|
+
if !File.exist?(File.join(webgl_dir, "index.html"))
|
24
|
+
puts("警告: WebGL目录中未找到index.html文件")
|
25
|
+
end
|
26
|
+
|
27
|
+
# 创建自定义日志格式器,只记录错误
|
28
|
+
custom_log = [
|
29
|
+
[:error, WEBrick::AccessLog::COMMON_LOG_FORMAT],
|
30
|
+
]
|
31
|
+
|
32
|
+
# 采用直接的方法配置服务器
|
33
|
+
server = WEBrick::HTTPServer.new(
|
34
|
+
:Port => port,
|
35
|
+
:DocumentRoot => webgl_dir,
|
36
|
+
:Logger => WEBrick::Log.new(nil, WEBrick::Log::ERROR),
|
37
|
+
:AccessLog => debug ? nil : [],
|
38
|
+
:DoNotReverseLookup => true,
|
39
|
+
:BindAddress => '0.0.0.0' # 绑定到所有网络接口,使其在局域网可访问
|
40
|
+
)
|
41
|
+
|
42
|
+
# 设置根路径处理器
|
43
|
+
server.mount_proc("/") { |req, res|
|
44
|
+
# 根路径请求直接提供WebGL内容
|
45
|
+
if req.path == "/" || req.path == "/index.html"
|
46
|
+
# 直接提供index.html,不再重定向到响应式预览
|
47
|
+
index_path = File.join(webgl_dir, "index.html")
|
48
|
+
if File.exist?(index_path)
|
49
|
+
# 读取原始HTML内容
|
50
|
+
original_html = File.read(index_path)
|
51
|
+
|
52
|
+
# 添加base标签以修复相对路径问题
|
53
|
+
if !original_html.include?('<base href=')
|
54
|
+
# 在<head>标签后插入base标签
|
55
|
+
modified_html = original_html.gsub(/<head>/, '<head><base href="./">')
|
56
|
+
res.body = modified_html
|
57
|
+
else
|
58
|
+
res.body = original_html
|
59
|
+
end
|
60
|
+
|
61
|
+
res.content_type = "text/html"
|
62
|
+
res.status = 200
|
63
|
+
else
|
64
|
+
res.status = 404
|
65
|
+
res.body = "WebGL index.html not found"
|
66
|
+
end
|
67
|
+
else
|
68
|
+
# 对于非根路径,使用普通的静态文件处理
|
69
|
+
path = req.path
|
70
|
+
file_path = File.join(webgl_dir, path[1..-1])
|
71
|
+
|
72
|
+
if File.exist?(file_path) && !File.directory?(file_path)
|
73
|
+
# 确定内容类型
|
74
|
+
ext = File.extname(file_path)
|
75
|
+
content_type = case ext
|
76
|
+
when ".html" then "text/html"
|
77
|
+
when ".js" then "application/javascript"
|
78
|
+
when ".css" then "text/css"
|
79
|
+
when ".png" then "image/png"
|
80
|
+
when ".jpg", ".jpeg" then "image/jpeg"
|
81
|
+
when ".gif" then "image/gif"
|
82
|
+
when ".ico" then "image/x-icon"
|
83
|
+
when ".wasm" then "application/wasm"
|
84
|
+
when ".data" then "application/octet-stream"
|
85
|
+
when ".json" then "application/json"
|
86
|
+
else "application/octet-stream"
|
87
|
+
end
|
88
|
+
|
89
|
+
# 设置Brotli压缩相关的响应头
|
90
|
+
if file_path.end_with?('.br')
|
91
|
+
res.header["Content-Encoding"] = "br"
|
92
|
+
file_content = File.binread(file_path)
|
93
|
+
else
|
94
|
+
file_content = File.read(file_path)
|
95
|
+
end
|
96
|
+
|
97
|
+
res.content_type = content_type
|
98
|
+
res.body = file_content
|
99
|
+
res.status = 200
|
100
|
+
else
|
101
|
+
res.status = 404
|
102
|
+
res.body = "File not found: #{path}"
|
103
|
+
end
|
104
|
+
end
|
105
|
+
}
|
106
|
+
|
107
|
+
# 挂载一个特殊的处理器专门处理rawindex.html(供预览页面使用)
|
108
|
+
server.mount_proc("/rawindex.html") { |req, res|
|
109
|
+
index_path = File.join(webgl_dir, "index.html")
|
110
|
+
if File.exist?(index_path)
|
111
|
+
# 读取原始HTML内容
|
112
|
+
original_html = File.read(index_path)
|
113
|
+
|
114
|
+
# 添加base标签以修复相对路径问题
|
115
|
+
if !original_html.include?('<base href=')
|
116
|
+
# 在<head>标签后插入base标签
|
117
|
+
modified_html = original_html.gsub(/<head>/, '<head><base href="./">')
|
118
|
+
res.body = modified_html
|
119
|
+
else
|
120
|
+
res.body = original_html
|
121
|
+
end
|
122
|
+
|
123
|
+
res.content_type = "text/html"
|
124
|
+
res.status = 200
|
125
|
+
else
|
126
|
+
res.status = 404
|
127
|
+
res.body = "WebGL index.html not found"
|
128
|
+
end
|
129
|
+
}
|
130
|
+
|
131
|
+
# 挂载响应式预览页面处理器
|
132
|
+
server.mount("/responsive", Pindo::WebServer::ResponsivePreviewHandler, webgl_dir, port, debug)
|
133
|
+
|
134
|
+
# 挂载Brotli处理器(后缀为.br的文件)
|
135
|
+
paths_with_br = []
|
136
|
+
Find.find(webgl_dir) do |path|
|
137
|
+
if path.end_with?('.br') && File.file?(path)
|
138
|
+
rel_path = path.sub(webgl_dir, '')
|
139
|
+
paths_with_br << rel_path
|
140
|
+
end
|
141
|
+
end
|
142
|
+
|
143
|
+
# 挂载每个.br文件
|
144
|
+
paths_with_br.each do |br_path|
|
145
|
+
server.mount(br_path, Pindo::WebServer::BrotliFileHandler, webgl_dir, debug)
|
146
|
+
end
|
147
|
+
|
148
|
+
# 只在调试模式下显示详细信息
|
149
|
+
if debug
|
150
|
+
puts("找到.br文件: #{paths_with_br.join(', ')}")
|
151
|
+
|
152
|
+
puts("WebGL目录内容:")
|
153
|
+
Dir.entries(webgl_dir).each do |entry|
|
154
|
+
next if entry == "." || entry == ".."
|
155
|
+
puts(" - #{entry}")
|
156
|
+
|
157
|
+
# 递归显示子目录中的文件(限制为一级)
|
158
|
+
entry_path = File.join(webgl_dir, entry)
|
159
|
+
if File.directory?(entry_path)
|
160
|
+
Dir.entries(entry_path).each do |subentry|
|
161
|
+
next if subentry == "." || subentry == ".."
|
162
|
+
puts(" - #{entry}/#{subentry}")
|
163
|
+
end
|
164
|
+
end
|
165
|
+
end
|
166
|
+
end
|
167
|
+
|
168
|
+
# 返回配置好的服务器
|
169
|
+
return server
|
170
|
+
rescue Exception => e
|
171
|
+
puts("启动HTTP服务器失败: #{e.message}")
|
172
|
+
puts(e.backtrace.join("\n")) if debug
|
173
|
+
return nil
|
174
|
+
end
|
175
|
+
end
|
176
|
+
|
177
|
+
# 获取本机局域网IP地址
|
178
|
+
def self.get_local_ip
|
179
|
+
ip = nil
|
180
|
+
Socket.ip_address_list.each do |addr_info|
|
181
|
+
if addr_info.ipv4? && !addr_info.ipv4_loopback?
|
182
|
+
ip = addr_info.ip_address
|
183
|
+
break
|
184
|
+
end
|
185
|
+
end
|
186
|
+
return ip || 'localhost'
|
187
|
+
end
|
188
|
+
end
|
189
|
+
end
|
190
|
+
end
|
data/lib/pindo/version.rb
CHANGED
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: pindo
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 5.1.
|
4
|
+
version: 5.1.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- wade
|
8
8
|
bindir: bin
|
9
9
|
cert_chain: []
|
10
|
-
date: 2025-04-
|
10
|
+
date: 2025-04-23 00:00:00.000000000 Z
|
11
11
|
dependencies:
|
12
12
|
- !ruby/object:Gem::Dependency
|
13
13
|
name: claide
|
@@ -378,7 +378,9 @@ files:
|
|
378
378
|
- lib/pindo/command/setup.rb
|
379
379
|
- lib/pindo/command/unity.rb
|
380
380
|
- lib/pindo/command/unity/apk.rb
|
381
|
+
- lib/pindo/command/unity/autobuild.rb
|
381
382
|
- lib/pindo/command/unity/ipa.rb
|
383
|
+
- lib/pindo/command/unity/web.rb
|
382
384
|
- lib/pindo/command/utils.rb
|
383
385
|
- lib/pindo/command/utils/boss.rb
|
384
386
|
- lib/pindo/command/utils/clearcert.rb
|
@@ -414,6 +416,13 @@ files:
|
|
414
416
|
- lib/pindo/module/cert/provisioninghelper.rb
|
415
417
|
- lib/pindo/module/cert/xcodecerthelper.rb
|
416
418
|
- lib/pindo/module/pgyer/pgyerhelper.rb
|
419
|
+
- lib/pindo/module/webserver/brotli_file_handler.rb
|
420
|
+
- lib/pindo/module/webserver/preview/preview.css
|
421
|
+
- lib/pindo/module/webserver/preview/preview.html
|
422
|
+
- lib/pindo/module/webserver/preview/preview.js
|
423
|
+
- lib/pindo/module/webserver/responsive_preview_handler.rb
|
424
|
+
- lib/pindo/module/webserver/webgl_page_handler.rb
|
425
|
+
- lib/pindo/module/webserver/webgl_server_helper.rb
|
417
426
|
- lib/pindo/module/xcode/xcodeappconfig.rb
|
418
427
|
- lib/pindo/module/xcode/xcodebuildconfig.rb
|
419
428
|
- lib/pindo/module/xcode/xcodebuildhelper.rb
|