flr 1.0.0 → 3.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +3 -1
- data/CHANGELOG.md +37 -0
- data/Gemfile.lock +1 -1
- data/lib/flr.rb +11 -3
- data/lib/flr/checker.rb +16 -13
- data/lib/flr/command.rb +447 -137
- data/lib/flr/constant.rb +5 -1
- data/lib/flr/util/asset_util.rb +325 -32
- data/lib/flr/util/code_util.rb +226 -47
- data/lib/flr/util/file_util.rb +154 -22
- data/lib/flr/version.rb +2 -2
- metadata +3 -3
data/lib/flr/util/file_util.rb
CHANGED
@@ -8,20 +8,36 @@ module Flr
|
|
8
8
|
|
9
9
|
# get_cur_flutter_project_root_dir -> String
|
10
10
|
#
|
11
|
-
#
|
11
|
+
# 获取flutter主工程的根目录
|
12
12
|
#
|
13
|
-
def self.
|
13
|
+
def self.get_flutter_main_project_root_dir
|
14
14
|
flutter_project_root_dir = "#{Pathname.pwd}"
|
15
15
|
return flutter_project_root_dir
|
16
16
|
end
|
17
17
|
|
18
|
-
#
|
18
|
+
# get_flutter_sub_project_root_dirs -> [sub_project_root_dir]
|
19
|
+
#
|
20
|
+
# 获取flutter主工程的所有子工程的根目录
|
21
|
+
#
|
22
|
+
def self.get_flutter_sub_project_root_dirs(flutter_main_project_root_dir)
|
23
|
+
flutter_sub_project_root_dir_array = []
|
24
|
+
Dir.glob(["#{flutter_main_project_root_dir}/*/pubspec.yaml"]).each do |file|
|
25
|
+
flutter_project_root_dir = File.dirname(file)
|
26
|
+
flutter_sub_project_root_dir_array.push(flutter_project_root_dir)
|
27
|
+
end
|
28
|
+
return flutter_sub_project_root_dir_array
|
29
|
+
end
|
30
|
+
|
31
|
+
# get_pubspec_file_path(flutter_project_dir) -> String
|
19
32
|
#
|
20
33
|
# 获取当前flutter工程的pubspec.yaml文件的路径
|
21
34
|
#
|
22
|
-
|
23
|
-
|
24
|
-
|
35
|
+
# === Examples
|
36
|
+
# flutter_project_dir = "~/path/to/flutter_r_demo"
|
37
|
+
# pubspec_file_path = "~/path/to/flutter_r_demo/pubspec.yaml"
|
38
|
+
#
|
39
|
+
def self.get_pubspec_file_path(flutter_project_dir)
|
40
|
+
file_path = flutter_project_dir + "/pubspec.yaml"
|
25
41
|
return file_path
|
26
42
|
end
|
27
43
|
|
@@ -79,6 +95,120 @@ module Flr
|
|
79
95
|
return true
|
80
96
|
end
|
81
97
|
|
98
|
+
# is_package_project_type?(flutter_project_dir) -> true or false
|
99
|
+
#
|
100
|
+
# 判断当前flutter工程的工程类型是不是Package工程类型
|
101
|
+
#
|
102
|
+
# flutter工程共有4种工程类型:
|
103
|
+
# - app:Flutter App工程,用于开发纯Flutter的App
|
104
|
+
# - module:Flutter Component工程,用于开发Flutter组件以嵌入iOS和Android原生工程
|
105
|
+
# - package:General Dart Package工程,用于开发一个供应用层开发者使用的包
|
106
|
+
# - plugin:Plugin Package工程(属于特殊的Dart Package工程),用于开发一个调用特定平台API的包
|
107
|
+
#
|
108
|
+
# flutter工程的工程类型可从flutter工程目录的 .metadata 文件中读取获得
|
109
|
+
# 如果不存在 .metadata 文件,则判断 pubspec.yaml 是否存在 author 配置,若存在,说明是一个 Package工程
|
110
|
+
#
|
111
|
+
def self.is_package_project_type?(flutter_project_dir)
|
112
|
+
metadata_file_path = flutter_project_dir + "/.metadata"
|
113
|
+
|
114
|
+
if File.exist?(metadata_file_path)
|
115
|
+
begin
|
116
|
+
metadata_file = File.open(metadata_file_path, 'r')
|
117
|
+
metadata_config = YAML.load(metadata_file)
|
118
|
+
project_type = metadata_config["project_type"]
|
119
|
+
if project_type.nil?
|
120
|
+
project_type = "unknown"
|
121
|
+
end
|
122
|
+
project_type = project_type.downcase
|
123
|
+
|
124
|
+
if project_type == "package" || project_type == "plugin"
|
125
|
+
return true
|
126
|
+
end
|
127
|
+
|
128
|
+
rescue YAML::SyntaxError => e
|
129
|
+
puts("YAML Syntax Error: #{e}".error_style)
|
130
|
+
puts("")
|
131
|
+
ensure
|
132
|
+
metadata_file.close
|
133
|
+
end
|
134
|
+
else
|
135
|
+
message = <<-MESSAGE
|
136
|
+
#{"[!]: warning, metadata file is missed, flr can not make sure to get a right project type of this flutter project".warning_style}
|
137
|
+
#{"[!]: then flr maybe generate buggy r.g.dart".warning_style}
|
138
|
+
#{"[*]: to fix it, you can manually copy the metadata file of a flutter project with same project type to #{metadata_file_path}".tips_style}
|
139
|
+
|
140
|
+
MESSAGE
|
141
|
+
puts(message)
|
142
|
+
|
143
|
+
begin
|
144
|
+
pubspec_file_path = get_pubspec_file_path(flutter_project_dir)
|
145
|
+
pubspec_config = load_pubspec_config_from_file(pubspec_file_path)
|
146
|
+
if pubspec_config.has_key?("author")
|
147
|
+
return true
|
148
|
+
end
|
149
|
+
rescue Exception => e
|
150
|
+
puts(e.message)
|
151
|
+
end
|
152
|
+
end
|
153
|
+
|
154
|
+
return false
|
155
|
+
end
|
156
|
+
|
157
|
+
# 判断当前文件是不是非SVG类图片资源文件
|
158
|
+
def self.is_non_svg_image_resource_file?(file)
|
159
|
+
file_extname = File.extname(file).downcase
|
160
|
+
|
161
|
+
if Flr::NON_SVG_IMAGE_FILE_TYPES.include?(file_extname)
|
162
|
+
return true;
|
163
|
+
end
|
164
|
+
|
165
|
+
return false
|
166
|
+
end
|
167
|
+
|
168
|
+
# 判断当前文件是不是SVG类图片资源文件
|
169
|
+
def self.is_svg_image_resource_file?(file)
|
170
|
+
file_extname = File.extname(file).downcase
|
171
|
+
|
172
|
+
if Flr::SVG_IMAGE_FILE_TYPES.include?(file_extname)
|
173
|
+
return true;
|
174
|
+
end
|
175
|
+
|
176
|
+
return false
|
177
|
+
end
|
178
|
+
|
179
|
+
# 判断当前文件是不是图片资源文件
|
180
|
+
def self.is_image_resource_file?(file)
|
181
|
+
file_extname = File.extname(file).downcase
|
182
|
+
|
183
|
+
if Flr::IMAGE_FILE_TYPES.include?(file_extname)
|
184
|
+
return true;
|
185
|
+
end
|
186
|
+
|
187
|
+
return false
|
188
|
+
end
|
189
|
+
|
190
|
+
# 判断当前文件是不是文本资源文件
|
191
|
+
def self.is_text_resource_file?(file)
|
192
|
+
file_extname = File.extname(file).downcase
|
193
|
+
|
194
|
+
if Flr::TEXT_FILE_TYPES.include?(file_extname)
|
195
|
+
return true;
|
196
|
+
end
|
197
|
+
|
198
|
+
return false
|
199
|
+
end
|
200
|
+
|
201
|
+
# 判断当前文件是不是字体资源文件
|
202
|
+
def self.is_font_resource_file?(file)
|
203
|
+
file_extname = File.extname(file).downcase
|
204
|
+
|
205
|
+
if Flr::FONT_FILE_TYPES.include?(file_extname)
|
206
|
+
return true;
|
207
|
+
end
|
208
|
+
|
209
|
+
return false
|
210
|
+
end
|
211
|
+
|
82
212
|
# is_legal_resource_file??(file) -> true or false
|
83
213
|
#
|
84
214
|
# 判断当前资源文件是否合法
|
@@ -87,8 +217,8 @@ module Flr
|
|
87
217
|
# 其file_basename_no_extension 由字母(a-z、A-Z)、数字(0-9)、其他合法字符('_', '+', '-', '.', '·', '!', '@', '&', '$', '¥')组成
|
88
218
|
#
|
89
219
|
# === Examples
|
90
|
-
# good_file = "lib/assets/images/test.png"
|
91
|
-
# bad_file = "lib/assets/images/~.png"
|
220
|
+
# good_file = "~/path/to/flutter_project/lib/assets/images/test.png"
|
221
|
+
# bad_file = "~/path/to/flutter_project/lib/assets/images/~.png"
|
92
222
|
# is_legal_resource_file?(good_file) -> true
|
93
223
|
# is_legal_resource_file?(bad_file) -> false
|
94
224
|
#
|
@@ -105,25 +235,26 @@ module Flr
|
|
105
235
|
|
106
236
|
# find_image_files(resource_dir) -> image_file_result_tuple
|
107
237
|
#
|
108
|
-
#
|
238
|
+
# 扫描指定的资源目录和其所有层级的子目录,查找所有图片文件
|
109
239
|
# 返回图片文件结果二元组 image_file_result_tuple
|
110
240
|
# image_file_result_tuple = [legal_image_file_array, illegal_image_file_array]
|
111
241
|
#
|
112
242
|
# 判断文件合法的标准参考 self.is_legal_resource_file? 方法
|
113
243
|
#
|
114
244
|
# === Examples
|
115
|
-
# resource_dir = "lib/assets/images"
|
116
|
-
# legal_image_file_array = ["lib/assets/images/test.png", "lib/assets/images/2.0x/test.png"]
|
117
|
-
# illegal_image_file_array = ["lib/assets/images/~.png"]
|
245
|
+
# resource_dir = "~/path/to/flutter_project/lib/assets/images"
|
246
|
+
# legal_image_file_array = ["~/path/to/flutter_project/lib/assets/images/test.png", "~/path/to/flutter_project/lib/assets/images/2.0x/test.png"]
|
247
|
+
# illegal_image_file_array = ["~/path/to/flutter_project/lib/assets/images/~.png"]
|
118
248
|
#
|
119
249
|
def self.find_image_files(resource_dir)
|
120
250
|
legal_image_file_array = []
|
121
251
|
illegal_image_file_array = []
|
122
252
|
|
123
253
|
pattern_file_types = Flr::IMAGE_FILE_TYPES.join(",")
|
124
|
-
# dir/*{.png
|
125
|
-
# dir/*/*{.png
|
126
|
-
|
254
|
+
# dir/*{.png,.jpg} : 查找当前目录的指定类型文件
|
255
|
+
# dir/*/*{.png,.jpg}: 查找当前目录的第1级子目录的指定类型文件
|
256
|
+
# dir/**/*{.png,.jpg}: 查找当前目录和其所有子目录的指定类型文件
|
257
|
+
Dir.glob(["#{resource_dir}/**/*{#{pattern_file_types}}"]).each do |file|
|
127
258
|
if is_legal_resource_file?(file)
|
128
259
|
legal_image_file_array.push(file)
|
129
260
|
else
|
@@ -144,9 +275,9 @@ module Flr
|
|
144
275
|
# 判断文件合法的标准参考 self.is_legal_resource_file? 方法
|
145
276
|
#
|
146
277
|
# === Examples
|
147
|
-
# resource_dir = "lib/assets/jsons"
|
148
|
-
# legal_text_file_array = ["lib/assets/jsons/city.json", "lib/assets/jsons/mock/city.json"]
|
149
|
-
# illegal_text_file_array = ["lib/assets/jsons/~.json"]
|
278
|
+
# resource_dir = "~/path/to/flutter_project/lib/assets/jsons"
|
279
|
+
# legal_text_file_array = ["~/path/to/flutter_project/lib/assets/jsons/city.json", "~/path/to/flutter_project/lib/assets/jsons/mock/city.json"]
|
280
|
+
# illegal_text_file_array = ["~/path/to/flutter_project/lib/assets/jsons/~.json"]
|
150
281
|
#
|
151
282
|
def self.find_text_files(resource_dir)
|
152
283
|
legal_text_file_array = []
|
@@ -171,7 +302,8 @@ module Flr
|
|
171
302
|
# 扫描指定的资源目录,返回其所有第一级子目录
|
172
303
|
#
|
173
304
|
# === Examples
|
174
|
-
#
|
305
|
+
# resource_dir = "~/path/to/flutter_project/lib/assets/fonts"
|
306
|
+
# top_child_dir_array = ["~/path/to/flutter_project/lib/assets/fonts/Amiri", "~/path/to/flutter_project/lib/assets/fonts/Open_Sans"]
|
175
307
|
#
|
176
308
|
def self.find_top_child_dirs(resource_dir)
|
177
309
|
top_child_dir_array = []
|
@@ -194,9 +326,9 @@ module Flr
|
|
194
326
|
# 判断文件合法的标准参考 self.is_legal_resource_file? 方法
|
195
327
|
#
|
196
328
|
# === Examples
|
197
|
-
# font_family_dir = "lib/assets/fonts/Amiri"
|
198
|
-
# legal_font_file_array = ["lib/assets/fonts/Amiri/Amiri-Regular.ttf", "lib/assets/fonts/Amiri/Amiri-Bold.ttf"]
|
199
|
-
# illegal_font_file_array = ["lib/assets/fonts/Amiri/~.ttf"]
|
329
|
+
# font_family_dir = "~/path/to/flutter_project/lib/assets/fonts/Amiri"
|
330
|
+
# legal_font_file_array = ["~/path/to/flutter_project/lib/assets/fonts/Amiri/Amiri-Regular.ttf", "~/path/to/flutter_project/lib/assets/fonts/Amiri/Amiri-Bold.ttf"]
|
331
|
+
# illegal_font_file_array = ["~/path/to/flutter_project/lib/assets/fonts/Amiri/~.ttf"]
|
200
332
|
#
|
201
333
|
def self.find_font_files_in_font_family_dir(font_family_dir)
|
202
334
|
legal_font_file_array = []
|
data/lib/flr/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: flr
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 3.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- York
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2021-03-21 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -124,7 +124,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
124
124
|
- !ruby/object:Gem::Version
|
125
125
|
version: '0'
|
126
126
|
requirements: []
|
127
|
-
rubygems_version: 3.
|
127
|
+
rubygems_version: 3.2.13
|
128
128
|
signing_key:
|
129
129
|
specification_version: 4
|
130
130
|
summary: 'Flr(Flutter-R): A Flutter Resource Manager CLI TooL.'
|