vvtool 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 65ae28bec15aa73b776b27b0b1e3185723d4c6d8
4
+ data.tar.gz: fec96004160fc294e0f3007e74108cd64c7b46ea
5
+ SHA512:
6
+ metadata.gz: 40f870803a492476af4ed4145ee29037fc1ad38d51bab575c6b6c9c2538afa7da8148b7b806f97ee61bd18054db56787faf36248d9bfa311e4138a121d00089c
7
+ data.tar.gz: 6e30afe676740938eb1b99623caf2d10e728096707c50b639918cdffe1f4371ef57c0b31c425f51d892f13afcb9527dba35acd556460998f90d29b0ac75f67f6
data/.gitignore ADDED
@@ -0,0 +1,8 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source "https://rubygems.org"
2
+
3
+ git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
4
+
5
+ # Specify your gem's dependencies in vvtool.gemspec
6
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,32 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ vvtool (0.1.0)
5
+ listen (~> 3.0)
6
+ thor (~> 0.20)
7
+
8
+ GEM
9
+ remote: https://rubygems.org/
10
+ specs:
11
+ ffi (1.9.25)
12
+ listen (3.1.5)
13
+ rb-fsevent (~> 0.9, >= 0.9.4)
14
+ rb-inotify (~> 0.9, >= 0.9.7)
15
+ ruby_dep (~> 1.2)
16
+ rake (10.4.2)
17
+ rb-fsevent (0.10.3)
18
+ rb-inotify (0.9.10)
19
+ ffi (>= 0.5.0, < 2)
20
+ ruby_dep (1.5.0)
21
+ thor (0.20.0)
22
+
23
+ PLATFORMS
24
+ ruby
25
+
26
+ DEPENDENCIES
27
+ bundler (~> 1.16)
28
+ rake (~> 10.0)
29
+ vvtool!
30
+
31
+ BUNDLED WITH
32
+ 1.16.3
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2018 ChenTian
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,39 @@
1
+ # Vvtool
2
+
3
+ Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/vvtool`. To experiment with that code, run `bin/console` for an interactive prompt.
4
+
5
+ TODO: Delete this and the text above, and describe your gem
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'vvtool'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install vvtool
22
+
23
+ ## Usage
24
+
25
+ TODO: Write usage instructions here
26
+
27
+ ## Development
28
+
29
+ After checking out the repo, run `bin/setup` to install dependencies. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
30
+
31
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
32
+
33
+ ## Contributing
34
+
35
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/vvtool.
36
+
37
+ ## License
38
+
39
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+ task :default => :spec
data/bin/vvtool ADDED
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env ruby
2
+ require "vvtool.rb"
3
+
@@ -0,0 +1,218 @@
1
+ #!/usr/bin/ruby
2
+
3
+ require 'fileutils'
4
+ require 'pathname'
5
+ require 'webrick'
6
+ require 'Listen'
7
+ require 'base64'
8
+ require 'json'
9
+ require 'net/http'
10
+
11
+ # 路径
12
+ PropertiesFileName = 'templatelist.properties'
13
+ CompilerFileName = '.compiler.jar'
14
+ TemplatesPath = Dir.pwd
15
+ TemplatePath = File.join(TemplatesPath, 'template')
16
+ VVBuildPath = File.join(TemplatesPath, 'build')
17
+ VVBuildLogFilePath = File.join(TemplatesPath, '.vvbuild.log')
18
+ VVCompilerFilePath = File.join(TemplatesPath, CompilerFileName)
19
+ PropertiesFilePath = File.join(TemplatesPath, PropertiesFileName)
20
+ DirFilePath = File.join(TemplatesPath, '.dir')
21
+
22
+ VVCompilerDownloadURL = 'https://raw.githubusercontent.com/alibaba/virtualview_tools/master/compiler-tools/TemplateWorkSpace/compiler.jar'
23
+
24
+ $buildCount = 1
25
+
26
+ module VVPrepare
27
+ # 拷贝 xml 准备编译
28
+ def self.copyXML(copyTemplatePath)
29
+ FileUtils.rm_rf TemplatePath
30
+ FileUtils.mkdir_p TemplatePath
31
+ FileUtils.cp Dir.glob("#{copyTemplatePath}/**/*.xml"), TemplatePath
32
+ end
33
+
34
+ # 生成 templatelist.properties 文件
35
+ def self.generateProperties()
36
+ nowTimestamp = Time.now.to_i
37
+ propertiesContent = Dir.entries(TemplatePath).reject { |f| File.directory? f } .map { |f|
38
+ filename = File.basename f, '.*'
39
+ "#{filename}=#{filename},#{nowTimestamp}"
40
+ }
41
+ File.open(PropertiesFilePath, 'w+') { |f|
42
+ propertiesContent.each { |e| f.puts e }
43
+ }
44
+ end
45
+
46
+ def self.checkVVCompiler()
47
+ if File.exist? VVCompilerFilePath
48
+ puts 'Check VV compiler ok.'
49
+ else
50
+ puts 'Start downloading VV compiler.jar...'
51
+ File.write(VVCompilerFilePath, Net::HTTP.get(URI.parse(VVCompilerDownloadURL)))
52
+ if File.exist? VVCompilerFilePath
53
+ puts 'VV compiler.jar download success.'
54
+ else
55
+ puts 'VV compiler.jar download fail.'
56
+ exit
57
+ end
58
+ end
59
+ end
60
+
61
+ # 编译
62
+ def self.vvbuild()
63
+ system "java -jar #{VVCompilerFilePath} jarBuild > #{VVBuildLogFilePath}"
64
+ end
65
+
66
+ def self.generateDataJSON(aTemplatesPath)
67
+ # 生成每个模版对应的 data.json
68
+ templateNameList = []
69
+ Pathname.new(aTemplatesPath).children.push(aTemplatesPath).each { | aTemplatePath |
70
+ templateName = File.basename aTemplatePath, '.*'
71
+
72
+ next if not File.directory? aTemplatePath
73
+ next if not File.exist?(File.join(aTemplatePath, "#{templateName}.json"))
74
+ next if templateName.start_with? '.'
75
+
76
+ # 把所有模版名记录下来
77
+ templateNameList << templateName
78
+
79
+ # 获取这个模版目录下所有 xml 的编译二进制 Base64 列表
80
+ xmlBase64List = []
81
+ Dir.glob(File.join(aTemplatePath, '**/*.xml')).each { | xmlFilePath |
82
+ xmlFileName = File.basename xmlFilePath, '.*'
83
+
84
+ # 获取这个 xml 的 .out -> base64
85
+ xmlBuildOutPath = File.join(VVBuildPath, "out/#{xmlFileName}.out")
86
+ xmlBase64String = Base64.strict_encode64(File.open(xmlBuildOutPath, "rb").read)
87
+ xmlBase64List << xmlBase64String
88
+ }
89
+
90
+ # 读取模版参数 JSON
91
+ templateParams = {}
92
+ templateParamsJSONPath = File.join(aTemplatePath, "#{templateName}.json")
93
+ if File.exist?(templateParamsJSONPath)
94
+ templateParams = JSON.parse(File.read(templateParamsJSONPath))
95
+ end
96
+
97
+
98
+ # 合并 data.json (HTTP Server 读取)
99
+ if xmlBase64List.count > 0
100
+ dataHash = {'templates': xmlBase64List, 'data': templateParams,}
101
+ dataJSONPath = File.join(aTemplatePath, "data.json")
102
+ File.open(dataJSONPath, "w") { |f|
103
+ f.write(JSON.pretty_generate dataHash)
104
+ }
105
+ end
106
+ }
107
+
108
+ # 生成模版目录结构 .dir(HTTP Server 读取)
109
+ File.open(DirFilePath, "w") { |f|
110
+ f.write(JSON.pretty_generate templateNameList)
111
+ }
112
+ end
113
+
114
+ def self.clean()
115
+ FileUtils.rm_rf TemplatePath
116
+ FileUtils.rm_rf VVBuildPath
117
+ FileUtils.rm_f PropertiesFilePath
118
+ end
119
+ end
120
+
121
+ # 第一次
122
+ def firstBuild()
123
+ # 0. Clean
124
+ VVPrepare.clean
125
+
126
+ # 0.1 检查编译器 - 没有则下载
127
+ VVPrepare.checkVVCompiler()
128
+
129
+ puts 'Start build templates...'
130
+
131
+ # 1. 拷贝出来集中所有 .xml 模版文件
132
+ VVPrepare.copyXML TemplatesPath
133
+
134
+ # 2. 生成 compiler.jar 编译所需的 templatelist.properties 文件
135
+ VVPrepare.generateProperties
136
+
137
+ # 3. 编译
138
+ VVPrepare.vvbuild
139
+
140
+ # 4. 生成 data.json
141
+ VVPrepare.generateDataJSON TemplatesPath
142
+
143
+ # 5. Clean
144
+ VVPrepare.clean
145
+
146
+ puts 'All templates build finished.'
147
+ end
148
+
149
+ # 单次编译
150
+ public def singleBuild(aTemplatePath)
151
+ # 0. Clean
152
+ VVPrepare.clean
153
+
154
+ # 1. 拷贝出来集中所有 .xml 模版文件
155
+ VVPrepare.copyXML aTemplatePath
156
+
157
+
158
+ # 2. 生成 compiler.jar 编译所需的 templatelist.properties 文件
159
+ VVPrepare.generateProperties
160
+
161
+ # 3. 编译
162
+ VVPrepare.vvbuild
163
+
164
+ # 4. 生成 data.json
165
+ VVPrepare.generateDataJSON aTemplatePath
166
+
167
+ # 5. Clean
168
+ VVPrepare.clean
169
+ end
170
+
171
+ def live_server_run
172
+ firstBuild()
173
+
174
+ puts TemplatesPath
175
+ # HTTP Server
176
+ Thread.new {
177
+ http_server = WEBrick::HTTPServer.new(
178
+ :Port => 7788,
179
+ :DocumentRoot => TemplatesPath,
180
+ :Logger => WEBrick::Log.new(VVBuildLogFilePath),
181
+ :AccessLog => []
182
+ )
183
+ http_server.start
184
+ }
185
+
186
+ puts 'Start HTTP server: http://127.0.0.1:7788'
187
+
188
+ # File Watch
189
+ listener = Listen.to(TemplatesPath, only: [/\.xml$/, /\.json$/]) { |modified, added, removed|
190
+ (modified + added).each { |filePath|
191
+ thisTemplatePath = Pathname.new(filePath).dirname
192
+ thisTemplateName = File.basename filePath, '.*'
193
+ thisTemplateNameAndExt = File.basename filePath
194
+ next if thisTemplateNameAndExt == 'data.json'
195
+ puts "[#{ Time.now.strftime("%H:%M:%S") }] Update template: #{thisTemplateName} (#{thisTemplateNameAndExt})"
196
+
197
+ self.singleBuild thisTemplatePath
198
+ VVPrepare.clean
199
+ $buildCount += 1
200
+ }
201
+ }.start
202
+
203
+ puts 'Start Watching...'
204
+ puts ''
205
+
206
+ trap "SIGINT" do
207
+ puts ''
208
+ puts "Bye, see you next time, build count: #{$buildCount}"
209
+
210
+ # clean
211
+ FileUtils.rm_f VVBuildLogFilePath
212
+ FileUtils.rm_f DirFilePath
213
+
214
+ exit 130
215
+ end
216
+
217
+ sleep
218
+ end
@@ -0,0 +1,3 @@
1
+ module VVTool
2
+ VERSION = "0.1.0"
3
+ end
data/lib/vvtool.rb ADDED
@@ -0,0 +1,21 @@
1
+ #!/usr/bin/ruby
2
+
3
+ require "vvtool/version"
4
+ require "live_server.rb"
5
+ require 'Thor'
6
+
7
+ module VVTool
8
+ class CLI < Thor
9
+ desc "run", "启动 VirtualView 实时预览服务"
10
+ def runLiveServer
11
+ live_server_run
12
+ end
13
+
14
+ desc "about", "关于"
15
+ def about
16
+ puts "这个命令主要用于 VirtualView 实时预览"
17
+ end
18
+ end
19
+ end
20
+
21
+ VVTool::CLI.start(ARGV)
data/vvtool.gemspec ADDED
@@ -0,0 +1,30 @@
1
+ lib = File.expand_path("../lib", __FILE__)
2
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
+ require "vvtool/version"
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = "vvtool"
7
+ spec.version = VVTool::VERSION
8
+ spec.authors = ["isaced"]
9
+ spec.email = ["isaced@163.com"]
10
+
11
+ spec.summary = "VVTool - VirtualView 工具集."
12
+ spec.description = "目前可用于结合 VVPlayground 支持 VirtualView 模版开发实时预览."
13
+ spec.homepage = "https://github.com/isaced/VVTool"
14
+ spec.license = "MIT"
15
+
16
+ # Specify which files should be added to the gem when it is released.
17
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
18
+ spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
19
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
20
+ end
21
+
22
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
23
+ spec.require_paths = ["lib"]
24
+
25
+ spec.add_development_dependency "bundler", "~> 1.16"
26
+ spec.add_development_dependency "rake", "~> 10.0"
27
+
28
+ spec.add_dependency "thor", "~> 0.20"
29
+ spec.add_dependency "listen", "~> 3.0"
30
+ end
metadata ADDED
@@ -0,0 +1,112 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: vvtool
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - isaced
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2018-08-02 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.16'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.16'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: thor
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '0.20'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '0.20'
55
+ - !ruby/object:Gem::Dependency
56
+ name: listen
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '3.0'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '3.0'
69
+ description: 目前可用于结合 VVPlayground 支持 VirtualView 模版开发实时预览.
70
+ email:
71
+ - isaced@163.com
72
+ executables:
73
+ - vvtool
74
+ extensions: []
75
+ extra_rdoc_files: []
76
+ files:
77
+ - ".gitignore"
78
+ - Gemfile
79
+ - Gemfile.lock
80
+ - LICENSE.txt
81
+ - README.md
82
+ - Rakefile
83
+ - bin/vvtool
84
+ - lib/live_server.rb
85
+ - lib/vvtool.rb
86
+ - lib/vvtool/version.rb
87
+ - vvtool.gemspec
88
+ homepage: https://github.com/isaced/VVTool
89
+ licenses:
90
+ - MIT
91
+ metadata: {}
92
+ post_install_message:
93
+ rdoc_options: []
94
+ require_paths:
95
+ - lib
96
+ required_ruby_version: !ruby/object:Gem::Requirement
97
+ requirements:
98
+ - - ">="
99
+ - !ruby/object:Gem::Version
100
+ version: '0'
101
+ required_rubygems_version: !ruby/object:Gem::Requirement
102
+ requirements:
103
+ - - ">="
104
+ - !ruby/object:Gem::Version
105
+ version: '0'
106
+ requirements: []
107
+ rubyforge_project:
108
+ rubygems_version: 2.5.1
109
+ signing_key:
110
+ specification_version: 4
111
+ summary: VVTool - VirtualView 工具集.
112
+ test_files: []