Class: Pindo::Command::Web::Run
- Inherits:
-
Pindo::Command::Web
- Object
- CLAide::Command
- Pindo::Command
- Pindo::Command::Web
- Pindo::Command::Web::Run
- Defined in:
- lib/pindo/command/web/run.rb
Defined Under Namespace
Modules: UI
Constant Summary
Constants inherited from Pindo::Command
DEFAULT_OPTIONS, DEFAULT_ROOT_OPTIONS
Instance Attribute Summary
Attributes inherited from Pindo::Command
Class Method Summary collapse
-
.options ⇒ Object
命令的选项列表.
Instance Method Summary collapse
-
#initialize(argv) ⇒ Run
constructor
A new instance of Run.
- #run ⇒ Object
- #validate! ⇒ Object
Methods inherited from Pindo::Command
Methods included from Funlog::Mixin
Methods included from Pindoconfig::Mixin
Methods included from Githelper
#add_branch, #add_tag, #add_tag_with_check, #clone_clang_repo, #clone_devclang_repo, #clone_pindo_common_config_repo, #clone_pindo_env_config_repo, #clong_buildconfig_repo, #get_repo_base_name, #getcode_to_dir, #git_addpush_repo, #git_latest_commit_id, #git_root_directory, #is_git_directory?, #local_branch_exists?, #local_tag_exists?, #prepare_gitenv, #process_need_add_files, #remote_branch_exists?, #remote_tag_exists?, #remove_branch, #remove_tag
Methods included from Executable
capture_command, #executable, execute_command, which, which!
Constructor Details
#initialize(argv) ⇒ Run
Returns a new instance of Run.
47 48 49 50 51 52 53 |
# File 'lib/pindo/command/web/run.rb', line 47 def initialize(argv) @args_port = argv.option('port', '8000').to_i # 添加端口参数,默认8000 @args_debug = argv.flag?('debug', false) # 是否显示调试信息 super @additional_args = argv.remainder! end |
Class Method Details
.options ⇒ Object
命令的选项列表
38 39 40 41 42 43 44 45 |
# File 'lib/pindo/command/web/run.rb', line 38 def self. [ # 添加HTTP服务器端口选项 ['--port', '指定HTTP服务器的端口,默认为8000'], # 添加调试选项 ['--debug', '显示详细的调试信息'] ].concat(super) end |
Instance Method Details
#run ⇒ Object
70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 |
# File 'lib/pindo/command/web/run.rb', line 70 def run pindo_project_dir = Dir.pwd build_helper = Pindo::BuildHelper.share_instance project_type = build_helper.project_type(pindo_project_dir) webgl_res_dir = Dir.pwd case project_type when :unity webgl_res_dir = File.join(pindo_project_dir, "GoodPlatform/WebGL/build") end # 确保路径规范化 webgl_res_dir = File.(webgl_res_dir) # 只在调试模式下显示这些信息 UI.debug("WebGL资源目录: #{webgl_res_dir}", @args_debug) UI.debug("目录存在: #{File.directory?(webgl_res_dir)}", @args_debug) # 使用WebGlServerHelper启动HTTP服务器 server = Pindo::WebServer::WebGlServerHelper.start_http_server(webgl_res_dir, @args_port, @args_debug) if server # 获取本地IP地址 local_ip = Pindo::WebServer::WebGlServerHelper.get_local_ip # 显示访问地址 UI.puts("启动WebGL HTTP服务器,端口: #{@args_port},目录: #{webgl_res_dir}") UI.puts("原始WebGL本地预览地址: http://localhost:#{@args_port}/") UI.puts("模拟设备本地预览地址: http://localhost:#{@args_port}/responsive") UI.puts("原始WebGL局域网预览地址: http://#{local_ip}:#{@args_port}/") UI.puts("模拟设备局域网预览地址: http://#{local_ip}:#{@args_port}/responsive") # 打开浏览器展示WebGL内容 - 直接打开预览页面 system("open http://localhost:#{@args_port}/responsive") # 捕获Ctrl+C信号来优雅地关闭服务器 trap('INT') { server.shutdown } trap('TERM') { server.shutdown } # 启动服务器主循环 UI.puts("服务器运行中,按Ctrl+C停止...") server.start else # 如果服务器启动失败,回退到简单打开目录 UI.puts("无法启动HTTP服务器,将直接打开WebGL目录") system "open #{webgl_res_dir}" end end |
#validate! ⇒ Object
55 56 57 |
# File 'lib/pindo/command/web/run.rb', line 55 def validate! super end |