Module: VVPrepare
- Defined in:
- lib/vvtool/live_server.rb
Class Method Summary collapse
-
.checkVVCompiler ⇒ Object
检查和下载 VV 编译器.
-
.checkVVConfigProperties ⇒ Object
检查和下载 config.properties.
- .clean ⇒ Object
-
.copyXML(copyTemplatePath) ⇒ Object
拷贝 xml 准备编译.
- .generateDataJSON(aTemplatesPath) ⇒ Object
-
.generateProperties ⇒ Object
生成 templatelist.properties 文件.
-
.vvbuild ⇒ Object
编译.
Class Method Details
.checkVVCompiler ⇒ Object
检查和下载 VV 编译器
67 68 69 70 71 72 73 74 75 76 77 78 79 80 |
# 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 ⇒ Object
检查和下载 config.properties
83 84 85 86 87 88 89 90 91 92 93 94 95 96 |
# 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 ⇒ Object
161 162 163 164 165 |
# 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) ⇒ Object
拷贝 xml 准备编译
48 49 50 51 52 |
# 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) ⇒ Object
103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 |
# 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 ⇒ Object
生成 templatelist.properties 文件
55 56 57 58 59 60 61 62 63 64 |
# 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 ⇒ Object
编译
99 100 101 |
# File 'lib/vvtool/live_server.rb', line 99 def self.vvbuild() system "java -jar #{VVCompilerFilePath} jarBuild > #{VVBuildLogFilePath}" end |