pindo 5.1.2 → 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 +15 -168
- data/lib/pindo/module/android/build_helper.rb +325 -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 +92 -816
- data/lib/pindo/module/webserver/webgl_server_helper.rb +175 -3
- data/lib/pindo/version.rb +1 -1
- metadata +7 -2
@@ -10,9 +10,181 @@ module Pindo
|
|
10
10
|
# WebGL服务器辅助类
|
11
11
|
# 用于配置和启动WebGL预览服务器
|
12
12
|
class WebGlServerHelper
|
13
|
-
|
14
|
-
|
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
|
+
]
|
15
31
|
|
16
|
-
|
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
|
17
189
|
end
|
18
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
|
@@ -415,6 +417,9 @@ files:
|
|
415
417
|
- lib/pindo/module/cert/xcodecerthelper.rb
|
416
418
|
- lib/pindo/module/pgyer/pgyerhelper.rb
|
417
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
|
418
423
|
- lib/pindo/module/webserver/responsive_preview_handler.rb
|
419
424
|
- lib/pindo/module/webserver/webgl_page_handler.rb
|
420
425
|
- lib/pindo/module/webserver/webgl_server_helper.rb
|