module VVPrepare
Public Class Methods
checkVVCompiler()
click to toggle source
检查和下载 VV 编译器
# File lib/vvtool/live_server.rb, line 67 def self.checkVVCompiler() if File.exist? VVCompilerFilePath puts 'Check VV compiler ok.' else puts 'Start downloading VV compiler.jar...' File.write(VVCompilerFilePath, Net::HTTP.get(URI.parse(VVCompilerDownloadURL))) if File.exist? VVCompilerFilePath puts 'VV compiler.jar download success.' else puts 'VV compiler.jar download fail.' exit end end end
checkVVConfigProperties()
click to toggle source
检查和下载 config.properties
# File lib/vvtool/live_server.rb, line 83 def self.checkVVConfigProperties() if File.exist? VVConfigPropertiesFilePath puts 'Check VV config.properties ok.' else puts 'Start downloading VV config.properties...' File.write(VVConfigPropertiesFilePath, Net::HTTP.get(URI.parse(VVConfigPropertiesDownloadURL))) if File.exist? VVConfigPropertiesFilePath puts 'VV config.properties download success.' else puts 'VV config.properties download fail.' exit end end end
clean()
click to toggle source
# File lib/vvtool/live_server.rb, line 161 def self.clean() FileUtils.rm_rf TemplatePath FileUtils.rm_rf VVBuildPath FileUtils.rm_f PropertiesFilePath end
copyXML(copyTemplatePath)
click to toggle source
拷贝 xml 准备编译
# File lib/vvtool/live_server.rb, line 48 def self.copyXML(copyTemplatePath) FileUtils.rm_rf TemplatePath FileUtils.mkdir_p TemplatePath FileUtils.cp Dir.glob("#{copyTemplatePath}/**/*.xml"), TemplatePath end
generateDataJSON(aTemplatesPath)
click to toggle source
# File lib/vvtool/live_server.rb, line 103 def self.generateDataJSON(aTemplatesPath) # 生成每个模版对应的 data.json templateNameList = [] Pathname.new(aTemplatesPath).children.push(aTemplatesPath).each { | aTemplatePath | templateName = File.basename aTemplatePath, '.*' next if not File.directory? aTemplatePath next if not File.exist?(File.join(aTemplatePath, "#{templateName}.xml")) next if templateName.start_with? '.' # 把所有模版名记录下来 templateNameList << templateName # 获取这个模版目录下所有 xml 的编译二进制 Base64 列表 xmlBase64List = [] Dir.glob(File.join(aTemplatePath, '**/*.xml')).each { | xmlFilePath | xmlFileName = File.basename xmlFilePath, '.*' # 获取这个 xml 的 .out -> base64 xmlBuildOutPath = File.join(VVBuildPath, "out/#{xmlFileName}.out") xmlBase64String = Base64.strict_encode64(File.open(xmlBuildOutPath, "rb").read) xmlBase64List << xmlBase64String } # 读取模版参数 JSON templateParams = {} templateParamsJSONPath = File.join(aTemplatePath, "#{templateName}.json") if File.exist?(templateParamsJSONPath) begin templateParams = JSON.parse(File.read(templateParamsJSONPath)) rescue JSON::ParserError => e puts "[ERROR] - JSON parsing failed! (#{templateName}.json)".red end end # 合并 data.json (HTTP Server 读取) if xmlBase64List.count > 0 dataHash = {'templates': xmlBase64List, 'data': templateParams,} dataJSONPath = File.join(aTemplatePath, "data.json") File.open(dataJSONPath, "w") { |f| f.write(JSON.pretty_generate dataHash) } end # 生成二维码 if LocalIP qrcode = RQRCode::QRCode.new("http://#{LocalIP}:#{HTTPServerPort}/#{templateName}/data.json") qrcodeFilePath = File.join(aTemplatePath, "#{templateName}_QR.png") qrcode.as_png(file: qrcodeFilePath) end } # 生成模版目录结构 .dir(HTTP Server 读取) File.open(DirFilePath, "w") { |f| f.write(JSON.pretty_generate templateNameList) } end
generateProperties()
click to toggle source
生成 templatelist.properties 文件
# File lib/vvtool/live_server.rb, line 55 def self.generateProperties() nowTimestamp = Time.now.to_i propertiesContent = Dir.entries(TemplatePath).reject { |f| File.directory? f } .map { |f| filename = File.basename f, '.*' "#{filename}=#{filename},#{nowTimestamp}" } File.open(PropertiesFilePath, 'w+') { |f| propertiesContent.each { |e| f.puts e } } end
vvbuild()
click to toggle source
编译
# File lib/vvtool/live_server.rb, line 99 def self.vvbuild() system "java -jar #{VVCompilerFilePath} jarBuild > #{VVBuildLogFilePath}" end