Module: VVPrepare

Defined in:
lib/live_server.rb

Class Method Summary collapse

Class Method Details

.checkVVCompilerObject

检查和下载 VV 编译器



64
65
66
67
68
69
70
71
72
73
74
75
76
77
# File 'lib/live_server.rb', line 64

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

.checkVVConfigPropertiesObject

检查和下载 config.properties



80
81
82
83
84
85
86
87
88
89
90
91
92
93
# File 'lib/live_server.rb', line 80

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

.cleanObject



155
156
157
158
159
# File 'lib/live_server.rb', line 155

def self.clean()
  FileUtils.rm_rf TemplatePath
  FileUtils.rm_rf VVBuildPath
  FileUtils.rm_f PropertiesFilePath
end

.copyXML(copyTemplatePath) ⇒ Object

拷贝 xml 准备编译



45
46
47
48
49
# File 'lib/live_server.rb', line 45

def self.copyXML(copyTemplatePath)
  FileUtils.rm_rf TemplatePath
  FileUtils.mkdir_p TemplatePath
  FileUtils.cp Dir.glob("#{copyTemplatePath}/**/*.xml"), TemplatePath
end

.generateDataJSON(aTemplatesPath) ⇒ Object



100
101
102
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
# File 'lib/live_server.rb', line 100

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)
      templateParams = JSON.parse(File.read(templateParamsJSONPath))
    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

.generatePropertiesObject

生成 templatelist.properties 文件



52
53
54
55
56
57
58
59
60
61
# File 'lib/live_server.rb', line 52

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

.vvbuildObject

编译



96
97
98
# File 'lib/live_server.rb', line 96

def self.vvbuild()
  system "java -jar #{VVCompilerFilePath} jarBuild > #{VVBuildLogFilePath}"
end