tcms 0.0.1 → 0.9.1
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 +4 -4
- data/Gemfile +1 -1
- data/LICENSE.txt +0 -0
- data/README.md +0 -0
- data/Rakefile +0 -0
- data/bin/tcms +17 -6
- data/lib/tcms.rb +65 -5
- data/lib/tcms/helper.rb +65 -0
- data/lib/tcms/publisher.rb +58 -0
- data/lib/tcms/version.rb +1 -1
- data/server +8 -0
- metadata +15 -14
- data/.gitignore +0 -14
- data/tcms.gemspec +0 -23
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4fb365b173a996cbde60604babc913c56ada8eae
|
4
|
+
data.tar.gz: c108119027212708cec9913e7e2dc763daec11cc
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b14ead2367a951fb0c0971e8dd83f762da0ed557c5a33666a8faa92960c9af40d30110392426dc7ccb50094e8088eb64bd749c1b474e8168de7539e2d33e8adc
|
7
|
+
data.tar.gz: 87e984fa0d42991d7f32c7ce7b3e2f78655532791c8ad7140a8b52471aaa6df791d04af3793dbecdfd3087ba8f16e3aad5de557b28c01308e6b0c1cbefaf69b0
|
data/Gemfile
CHANGED
data/LICENSE.txt
CHANGED
File without changes
|
data/README.md
CHANGED
File without changes
|
data/Rakefile
CHANGED
File without changes
|
data/bin/tcms
CHANGED
@@ -2,11 +2,12 @@
|
|
2
2
|
require 'pathname'
|
3
3
|
require 'optparse'
|
4
4
|
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
require
|
5
|
+
begin
|
6
|
+
command_path = Pathname.new(File.dirname(__FILE__)).realpath.parent.to_s
|
7
|
+
require command_path + '/lib/tcms'
|
8
|
+
rescue
|
9
|
+
require "tcms"
|
10
|
+
end
|
10
11
|
|
11
12
|
#减少
|
12
13
|
#unless File.exist?('project.yml')
|
@@ -21,6 +22,10 @@ opt = OptionParser.new do |opts|
|
|
21
22
|
options[:files] = arr
|
22
23
|
options[:action] = :deploy
|
23
24
|
end
|
25
|
+
opts.on('-b [type]','--build [type]','构建项目') do |type|
|
26
|
+
options[:type] = type
|
27
|
+
options[:action] = :build
|
28
|
+
end
|
24
29
|
opts.on('-h','--help','帮助文档') do |n|
|
25
30
|
puts opts
|
26
31
|
puts '更多参考,请访问-http://wiki.cms.tencent-cloud.com/mars.html'
|
@@ -30,5 +35,11 @@ end.parse!
|
|
30
35
|
|
31
36
|
case options[:action]
|
32
37
|
when :deploy
|
33
|
-
|
38
|
+
if options[:files]
|
39
|
+
Tcms::upload_assets options[:files]
|
40
|
+
else
|
41
|
+
Tcms::deploy_project
|
42
|
+
end
|
43
|
+
when :build
|
44
|
+
Tcms::build_project(options[:type])
|
34
45
|
end
|
data/lib/tcms.rb
CHANGED
@@ -3,6 +3,13 @@ require 'rest_client'
|
|
3
3
|
require 'rake'
|
4
4
|
require 'pathname'
|
5
5
|
|
6
|
+
begin
|
7
|
+
tcms_lib_path = Pathname.new(File.dirname(__FILE__)).realpath.to_s
|
8
|
+
require tcms_lib_path+ '/tcms/publisher'
|
9
|
+
rescue
|
10
|
+
require "tcms/publisher"
|
11
|
+
end
|
12
|
+
|
6
13
|
module Tcms
|
7
14
|
PROJECT_FILE = "project.yml"
|
8
15
|
UPLOAD_CGI = 'http://wizard2.webdev.com/tcms/tools/uploadfile.php'
|
@@ -20,9 +27,7 @@ module Tcms
|
|
20
27
|
puts "#{file}/ 下无assets.yml配置,请配置素材远程频道和目录.."
|
21
28
|
next
|
22
29
|
end
|
23
|
-
|
24
30
|
file_config = self.read_config_file file_path
|
25
|
-
|
26
31
|
if File.directory? file
|
27
32
|
FileList.new(file+'/**/*').each do |f|
|
28
33
|
unless File.directory? f
|
@@ -41,12 +46,21 @@ module Tcms
|
|
41
46
|
def self.upload_file file,config
|
42
47
|
remote_path = config["remotepath"]+'/'+file.sub(/^\w+\//,'')
|
43
48
|
#puts remote_path
|
44
|
-
puts "
|
49
|
+
puts "正在上传#{file}"
|
45
50
|
upload_path = "#{UPLOAD_CGI}?site=#{config["site"]}&channel=#{config["channel"]}&remotepath=#{remote_path}"
|
46
51
|
begin
|
47
|
-
response = RestClient.post(upload_path,:NEW_FILE=>File.new(file)){|response|
|
52
|
+
response = RestClient.post(upload_path,:NEW_FILE=>File.new(file)){|response,request,result|
|
48
53
|
if [200].include? response.code
|
49
|
-
puts '--上传成功!'
|
54
|
+
puts '--上传成功!'+response.description
|
55
|
+
site = config["site"]
|
56
|
+
domain = 'qq.com'
|
57
|
+
|
58
|
+
#业务修正
|
59
|
+
if site.match 'mat1' then domain = "gtimg.cn/#{config["channel"]}" end
|
60
|
+
if site.match 'pingjs' then site = 'rss' end
|
61
|
+
|
62
|
+
url = "http://#{site}.#{domain}/#{remote_path}"
|
63
|
+
puts '--远程地址:'+url
|
50
64
|
end
|
51
65
|
}
|
52
66
|
rescue Exception => e
|
@@ -56,4 +70,50 @@ module Tcms
|
|
56
70
|
puts ''
|
57
71
|
end
|
58
72
|
end
|
73
|
+
|
74
|
+
#发布整个项目
|
75
|
+
def self.deploy_project
|
76
|
+
unless File.exist? PROJECT_FILE
|
77
|
+
puts 'project.yml 不存在,请运行: tcms -create 创建配置文件'
|
78
|
+
return
|
79
|
+
end
|
80
|
+
|
81
|
+
project = self.read_config_file PROJECT_FILE
|
82
|
+
assets = project['assets']
|
83
|
+
#上传素材文件夹
|
84
|
+
FileList.new(assets["folder"]+'/**/*').each do |f|
|
85
|
+
unless File.directory? f
|
86
|
+
if f.include? project["version"].to_s
|
87
|
+
self.upload_file f,assets
|
88
|
+
end
|
89
|
+
end
|
90
|
+
end
|
91
|
+
#上传页面文件
|
92
|
+
#TODO fixed concat upload function
|
93
|
+
pages = project['pages']
|
94
|
+
FileList.new(pages['folder']+"/**/*").each do |f|
|
95
|
+
unless File.directory? f
|
96
|
+
if f.include? 'htm'
|
97
|
+
self.upload_file f,pages
|
98
|
+
end
|
99
|
+
end
|
100
|
+
end
|
101
|
+
end
|
102
|
+
|
103
|
+
def self.build_project type
|
104
|
+
unless type then type = 'dev' end
|
105
|
+
unless ['dev','test','rel','release'].include? type
|
106
|
+
puts '未知命令选项,请选择[dev,test,release].'
|
107
|
+
return
|
108
|
+
end
|
109
|
+
|
110
|
+
project = self.read_config_file PROJECT_FILE
|
111
|
+
FileList.new(project['templates']['folder']+'/**/*').each do |f|
|
112
|
+
result = f.match(/\/(\w+).html?\.erb/)
|
113
|
+
if result
|
114
|
+
publisher = Tcms::Publisher.new(result[1],{"title"=>"aa"},project)
|
115
|
+
publisher.render(type)
|
116
|
+
end
|
117
|
+
end
|
118
|
+
end
|
59
119
|
end
|
data/lib/tcms/helper.rb
ADDED
@@ -0,0 +1,65 @@
|
|
1
|
+
module Tcms
|
2
|
+
module Helper
|
3
|
+
def script_for name
|
4
|
+
if @_build_type == "dev"
|
5
|
+
return _script_for_local name
|
6
|
+
else
|
7
|
+
return _script_for_publish name
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
def _script_for_local name
|
12
|
+
file_path = @_project["scripts"]["folder"]
|
13
|
+
file_content = File.read(file_path+"/#{name}.js",:encoding=>"utf-8")
|
14
|
+
script_output = ''
|
15
|
+
file_output = file_content.gsub(/\/\/=include\s([^\s]+)/){|include_str|
|
16
|
+
matches = /\/\/=include\s([^\s]+)/.match(include_str)
|
17
|
+
file_url = file_path+"/#{matches[1]}.js"
|
18
|
+
script_output+= '<script type="text/javascript" charset="utf-8" src="'+file_url+'"></script>';
|
19
|
+
script_output+="\n"
|
20
|
+
}
|
21
|
+
|
22
|
+
script_output += '<script type="text/javascript" charset="utf-8" src="'+file_path+"/"+name+'.js"></script>'
|
23
|
+
return script_output
|
24
|
+
end
|
25
|
+
|
26
|
+
def _script_for_publish name
|
27
|
+
file_path = @_project["scripts"]["folder"]
|
28
|
+
file_content = File.read(file_path+"/#{name}.js",:encoding=>"utf-8")
|
29
|
+
script_output = "";
|
30
|
+
file_output = file_content.gsub(/\/\/=include\s([^\s]+)/){|include_str|
|
31
|
+
matches = /\/\/=include\s([^\s]+)/.match(include_str)
|
32
|
+
file_url = file_path+"/#{matches[1]}.js"
|
33
|
+
|
34
|
+
unless File.exist?(file_url)
|
35
|
+
puts 'no file include exist!|'+ file_url
|
36
|
+
return
|
37
|
+
end
|
38
|
+
|
39
|
+
File.read(file_url,:encoding=>"utf-8")
|
40
|
+
}
|
41
|
+
publish_name = name+'.'+ @_project["version"].to_s
|
42
|
+
#写文件
|
43
|
+
write_file =file_path+'/'+publish_name+'.js';
|
44
|
+
|
45
|
+
if File.exist? write_file
|
46
|
+
File.delete write_file
|
47
|
+
end
|
48
|
+
|
49
|
+
concat_file = File.open(write_file,'w+')
|
50
|
+
concat_file.write(file_output)
|
51
|
+
|
52
|
+
puts '-生成素材'+publish_name+'.js'
|
53
|
+
|
54
|
+
assets = @_project["assets"]
|
55
|
+
site = assets["site"]
|
56
|
+
domain = 'qq.com'
|
57
|
+
remote_path = assets["remotepath"]
|
58
|
+
if site.match 'mat1' then domain = "gtimg.cn/#{assets["channel"]}" end
|
59
|
+
if site.match 'pingjs' then site = 'rss' end
|
60
|
+
url = "http://#{site}.#{domain}/#{remote_path}"
|
61
|
+
return '<script type="text/javascript" charset="utf-8" src="'+url+"/"+publish_name+'.js?v='+Digest::MD5.hexdigest(file_output)+'"></script>'
|
62
|
+
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
@@ -0,0 +1,58 @@
|
|
1
|
+
require 'digest'
|
2
|
+
require 'erb'
|
3
|
+
require 'json'
|
4
|
+
require 'pathname'
|
5
|
+
|
6
|
+
begin
|
7
|
+
require Pathname.new(File.dirname(__FILE__)).realpath.to_s+'/helper'
|
8
|
+
rescue
|
9
|
+
require "tcms/helper"
|
10
|
+
end
|
11
|
+
|
12
|
+
module Tcms
|
13
|
+
class Publisher
|
14
|
+
#初始化
|
15
|
+
def initialize(name,data,project)
|
16
|
+
@project = project
|
17
|
+
templates = project["templates"]
|
18
|
+
@encoding = project["encoding"]
|
19
|
+
@name = name
|
20
|
+
@data = self.extend_data(data)
|
21
|
+
@template = File.read("#{templates['folder']}/#{name}.html.erb",:encoding=>@encoding)
|
22
|
+
end
|
23
|
+
|
24
|
+
def extend_data data
|
25
|
+
class<<data
|
26
|
+
include Tcms::Helper
|
27
|
+
def method_missing name,*args
|
28
|
+
self[name.to_s]
|
29
|
+
end
|
30
|
+
end
|
31
|
+
data
|
32
|
+
end
|
33
|
+
#直接输出页面地址
|
34
|
+
def render type
|
35
|
+
page = ERB.new(@template)
|
36
|
+
project = @project
|
37
|
+
|
38
|
+
bd = @data.instance_eval{
|
39
|
+
@_build_type = type
|
40
|
+
@_project = project
|
41
|
+
|
42
|
+
binding();
|
43
|
+
}
|
44
|
+
content = page.result(bd)
|
45
|
+
|
46
|
+
write_file_path = @project["pages"]["folder"]+"/"+@name+'.html'
|
47
|
+
if File.exist? write_file_path
|
48
|
+
File.delete write_file_path
|
49
|
+
end
|
50
|
+
|
51
|
+
write_file = File.new(write_file_path,'w+')
|
52
|
+
write_file.puts content
|
53
|
+
write_file.close
|
54
|
+
|
55
|
+
puts "已生成页面#{write_file_path}"
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
data/lib/tcms/version.rb
CHANGED
data/server
ADDED
metadata
CHANGED
@@ -1,60 +1,61 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: tcms
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.9.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
|
-
- '
|
7
|
+
- "'bertwang'"
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-03-
|
11
|
+
date: 2015-03-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- - ~>
|
17
|
+
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
19
|
version: '1.7'
|
20
20
|
type: :development
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
|
-
- - ~>
|
24
|
+
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '1.7'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: rake
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
|
-
- - ~>
|
31
|
+
- - "~>"
|
32
32
|
- !ruby/object:Gem::Version
|
33
33
|
version: '10.0'
|
34
34
|
type: :development
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
|
-
- - ~>
|
38
|
+
- - "~>"
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '10.0'
|
41
41
|
description: TCMS WebApp 互动相关工具,部分功能限于内网&VPN可用。相关文档@raylei.
|
42
42
|
email:
|
43
|
-
- '
|
43
|
+
- "'1060151577@qq.com'"
|
44
44
|
executables:
|
45
45
|
- tcms
|
46
46
|
extensions: []
|
47
47
|
extra_rdoc_files: []
|
48
48
|
files:
|
49
|
-
- .gitignore
|
50
49
|
- Gemfile
|
51
50
|
- LICENSE.txt
|
52
51
|
- README.md
|
53
52
|
- Rakefile
|
53
|
+
- bin/tcms
|
54
54
|
- lib/tcms.rb
|
55
|
+
- lib/tcms/helper.rb
|
56
|
+
- lib/tcms/publisher.rb
|
55
57
|
- lib/tcms/version.rb
|
56
|
-
-
|
57
|
-
- bin/tcms
|
58
|
+
- server
|
58
59
|
homepage: http://dxtool.cms.tencent-cloud.com/
|
59
60
|
licenses:
|
60
61
|
- MIT
|
@@ -65,17 +66,17 @@ require_paths:
|
|
65
66
|
- lib
|
66
67
|
required_ruby_version: !ruby/object:Gem::Requirement
|
67
68
|
requirements:
|
68
|
-
- -
|
69
|
+
- - ">="
|
69
70
|
- !ruby/object:Gem::Version
|
70
71
|
version: '0'
|
71
72
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
72
73
|
requirements:
|
73
|
-
- -
|
74
|
+
- - ">="
|
74
75
|
- !ruby/object:Gem::Version
|
75
76
|
version: '0'
|
76
77
|
requirements: []
|
77
78
|
rubyforge_project:
|
78
|
-
rubygems_version: 2.
|
79
|
+
rubygems_version: 2.2.2
|
79
80
|
signing_key:
|
80
81
|
specification_version: 4
|
81
82
|
summary: TCMS WebApp Tools
|
data/.gitignore
DELETED
data/tcms.gemspec
DELETED
@@ -1,23 +0,0 @@
|
|
1
|
-
# coding: utf-8
|
2
|
-
lib = File.expand_path('../lib', __FILE__)
|
3
|
-
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
-
require 'tcms/version'
|
5
|
-
|
6
|
-
Gem::Specification.new do |spec|
|
7
|
-
spec.name = "tcms"
|
8
|
-
spec.version = Tcms::VERSION
|
9
|
-
spec.authors = ["'bertwang'"]
|
10
|
-
spec.email = ["'1060151577@qq.com'"]
|
11
|
-
spec.summary = %q{TCMS WebApp Tools}
|
12
|
-
spec.description = %q{TCMS WebApp 互动相关工具,部分功能限于内网&VPN可用。相关文档@raylei.}
|
13
|
-
spec.homepage = "http://dxtool.cms.tencent-cloud.com/"
|
14
|
-
spec.license = "MIT"
|
15
|
-
|
16
|
-
spec.files = `git ls-files -z`.split("\x0")
|
17
|
-
spec.executables = ['tcms']
|
18
|
-
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
-
spec.require_paths = ["lib"]
|
20
|
-
|
21
|
-
spec.add_development_dependency "bundler", "~> 1.7"
|
22
|
-
spec.add_development_dependency "rake", "~> 10.0"
|
23
|
-
end
|