flr 1.0.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.
@@ -0,0 +1,221 @@
1
+ require 'yaml'
2
+ require 'flr/constant'
3
+
4
+ module Flr
5
+
6
+ # 资源文件相关的工具类方法
7
+ class FileUtil
8
+
9
+ # get_cur_flutter_project_root_dir -> String
10
+ #
11
+ # 获取当前flutter工程的根目录
12
+ #
13
+ def self.get_cur_flutter_project_root_dir
14
+ flutter_project_root_dir = "#{Pathname.pwd}"
15
+ return flutter_project_root_dir
16
+ end
17
+
18
+ # get_pubspec_file_path -> String
19
+ #
20
+ # 获取当前flutter工程的pubspec.yaml文件的路径
21
+ #
22
+ def self.get_pubspec_file_path
23
+ flutter_project_root_dir = self.get_cur_flutter_project_root_dir
24
+ file_path = flutter_project_root_dir + "/pubspec.yaml"
25
+ return file_path
26
+ end
27
+
28
+ # load_pubspec_config_from_file -> Hash
29
+ #
30
+ # 读取pubspec.yaml到pubspec_config
31
+ # 若读取成功,返回一个Hash对象pubspec_config
32
+ # 若读取失败,则抛出异常
33
+ #
34
+ def self.load_pubspec_config_from_file(pubspec_file_path)
35
+ begin
36
+ pubspec_file = File.open(pubspec_file_path, 'r')
37
+ pubspec_config = YAML.load(pubspec_file)
38
+ rescue YAML::SyntaxError => e
39
+ puts("YAML Syntax Error: #{e}".error_style)
40
+ puts("")
41
+
42
+ message = <<-MESSAGE
43
+
44
+ #{"[x]: pubspec.yaml is damaged with syntax error".error_style}
45
+ #{"[*]: please correct the pubspec.yaml file at #{pubspec_file_path}".tips_style}
46
+ MESSAGE
47
+
48
+ raise(message)
49
+ ensure
50
+ pubspec_file.close
51
+ end
52
+
53
+ return pubspec_config
54
+ end
55
+
56
+ # dump_pubspec_config_to_file -> true
57
+ #
58
+ # 保存pubspec_config到pubspec.yaml
59
+ #
60
+ def self.dump_pubspec_config_to_file(pubspec_config, pubspec_file_path)
61
+ pubspec_file = File.open(pubspec_file_path, 'w')
62
+ yaml_content = pubspec_config.to_yaml
63
+
64
+ # Because pubspec.yaml is only one document remove,
65
+ # and I want to shortcut it,
66
+ # so I choose to remove three dashes (“---”).
67
+ #
68
+ # To get the details about three dashes (“---”)
69
+ # see: https://yaml.org/spec/1.2/spec.html#id2760395
70
+ #
71
+ document_separate_maker = "---\n"
72
+ regx = /\A#{document_separate_maker}/
73
+ if yaml_content =~ regx
74
+ yaml_content[document_separate_maker] = ""
75
+ end
76
+
77
+ pubspec_file.write(yaml_content)
78
+ pubspec_file.close
79
+ return true
80
+ end
81
+
82
+ # is_legal_resource_file??(file) -> true or false
83
+ #
84
+ # 判断当前资源文件是否合法
85
+ #
86
+ # 判断资源文件合法的标准是:
87
+ # 其file_basename_no_extension 由字母(a-z、A-Z)、数字(0-9)、其他合法字符('_', '+', '-', '.', '·', '!', '@', '&', '$', '¥')组成
88
+ #
89
+ # === Examples
90
+ # good_file = "lib/assets/images/test.png"
91
+ # bad_file = "lib/assets/images/~.png"
92
+ # is_legal_resource_file?(good_file) -> true
93
+ # is_legal_resource_file?(bad_file) -> false
94
+ #
95
+ def self.is_legal_resource_file?(file)
96
+ file_basename_no_extension = File.basename(file, ".*")
97
+ regx = /^[a-zA-Z0-9_\+\-\.·!@&$¥]+$/
98
+
99
+ if file_basename_no_extension =~ regx
100
+ return true
101
+ else
102
+ return false
103
+ end
104
+ end
105
+
106
+ # find_image_files(resource_dir) -> image_file_result_tuple
107
+ #
108
+ # 扫描指定的资源目录和其第1级子目录,查找所有图片文件
109
+ # 返回图片文件结果二元组 image_file_result_tuple
110
+ # image_file_result_tuple = [legal_image_file_array, illegal_image_file_array]
111
+ #
112
+ # 判断文件合法的标准参考 self.is_legal_resource_file? 方法
113
+ #
114
+ # === 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"]
118
+ #
119
+ def self.find_image_files(resource_dir)
120
+ legal_image_file_array = []
121
+ illegal_image_file_array = []
122
+
123
+ pattern_file_types = Flr::IMAGE_FILE_TYPES.join(",")
124
+ # dir/*{.png.,.jpg} : 查找当前目录的指定类型文件
125
+ # dir/*/*{.png.,.jpg}: 查找当前目录的第1级子目录的指定类型文件
126
+ Dir.glob(["#{resource_dir}/*{#{pattern_file_types}}", "#{resource_dir}/*/*{#{pattern_file_types}}"]).each do |file|
127
+ if is_legal_resource_file?(file)
128
+ legal_image_file_array.push(file)
129
+ else
130
+ illegal_image_file_array.push(file)
131
+ end
132
+ end
133
+
134
+ image_file_result_tuple = [legal_image_file_array, illegal_image_file_array]
135
+ return image_file_result_tuple
136
+ end
137
+
138
+ # find_text_files(resource_dir) -> text_file_result_tuple
139
+ #
140
+ # 扫描指定的资源目录和其所有层级的子目录,查找所有文本文件
141
+ # 返回文本文件结果二元组 text_file_result_tuple
142
+ # text_file_result_tuple = [legal_text_file_array, illegal_text_file_array]
143
+ #
144
+ # 判断文件合法的标准参考 self.is_legal_resource_file? 方法
145
+ #
146
+ # === 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"]
150
+ #
151
+ def self.find_text_files(resource_dir)
152
+ legal_text_file_array = []
153
+ illegal_text_file_array = []
154
+
155
+ pattern_file_types = Flr::TEXT_FILE_TYPES.join(",")
156
+ # dir/**/*{.json.,.yaml} : 查找当前目录和其所有子目录的指定类型文件
157
+ Dir.glob(["#{resource_dir}/**/*{#{pattern_file_types}}"]).each do |file|
158
+ if is_legal_resource_file?(file)
159
+ legal_text_file_array.push(file)
160
+ else
161
+ illegal_text_file_array.push(file)
162
+ end
163
+ end
164
+
165
+ text_file_result_tuple = [legal_text_file_array, illegal_text_file_array]
166
+ return text_file_result_tuple
167
+ end
168
+
169
+ # find_top_child_dirs(resource_dir) -> top_child_dir_array
170
+ #
171
+ # 扫描指定的资源目录,返回其所有第一级子目录
172
+ #
173
+ # === Examples
174
+ # top_child_dir_array = ["lib/assets/fonts/Amiri", "lib/assets/fonts/Open_Sans"]
175
+ #
176
+ def self.find_top_child_dirs(resource_dir)
177
+ top_child_dir_array = []
178
+
179
+ Dir.glob(["#{resource_dir}/*"]).each do |file|
180
+ if File.directory?(file)
181
+ top_child_dir_array.push(file)
182
+ end
183
+ end
184
+
185
+ return top_child_dir_array
186
+ end
187
+
188
+ # find_font_files_in_font_family_dir(font_family_dir) -> font_file_result_tuple
189
+ #
190
+ # 扫描指定的字体家族目录和其所有层级的子目录,查找所有字体文件
191
+ # 返回字体文件结果二元组 font_file_result_tuple
192
+ # font_file_result_tuple = [legal_font_file_array, illegal_font_file_array]
193
+ #
194
+ # 判断文件合法的标准参考 self.is_legal_resource_file? 方法
195
+ #
196
+ # === 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"]
200
+ #
201
+ def self.find_font_files_in_font_family_dir(font_family_dir)
202
+ legal_font_file_array = []
203
+ illegal_font_file_array = []
204
+
205
+ pattern_file_types = Flr::FONT_FILE_TYPES.join(",")
206
+ # dir/**/*{.ttf.,.ott} : 查找当前目录和其所有子目录的指定类型文件
207
+ Dir.glob(["#{font_family_dir}/**/*{#{pattern_file_types}}"]).each do |file|
208
+ if is_legal_resource_file?(file)
209
+ legal_font_file_array.push(file)
210
+ else
211
+ illegal_font_file_array.push(file)
212
+ end
213
+ end
214
+
215
+ font_file_result_tuple = [legal_font_file_array, illegal_font_file_array]
216
+ return font_file_result_tuple
217
+ end
218
+
219
+ end
220
+
221
+ end
@@ -0,0 +1,38 @@
1
+ module Flr
2
+ # 工具版本号
3
+ VERSION = "1.0.0"
4
+
5
+ # 核心逻辑版本号
6
+ CORE_VERSION = "1.0.0"
7
+
8
+ class Version < Array
9
+ def initialize str
10
+ super(str.split('.').map { |e| e.to_i })
11
+ end
12
+
13
+ def < x
14
+ (self <=> x) < 0
15
+ end
16
+
17
+ def > x
18
+ (self <=> x) > 0
19
+ end
20
+
21
+ def == x
22
+ (self <=> x) == 0
23
+ end
24
+
25
+ def >= x
26
+ a = self > x
27
+ b = self == x
28
+ return (a || b)
29
+ end
30
+
31
+ def <= x
32
+ a = self < x
33
+ b = self == x
34
+ return (a || b)
35
+ end
36
+
37
+ end
38
+ end
metadata ADDED
@@ -0,0 +1,131 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: flr
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - York
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2020-03-29 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: '2.0'
20
+ - - ">="
21
+ - !ruby/object:Gem::Version
22
+ version: 2.0.2
23
+ type: :runtime
24
+ prerelease: false
25
+ version_requirements: !ruby/object:Gem::Requirement
26
+ requirements:
27
+ - - "~>"
28
+ - !ruby/object:Gem::Version
29
+ version: '2.0'
30
+ - - ">="
31
+ - !ruby/object:Gem::Version
32
+ version: 2.0.2
33
+ - !ruby/object:Gem::Dependency
34
+ name: thor
35
+ requirement: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - "~>"
38
+ - !ruby/object:Gem::Version
39
+ version: '1.0'
40
+ - - ">="
41
+ - !ruby/object:Gem::Version
42
+ version: 1.0.1
43
+ type: :runtime
44
+ prerelease: false
45
+ version_requirements: !ruby/object:Gem::Requirement
46
+ requirements:
47
+ - - "~>"
48
+ - !ruby/object:Gem::Version
49
+ version: '1.0'
50
+ - - ">="
51
+ - !ruby/object:Gem::Version
52
+ version: 1.0.1
53
+ - !ruby/object:Gem::Dependency
54
+ name: listen
55
+ requirement: !ruby/object:Gem::Requirement
56
+ requirements:
57
+ - - "~>"
58
+ - !ruby/object:Gem::Version
59
+ version: '3.0'
60
+ - - ">="
61
+ - !ruby/object:Gem::Version
62
+ version: 3.2.1
63
+ type: :runtime
64
+ prerelease: false
65
+ version_requirements: !ruby/object:Gem::Requirement
66
+ requirements:
67
+ - - "~>"
68
+ - !ruby/object:Gem::Version
69
+ version: '3.0'
70
+ - - ">="
71
+ - !ruby/object:Gem::Version
72
+ version: 3.2.1
73
+ description: 'Flr(Flutter-R): A Flutter Resource Manager CLI TooL, which can help
74
+ flutter developer to auto specify assets in pubspec.yaml and generate r.g.dart file
75
+ after he changes the flutter project assets.'
76
+ email:
77
+ - yorkzhang520@gmail.com
78
+ executables:
79
+ - flr
80
+ extensions: []
81
+ extra_rdoc_files: []
82
+ files:
83
+ - ".gitignore"
84
+ - ".rspec"
85
+ - ".travis.yml"
86
+ - CHANGELOG.md
87
+ - CODE_OF_CONDUCT.md
88
+ - Docs/flr_cli_deployment_check_list.md
89
+ - Docs/flr_usage_example_gif_record_scripts.txt
90
+ - Gemfile
91
+ - Gemfile.lock
92
+ - LICENSE.txt
93
+ - Rakefile
94
+ - bin/flr
95
+ - flr.gemspec
96
+ - lib/flr.rb
97
+ - lib/flr/checker.rb
98
+ - lib/flr/command.rb
99
+ - lib/flr/constant.rb
100
+ - lib/flr/string_extensions.rb
101
+ - lib/flr/util/asset_util.rb
102
+ - lib/flr/util/code_util.rb
103
+ - lib/flr/util/file_util.rb
104
+ - lib/flr/version.rb
105
+ homepage: https://github.com/Fly-Mix/flr-cli
106
+ licenses:
107
+ - MIT
108
+ metadata:
109
+ homepage_uri: https://github.com/Fly-Mix/flr-cli
110
+ source_code_uri: https://github.com/Fly-Mix/flr-cli
111
+ changelog_uri: https://github.com/Fly-Mix/flr-cli/blob/master/CHANGELOG.md
112
+ post_install_message:
113
+ rdoc_options: []
114
+ require_paths:
115
+ - lib
116
+ required_ruby_version: !ruby/object:Gem::Requirement
117
+ requirements:
118
+ - - ">="
119
+ - !ruby/object:Gem::Version
120
+ version: '0'
121
+ required_rubygems_version: !ruby/object:Gem::Requirement
122
+ requirements:
123
+ - - ">="
124
+ - !ruby/object:Gem::Version
125
+ version: '0'
126
+ requirements: []
127
+ rubygems_version: 3.0.3
128
+ signing_key:
129
+ specification_version: 4
130
+ summary: 'Flr(Flutter-R): A Flutter Resource Manager CLI TooL.'
131
+ test_files: []