aimtp 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/bin/aimtp +13 -0
- data/lib/aimtp.rb +195 -0
- metadata +45 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: cfef737c86b72194a7d559f30ba73d5b4fff829748d90e4aef147c10be422461
|
4
|
+
data.tar.gz: 74063cfd4c0353322679ed33b242951659c9b8edf78d2b0d858b5a6a1edf4aa9
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: b39459033aa5e1e22e3c5f9ca6f9d97566fa7340c54e63c800b1f35b2535f840863f123f8f9785092f3b4e0c16d530b6f26620d42351dc8b2d8a5f1d8dc624e2
|
7
|
+
data.tar.gz: b4c2c70ba852b3447cb165c53176fe38ad53f1782b86600c99ea9a9029d65891b827267d82e2bc191018fe2d4cc855403fd4d9e81e099734af9dd9c8517e76c5
|
data/bin/aimtp
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "aimtp"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
system("aimtp.rb")
|
data/lib/aimtp.rb
ADDED
@@ -0,0 +1,195 @@
|
|
1
|
+
include FileTest
|
2
|
+
require "fileutils"
|
3
|
+
|
4
|
+
@module_arr = [] #所有模块名称
|
5
|
+
$dep_arr = [] #依赖名称
|
6
|
+
$sub_pod_path_hash = Hash.new #子模块的名称和来源路径
|
7
|
+
$sub_pod_hash = Hash.new #子模块的名称和去向路径
|
8
|
+
$sub_need_root_hash = Hash.new #子模块是否只拷贝内容不创建根文件夹
|
9
|
+
$sub_file_path_arr = [] #子模块Aimfile的路径,包含主模块的Aimfile
|
10
|
+
|
11
|
+
|
12
|
+
class Template
|
13
|
+
attr_accessor :name
|
14
|
+
@c_path_arr = []
|
15
|
+
@tp_list = []
|
16
|
+
|
17
|
+
class << self
|
18
|
+
def config(name, &block)
|
19
|
+
tp = new
|
20
|
+
block.call(tp)
|
21
|
+
tp.name = name
|
22
|
+
@c_path_arr << name
|
23
|
+
@tp_list << tp
|
24
|
+
tp
|
25
|
+
end
|
26
|
+
|
27
|
+
def ret_all_module
|
28
|
+
@c_path_arr
|
29
|
+
end
|
30
|
+
|
31
|
+
def find_by_name(tp_name)
|
32
|
+
@tp_list.find { |tp| tp.name == tp_name }
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
def sub(name, path, nRoot = 1)
|
37
|
+
$sub_file_path_arr << 'sources/' + name + '/Aimfile'
|
38
|
+
name_arr = name.split('/')
|
39
|
+
mod_name = name_arr[name_arr.length - 1]
|
40
|
+
$sub_pod_hash[mod_name] = path
|
41
|
+
$sub_pod_path_hash[mod_name] = name
|
42
|
+
$sub_need_root_hash[mod_name] = nRoot
|
43
|
+
end
|
44
|
+
|
45
|
+
def pod(name, options = {})
|
46
|
+
if options == {}
|
47
|
+
$dep_arr.push('"' + name + '"')
|
48
|
+
elsif options.is_a? String
|
49
|
+
$dep_arr.push('"' + name + '"' + ', ' + '"' + options + '"')
|
50
|
+
elsif options.is_a? Hash
|
51
|
+
o_str = options.to_s
|
52
|
+
o_str = o_str.gsub(/[\{\}]/, '')
|
53
|
+
$dep_arr.push('"' + name + '"' + ', ' + o_str)
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
def sub(name, path, nRoot = 1)
|
59
|
+
$sub_file_path_arr << 'sources/' + name + '/Aimfile'
|
60
|
+
name_arr = name.split('/')
|
61
|
+
mod_name = name_arr[name_arr.length - 1]
|
62
|
+
$sub_pod_hash[mod_name] = path
|
63
|
+
$sub_pod_path_hash[mod_name] = name
|
64
|
+
$sub_need_root_hash[mod_name] = nRoot
|
65
|
+
end
|
66
|
+
|
67
|
+
def pod(name, options = {})
|
68
|
+
if options == {}
|
69
|
+
$dep_arr.push('"' + name + '"')
|
70
|
+
elsif options.is_a? String
|
71
|
+
$dep_arr.push('"' + name + '"' + ', ' + '"' + options + '"')
|
72
|
+
elsif options.is_a? Hash
|
73
|
+
o_str = options.to_s
|
74
|
+
o_str = o_str.gsub(/[\{\}]/, '')
|
75
|
+
$dep_arr.push('"' + name + '"' + ', ' + o_str)
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
# 循环深入文件夹
|
80
|
+
def traverse(from_path, to_path)
|
81
|
+
if File.directory?(from_path) # 如果是目录
|
82
|
+
if !FileTest.exist?(to_path)
|
83
|
+
FileUtils.mkdir_p(to_path)
|
84
|
+
end
|
85
|
+
dir = Dir.open(from_path)
|
86
|
+
while name = dir.read
|
87
|
+
next if name == "." # ※
|
88
|
+
next if name == ".." # ※
|
89
|
+
traverse(from_path + "/" + name, to_path + "/" + name)
|
90
|
+
end
|
91
|
+
dir.close
|
92
|
+
else
|
93
|
+
process_file(from_path, to_path) # 处理文件
|
94
|
+
end
|
95
|
+
end
|
96
|
+
|
97
|
+
# 拷贝文件
|
98
|
+
def process_file(from_path, to_path)
|
99
|
+
FileUtils.cp(from_path, to_path)
|
100
|
+
end
|
101
|
+
|
102
|
+
# 删除模块中的Aimfile
|
103
|
+
def delete_config_file(path)
|
104
|
+
file_name = path + '/Aimfile'
|
105
|
+
if FileTest.exist?(file_name)
|
106
|
+
FileUtils.rm(file_name)
|
107
|
+
end
|
108
|
+
end
|
109
|
+
|
110
|
+
# 加载主模块Aimfile
|
111
|
+
main_aimfile_path = './Aimfile'
|
112
|
+
if !FileTest.exist?(main_aimfile_path)
|
113
|
+
puts "Aimfile is not exist at current folder."
|
114
|
+
exit
|
115
|
+
else
|
116
|
+
content = File.read main_aimfile_path
|
117
|
+
eval content
|
118
|
+
end
|
119
|
+
|
120
|
+
# 将主模块的Aimfile单独添加进来,保证主工程的依赖也能引入
|
121
|
+
@module_arr = Template.ret_all_module.uniq
|
122
|
+
pro_dir_str = @module_arr[0]
|
123
|
+
$sub_file_path_arr << 'sources/' + pro_dir_str + '/Aimfile'
|
124
|
+
main_tp = Template.find_by_name(pro_dir_str)
|
125
|
+
|
126
|
+
# 拷贝模板主工程文件夹,主工程是@module_arr数组的第一个
|
127
|
+
traverse('sources/' + pro_dir_str, pro_dir_str)
|
128
|
+
|
129
|
+
# 加载子模块Aimfile
|
130
|
+
$sub_file_path_arr.each do |sub_str|
|
131
|
+
if !FileTest.exist?(sub_str)
|
132
|
+
puts "#{sub_str} is not exist."
|
133
|
+
else
|
134
|
+
sub_content = File.read sub_str
|
135
|
+
eval sub_content
|
136
|
+
end
|
137
|
+
end
|
138
|
+
|
139
|
+
# 依赖去重
|
140
|
+
$dep_arr = $dep_arr.uniq
|
141
|
+
@module_arr = Template.ret_all_module.uniq
|
142
|
+
|
143
|
+
# puts @module_arr
|
144
|
+
# puts $dep_arr
|
145
|
+
# puts $sub_pod_hash
|
146
|
+
# puts $sub_pod_path_hash
|
147
|
+
|
148
|
+
# 拷贝子模块文件夹
|
149
|
+
reg = Regexp.new(/\/$/)
|
150
|
+
@module_arr.each_with_index do |module_str, index|
|
151
|
+
if module_str != main_tp.name
|
152
|
+
cur_url = $sub_pod_hash[module_str]
|
153
|
+
nRoot = $sub_need_root_hash[module_str]
|
154
|
+
if nRoot == 0
|
155
|
+
to_path = cur_url
|
156
|
+
else
|
157
|
+
if reg =~ cur_url
|
158
|
+
to_path = cur_url + module_str
|
159
|
+
else
|
160
|
+
to_path = cur_url + '/' + module_str
|
161
|
+
end
|
162
|
+
end
|
163
|
+
# puts to_path
|
164
|
+
cur_from_path = $sub_pod_path_hash[module_str]
|
165
|
+
traverse('sources/' + cur_from_path, to_path)
|
166
|
+
delete_config_file(to_path)
|
167
|
+
end
|
168
|
+
end
|
169
|
+
|
170
|
+
# 删除主模块中的Aimfile
|
171
|
+
delete_config_file(main_tp.name)
|
172
|
+
|
173
|
+
# 添加依赖到podspec文件
|
174
|
+
podspec_path = "aim_project/{{cookiecutter.product_name}}/{{cookiecutter.product_name}}.podspec"
|
175
|
+
if FileTest.exist?(podspec_path)
|
176
|
+
File.open(podspec_path, "a") do |file|
|
177
|
+
$dep_arr.each do |dep_name|
|
178
|
+
file.puts("\ts.dependency " + dep_name + "\n")
|
179
|
+
end
|
180
|
+
file.puts :end
|
181
|
+
file.close
|
182
|
+
end
|
183
|
+
end
|
184
|
+
|
185
|
+
# 添加依赖到podfile文件
|
186
|
+
podfile_path = "aim_project/{{cookiecutter.product_name}}/App/Podfile"
|
187
|
+
if FileTest.exist?(podfile_path)
|
188
|
+
File.open(podfile_path, "a") do |file|
|
189
|
+
$dep_arr.each do |dep_name|
|
190
|
+
file.puts("\tpod " + dep_name + "\n")
|
191
|
+
end
|
192
|
+
file.puts :end
|
193
|
+
file.close
|
194
|
+
end
|
195
|
+
end
|
metadata
ADDED
@@ -0,0 +1,45 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: aimtp
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- ZhangLe
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2020-08-24 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
13
|
+
description: 项目模板生成工具,可自定义选择需要接入的模块。
|
14
|
+
email: zhangle6@asiainfo.com
|
15
|
+
executables:
|
16
|
+
- aimtp
|
17
|
+
extensions: []
|
18
|
+
extra_rdoc_files: []
|
19
|
+
files:
|
20
|
+
- bin/aimtp
|
21
|
+
- lib/aimtp.rb
|
22
|
+
homepage: http://rubygems.org
|
23
|
+
licenses:
|
24
|
+
- MIT
|
25
|
+
metadata: {}
|
26
|
+
post_install_message:
|
27
|
+
rdoc_options: []
|
28
|
+
require_paths:
|
29
|
+
- lib
|
30
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
31
|
+
requirements:
|
32
|
+
- - ">="
|
33
|
+
- !ruby/object:Gem::Version
|
34
|
+
version: '0'
|
35
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
36
|
+
requirements:
|
37
|
+
- - ">="
|
38
|
+
- !ruby/object:Gem::Version
|
39
|
+
version: '0'
|
40
|
+
requirements: []
|
41
|
+
rubygems_version: 3.0.3
|
42
|
+
signing_key:
|
43
|
+
specification_version: 4
|
44
|
+
summary: 项目模板生成工具
|
45
|
+
test_files: []
|