Top Level Namespace
Defined Under Namespace
Constant Summary collapse
- PropertiesFileName =
路径
'templatelist.properties'- ConfigPropertiesFileName =
'config.properties'- CompilerFileName =
'.compiler.jar'- TemplatesPath =
Dir.pwd
- TemplatePath =
File.join(TemplatesPath, 'template')
- VVBuildPath =
File.join(TemplatesPath, 'build')
- VVBuildLogFilePath =
File.join(TemplatesPath, '.vvbuild.log')
- VVCompilerFilePath =
File.join(TemplatesPath, CompilerFileName)
- VVConfigPropertiesFilePath =
File.join(TemplatesPath, ConfigPropertiesFileName)
- PropertiesFilePath =
File.join(TemplatesPath, PropertiesFileName)
- DirFilePath =
File.join(TemplatesPath, '.dir')
- VVCompilerDownloadURL =
VV 编译器下载地址 URL
'https://raw.githubusercontent.com/alibaba/virtualview_tools/bb727ac668856732f66c3845b27646c1b4124fc8/compiler-tools/TemplateWorkSpace/compiler.jar'- VVConfigPropertiesDownloadURL =
VV 默认的 config.properties 下载地址 URL
'https://raw.githubusercontent.com/alibaba/virtualview_tools/bb727ac668856732f66c3845b27646c1b4124fc8/compiler-tools/TemplateWorkSpace/config.properties'- LocalIP =
获取本机 IP
get_first_public_ipv4()
- HTTPServerPort =
HTTP 服务端口号
7788- RubyGemsLatestVersionURL =
'https://rubygems.org/api/v1/versions/vvtool/latest.json'
Instance Method Summary collapse
- #check_new_version ⇒ Object
-
#firstBuild ⇒ Object
第一次.
- #get_first_public_ipv4 ⇒ Object
- #get_remote_version ⇒ Object
- #live_server_run ⇒ Object
-
#singleBuild(aTemplatePath) ⇒ Object
单次编译.
Instance Method Details
#check_new_version ⇒ Object
19 20 21 22 23 24 25 26 |
# File 'lib/version_checker.rb', line 19 def check_new_version get_remote_version { |remoteVersion| currentVersion = VVTool::VERSION if currentVersion < remoteVersion puts "VVTool 发现新版本 v#{remoteVersion}(当前 v#{currentVersion}),可以通过命令 `sudo gem install vvtool` 升级" end } end |
#firstBuild ⇒ Object
第一次
163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 |
# File 'lib/live_server.rb', line 163 def firstBuild() # 0. Clean VVPrepare.clean # 0.1 检查编译器 - 没有则下载 VVPrepare.checkVVCompiler # 0.2 检查 config.properties - 没有则下载 VVPrepare.checkVVConfigProperties puts 'Start build templates...' # 1. 拷贝出来集中所有 .xml 模版文件 VVPrepare.copyXML TemplatesPath # 2. 生成 compiler.jar 编译所需的 templatelist.properties 文件 VVPrepare.generateProperties # 3. 编译 VVPrepare.vvbuild # 4. 生成 data.json VVPrepare.generateDataJSON TemplatesPath # 5. Clean VVPrepare.clean puts 'All templates build finished.' end |
#get_first_public_ipv4 ⇒ Object
3 4 5 6 |
# File 'lib/utils.rb', line 3 def get_first_public_ipv4 ip_info = Socket.ip_address_list.detect{|intf| intf.ipv4? and !intf.ipv4_loopback? and !intf.ipv4_multicast? and !intf.ipv4_private?} ip_info.ip_address unless ip_info.nil? end |
#get_remote_version ⇒ Object
9 10 11 12 13 14 15 16 17 |
# File 'lib/version_checker.rb', line 9 def get_remote_version begin Thread.new { response = Net::HTTP.get(URI(RubyGemsLatestVersionURL)) response = JSON.parse(response) yield response['version'] } end end |
#live_server_run ⇒ Object
215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 |
# File 'lib/live_server.rb', line 215 def live_server_run firstBuild() puts TemplatesPath # HTTP Server Thread.new { http_server = WEBrick::HTTPServer.new( :Port => HTTPServerPort, :DocumentRoot => TemplatesPath, :Logger => WEBrick::Log.new(VVBuildLogFilePath), :AccessLog => [] ) http_server.start } puts "Start HTTP server: http://#{LocalIP || '127.0.0.1'}:#{HTTPServerPort}" # File Watch listener = Listen.to(TemplatesPath, only: [/\.xml$/, /\.json$/]) { |modified, added, removed| (modified + added).each { |filePath| thisTemplatePath = Pathname.new(filePath).dirname thisTemplateName = File.basename filePath, '.*' thisTemplateNameAndExt = File.basename filePath next if thisTemplateNameAndExt == 'data.json' puts "[#{ Time.now.strftime("%H:%M:%S") }] Update template: #{thisTemplateName} (#{thisTemplateNameAndExt})" self.singleBuild thisTemplatePath VVPrepare.clean $buildCount += 1 } }.start puts 'Start Watching...' puts '' trap "SIGINT" do puts '' puts "Bye, see you next time, build count: #{$buildCount}" # clean FileUtils.rm_f VVBuildLogFilePath FileUtils.rm_f DirFilePath exit 130 end # 从 RubyGems 上检查新版本 check_new_version sleep end |
#singleBuild(aTemplatePath) ⇒ Object
单次编译
194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 |
# File 'lib/live_server.rb', line 194 public def singleBuild(aTemplatePath) # 0. Clean VVPrepare.clean # 1. 拷贝出来集中所有 .xml 模版文件 VVPrepare.copyXML aTemplatePath # 2. 生成 compiler.jar 编译所需的 templatelist.properties 文件 VVPrepare.generateProperties # 3. 编译 VVPrepare.vvbuild # 4. 生成 data.json VVPrepare.generateDataJSON aTemplatePath # 5. Clean VVPrepare.clean end |