Module: VVTool

Defined in:
lib/vvtool.rb,
lib/vvtool/version.rb,
lib/vvtool/live_server.rb

Defined Under Namespace

Classes: CLI

Constant Summary collapse

VERSION =
"0.1.6"

Class Method Summary collapse

Class Method Details

.firstBuild(check_dependency) ⇒ Object

第一次



170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
# File 'lib/vvtool/live_server.rb', line 170

def firstBuild(check_dependency)
  # 0. Clean
  VVPrepare.clean

  if check_dependency
    # 0.1 检查编译器 - 没有则下载
    VVPrepare.checkVVCompiler

    # 0.2 检查 config.properties - 没有则下载
    VVPrepare.checkVVConfigProperties
  end

  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

.live_server_run(check_dependency = true) ⇒ Object



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
266
267
268
269
270
271
272
273
274
# File 'lib/vvtool/live_server.rb', line 224

def live_server_run(check_dependency = true)
    self.firstBuild(check_dependency)

    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}".blue.bright.underline

    # 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

单次编译



203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
# File 'lib/vvtool/live_server.rb', line 203

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