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
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 316ebc8040b9907879cfd70d48163feb0804aba01ee376b21a7cb2c3dfa84347
|
4
|
+
data.tar.gz: a45282c1106560d8d4b0c7acb35a0f221a2e0e3fe057977aa339d78f80af43f1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ff1cd35e4be19a8b82af8c27c996ab67e7d37106fd3fcc2f843ea04cb01d89a6b5a65c437308d16cf79d02c9d9b171e6e6d994393ccd05fbf2fdb735b7b9b2c4
|
7
|
+
data.tar.gz: be14c260f62e3421587569ec97f091278e98443474f3e074e7ccb1efcb6ee95d36c6293269c95c593472522859a88b487a43bac23bf77111b29d3f0200189b53
|
data/.gitignore
CHANGED
data/CHANGELOG.md
CHANGED
@@ -1,4 +1,41 @@
|
|
1
|
+
## 3.2.0
|
2
|
+
|
3
|
+
- Support for nullsafety-feature of Dart 2.12
|
4
|
+
|
5
|
+
## 3.1.0
|
6
|
+
|
7
|
+
- Support for processing (init/generate/monitor) multi projects (the main project and its sub projects in one workspace)
|
8
|
+
|
9
|
+
- Support for auto merging old asset specifications when specifying new assets
|
10
|
+
|
11
|
+
> This is can help you to auto keep the manually added asset specifications.
|
12
|
+
|
13
|
+
## 3.0.0
|
14
|
+
|
15
|
+
- Support for processing non-implied resource file
|
16
|
+
|
17
|
+
> - non-implied resource file: the resource file which is outside of `lib/` directory, for example:
|
18
|
+
> - `~/path/to/flutter_r_demo/assets/images/test.png`
|
19
|
+
> - `~/path/to/flutter_r_demo/assets/images/3.0x/test.png`
|
20
|
+
> - implied resource file: the resource file which is inside of `lib/` directory, for example:
|
21
|
+
> - `~/path/to/flutter_r_demo/lib/assets/images/hot_foot_N.png`
|
22
|
+
> - `~/path/to/flutter_r_demo/lib/assets/images/3.0x/hot_foot_N.png`
|
23
|
+
|
24
|
+
- New recommended flutter resource structure
|
25
|
+
|
26
|
+
## 2.0.0
|
27
|
+
|
28
|
+
- New asset generation algorithm to support all kinds of standard or nonstandard image/text resource structure
|
29
|
+
- New asset-id generation algorithm to support assets with the same filename but different path
|
30
|
+
- New recommended flutter resource structure
|
31
|
+
|
32
|
+
## 1.1.0
|
33
|
+
|
34
|
+
- Improve generate-capability to support nonstandard image resource structure
|
35
|
+
- Add recommend-capability to display the recommended flutter resource structure
|
36
|
+
|
1
37
|
## 1.0.0
|
38
|
+
|
2
39
|
- Support for processing font assets ( `.ttf`, `.otf`, `.ttc`)
|
3
40
|
- Improve robustness
|
4
41
|
|
data/Gemfile.lock
CHANGED
data/lib/flr.rb
CHANGED
@@ -42,7 +42,7 @@ More details see https://github.com/Fly-Mix/flr-cli
|
|
42
42
|
|
43
43
|
LONGDESC
|
44
44
|
def init
|
45
|
-
Command.
|
45
|
+
Command.init_all
|
46
46
|
end
|
47
47
|
|
48
48
|
desc "run [--auto]", "Scan assets, specify scanned assets in pubspec.yaml, generate \"r.g.dart\""
|
@@ -62,10 +62,18 @@ More details see https://github.com/Fly-Mix/flr-cli
|
|
62
62
|
LONGDESC
|
63
63
|
option :auto, :type => :boolean
|
64
64
|
def run_command
|
65
|
-
options[:auto] ? Command.start_monitor : Command.
|
65
|
+
options[:auto] ? Command.start_monitor : Command.generate_all
|
66
66
|
end
|
67
|
-
|
68
67
|
map 'run' => :run_command
|
69
68
|
|
69
|
+
desc "recommend", "Display the recommended flutter resource structure"
|
70
|
+
long_desc <<-LONGDESC
|
71
|
+
Display the good flutter resource structure which is recommended by Flr.
|
72
|
+
|
73
|
+
LONGDESC
|
74
|
+
def recommend
|
75
|
+
Command.display_recommended_flutter_resource_structure
|
76
|
+
end
|
77
|
+
|
70
78
|
end
|
71
79
|
end
|
data/lib/flr/checker.rb
CHANGED
@@ -4,7 +4,7 @@ module Flr
|
|
4
4
|
# 条件检测器,提供检测各种条件是否合法的方法
|
5
5
|
class Checker
|
6
6
|
|
7
|
-
# check_pubspec_file_is_existed(
|
7
|
+
# check_pubspec_file_is_existed(flutter_project_dir) -> true
|
8
8
|
#
|
9
9
|
# 检测当前flutter工程目录是否存在pubspec.yaml文件
|
10
10
|
# 若存在,返回true
|
@@ -12,16 +12,16 @@ module Flr
|
|
12
12
|
#
|
13
13
|
# === Examples
|
14
14
|
#
|
15
|
-
#
|
16
|
-
# Checker.check_pubspec_file_is_existed(
|
15
|
+
# flutter_project_dir = "~path/to/flutter_r_demo"
|
16
|
+
# Checker.check_pubspec_file_is_existed(flutter_project_dir)
|
17
17
|
#
|
18
|
-
def self.check_pubspec_file_is_existed(
|
19
|
-
pubspec_file_path =
|
18
|
+
def self.check_pubspec_file_is_existed(flutter_project_dir)
|
19
|
+
pubspec_file_path = flutter_project_dir + "/pubspec.yaml"
|
20
20
|
|
21
21
|
if File.exist?(pubspec_file_path) == false
|
22
22
|
message = <<-MESSAGE
|
23
23
|
#{"[x]: #{pubspec_file_path} not found".error_style}
|
24
|
-
#{"[*]: please make sure pubspec.yaml is existed in #{
|
24
|
+
#{"[*]: please make sure pubspec.yaml is existed in #{flutter_project_dir}".tips_style}
|
25
25
|
MESSAGE
|
26
26
|
|
27
27
|
raise(message)
|
@@ -63,7 +63,7 @@ module Flr
|
|
63
63
|
return true
|
64
64
|
end
|
65
65
|
|
66
|
-
# check_flr_assets_is_legal(flr_config) -> resource_dir_result_tuple
|
66
|
+
# check_flr_assets_is_legal(flutter_project_dir, flr_config) -> resource_dir_result_tuple
|
67
67
|
#
|
68
68
|
# 检测当前flr配置信息中的assets配置是否合法
|
69
69
|
# 若合法,返回资源目录结果三元组 resource_dir_result_triplet
|
@@ -88,11 +88,12 @@ module Flr
|
|
88
88
|
# 判断flr的assets配置合法的标准是:assets配置的resource_dir数组中的legal_resource_dir数量大于0。
|
89
89
|
#
|
90
90
|
# === Examples
|
91
|
-
#
|
92
|
-
#
|
93
|
-
#
|
91
|
+
# flutter_project_dir = "~/path/to/flutter_r_demo"
|
92
|
+
# assets_legal_resource_dir_array = ["~/path/to/flutter_r_demo/lib/assets/images", "~/path/to/flutter_r_demo/lib/assets/texts"]
|
93
|
+
# fonts_legal_resource_dir_array = ["~/path/to/flutter_r_demo/lib/assets/fonts"]
|
94
|
+
# illegal_resource_dir_array = ["~/path/to/flutter_r_demo/to/non-existed_folder"]
|
94
95
|
#
|
95
|
-
def self.check_flr_assets_is_legal(flr_config)
|
96
|
+
def self.check_flr_assets_is_legal(flutter_project_dir, flr_config)
|
96
97
|
core_version = flr_config["core_version"]
|
97
98
|
dartfmt_line_length = flr_config["dartfmt_line_length"]
|
98
99
|
assets_resource_dir_array = flr_config["assets"]
|
@@ -119,7 +120,8 @@ module Flr
|
|
119
120
|
fonts_legal_resource_dir_array = []
|
120
121
|
illegal_resource_dir_array = []
|
121
122
|
|
122
|
-
assets_resource_dir_array.each do |
|
123
|
+
assets_resource_dir_array.each do |relative_resource_dir|
|
124
|
+
resource_dir = flutter_project_dir + "/" + relative_resource_dir
|
123
125
|
if File.exist?(resource_dir) == true
|
124
126
|
assets_legal_resource_dir_array.push(resource_dir)
|
125
127
|
else
|
@@ -127,7 +129,8 @@ module Flr
|
|
127
129
|
end
|
128
130
|
end
|
129
131
|
|
130
|
-
fonts_resource_dir_array.each do |
|
132
|
+
fonts_resource_dir_array.each do |relative_resource_dir|
|
133
|
+
resource_dir = flutter_project_dir + "/" + relative_resource_dir
|
131
134
|
if File.exist?(resource_dir) == true
|
132
135
|
fonts_legal_resource_dir_array.push(resource_dir)
|
133
136
|
else
|
data/lib/flr/command.rb
CHANGED
@@ -27,12 +27,118 @@ module Flr
|
|
27
27
|
# Listen Class Instance
|
28
28
|
@@listener = nil
|
29
29
|
|
30
|
-
#
|
30
|
+
# display the version of flr
|
31
31
|
def self.version
|
32
32
|
version_desc = "Flr version #{Flr::VERSION}\nCoreLogic version #{Flr::CORE_VERSION}"
|
33
33
|
puts(version_desc)
|
34
34
|
end
|
35
35
|
|
36
|
+
# display recommended flutter resource structure
|
37
|
+
def self.display_recommended_flutter_resource_structure
|
38
|
+
message = <<-MESSAGE
|
39
|
+
Flr recommends the following flutter resource structure schemes:
|
40
|
+
|
41
|
+
#{"------------------------------ scheme 1 ------------------------------".bold.bg_red}
|
42
|
+
|
43
|
+
flutter_project_root_dir
|
44
|
+
├── build
|
45
|
+
│ ├── ..
|
46
|
+
├── lib
|
47
|
+
│ ├── assets
|
48
|
+
│ │ ├── images #{"// image resource directory of all modules".red}
|
49
|
+
│ │ │ ├── \#{module} #{"// image resource directory of a module".red}
|
50
|
+
│ │ │ │ ├── \#{main_image_asset}
|
51
|
+
│ │ │ │ ├── \#{variant-dir} #{"// image resource directory of a variant".red}
|
52
|
+
│ │ │ │ │ ├── \#{image_asset_variant}
|
53
|
+
│ │ │ │
|
54
|
+
│ │ │ ├── home #{"// image resource directory of home module".red}
|
55
|
+
│ │ │ │ ├── home_badge.svg
|
56
|
+
│ │ │ │ ├── home_icon.png
|
57
|
+
│ │ │ │ ├── 3.0x #{"// image resource directory of a 3.0x-ratio-variant".red}
|
58
|
+
│ │ │ │ │ ├── home_icon.png
|
59
|
+
│ │ │ │
|
60
|
+
│ │ ├── texts #{"// text resource directory".red}
|
61
|
+
│ │ │ │ #{"// (you can also break it down further by module)".red}
|
62
|
+
│ │ │ └── test.json
|
63
|
+
│ │ │ └── test.yaml
|
64
|
+
│ │ │ │
|
65
|
+
│ │ ├── fonts #{"// font resource directory of all font-families".red}
|
66
|
+
│ │ │ ├── \#{font-family} #{"// font resource directory of a font-family".red}
|
67
|
+
│ │ │ │ ├── \#{font-family}-\#{font_weight_or_style}.ttf
|
68
|
+
│ │ │ │
|
69
|
+
│ │ │ ├── Amiri #{"// font resource directory of Amiri font-family".red}
|
70
|
+
│ │ │ │ ├── Amiri-Regular.ttf
|
71
|
+
│ │ │ │ ├── Amiri-Bold.ttf
|
72
|
+
│ │ │ │ ├── Amiri-Italic.ttf
|
73
|
+
│ │ │ │ ├── Amiri-BoldItalic.ttf
|
74
|
+
│ ├── ..
|
75
|
+
|
76
|
+
#{"[*]: Then config the resource directories that need to be scanned as follows:".tips_style}
|
77
|
+
|
78
|
+
#{"flr:".tips_style}
|
79
|
+
#{"core_version: #{Flr::CORE_VERSION}".tips_style}
|
80
|
+
#{"dartfmt_line_length: #{Flr::DARTFMT_LINE_LENGTH}".tips_style}
|
81
|
+
#{"# config the image and text resource directories that need to be scanned".tips_style}
|
82
|
+
#{"assets:".tips_style}
|
83
|
+
#{"- lib/assets/images".tips_style}
|
84
|
+
#{"- lib/assets/texts".tips_style}
|
85
|
+
#{"# config the font resource directories that need to be scanned".tips_style}
|
86
|
+
#{"fonts:".tips_style}
|
87
|
+
#{"- lib/assets/fonts".tips_style}
|
88
|
+
|
89
|
+
#{"------------------------------ scheme 2 ------------------------------".bold.bg_red}
|
90
|
+
|
91
|
+
flutter_project_root_dir
|
92
|
+
├── build
|
93
|
+
│ ├── ..
|
94
|
+
├── lib
|
95
|
+
│ ├── ..
|
96
|
+
├── assets
|
97
|
+
│ ├── images #{"// image resource directory of all modules".red}
|
98
|
+
│ │ ├── \#{module} #{"// image resource directory of a module".red}
|
99
|
+
│ │ │ ├── \#{main_image_asset}
|
100
|
+
│ │ │ ├── \#{variant-dir} #{"// image resource directory of a variant".red}
|
101
|
+
│ │ │ │ ├── \#{image_asset_variant}
|
102
|
+
│ │ │
|
103
|
+
│ │ ├── home #{"// image resource directory of home module".red}
|
104
|
+
│ │ │ ├── home_badge.svg
|
105
|
+
│ │ │ ├── home_icon.png
|
106
|
+
│ │ │ ├── 3.0x #{"// image resource directory of a 3.0x-ratio-variant".red}
|
107
|
+
│ │ │ │ ├── home_icon.png
|
108
|
+
│ │ │
|
109
|
+
│ ├── texts #{"// text resource directory".red}
|
110
|
+
│ │ │ #{"// (you can also break it down further by module)".red}
|
111
|
+
│ │ └── test.json
|
112
|
+
│ │ └── test.yaml
|
113
|
+
│ │ │
|
114
|
+
│ ├── fonts #{"// font resource directory of all font-families".red}
|
115
|
+
│ │ ├── \#{font-family} #{"// font resource directory of a font-family".red}
|
116
|
+
│ │ │ ├── \#{font-family}-\#{font_weight_or_style}.ttf
|
117
|
+
│ │ │
|
118
|
+
│ │ ├── Amiri #{"// font resource directory of Amiri font-family".red}
|
119
|
+
│ │ │ ├── Amiri-Regular.ttf
|
120
|
+
│ │ │ ├── Amiri-Bold.ttf
|
121
|
+
│ │ │ ├── Amiri-Italic.ttf
|
122
|
+
│ │ │ ├── Amiri-BoldItalic.ttf
|
123
|
+
│ ├── ..
|
124
|
+
|
125
|
+
#{"[*]: Then config the resource directories that need to be scanned as follows:".tips_style}
|
126
|
+
|
127
|
+
#{"flr:".tips_style}
|
128
|
+
#{"core_version: #{Flr::CORE_VERSION}".tips_style}
|
129
|
+
#{"dartfmt_line_length: #{Flr::DARTFMT_LINE_LENGTH}".tips_style}
|
130
|
+
#{"# config the image and text resource directories that need to be scanned".tips_style}
|
131
|
+
#{"assets:".tips_style}
|
132
|
+
#{"- assets/images".tips_style}
|
133
|
+
#{"- assets/texts".tips_style}
|
134
|
+
#{"# config the font resource directories that need to be scanned".tips_style}
|
135
|
+
#{"fonts:".tips_style}
|
136
|
+
#{"- assets/fonts".tips_style}
|
137
|
+
MESSAGE
|
138
|
+
|
139
|
+
puts(message)
|
140
|
+
end
|
141
|
+
|
36
142
|
# get the right version of r_dart_library package based on flutter's version
|
37
143
|
# to get more detail, see https://github.com/YK-Unit/r_dart_library#dependency-relationship-table
|
38
144
|
def self.get_r_dart_library_version
|
@@ -48,48 +154,115 @@ module Flr
|
|
48
154
|
return r_dart_library_version
|
49
155
|
end
|
50
156
|
|
51
|
-
|
52
|
-
|
157
|
+
flutter_version_with_hotfix_str = flutter_version_result.split(" ")[1]
|
158
|
+
flutter_version_without_hotfix_str = flutter_version_with_hotfix_str.split("+")[0]
|
159
|
+
|
160
|
+
dart_version_str = flutter_version_result.split("Dart")[1]
|
161
|
+
dart_version_str.strip!
|
53
162
|
|
54
|
-
|
163
|
+
puts("the flutter development environment is:")
|
164
|
+
puts(" - Flutter SDK Version: #{flutter_version_with_hotfix_str}")
|
165
|
+
puts(" - Dart SDK Version: #{dart_version_str}")
|
166
|
+
|
167
|
+
if Version.new(flutter_version_with_hotfix_str) >= Version.new("1.10.15")
|
55
168
|
r_dart_library_version = "0.2.1"
|
169
|
+
if Version.new(dart_version_str) >= Version.new("2.12.0")
|
170
|
+
r_dart_library_version = "0.4.0-nullsafety.0"
|
171
|
+
end
|
56
172
|
end
|
57
173
|
|
58
174
|
return r_dart_library_version
|
59
175
|
end
|
60
176
|
|
61
|
-
|
62
|
-
|
63
|
-
flutter_project_root_dir = FileUtil.get_cur_flutter_project_root_dir
|
177
|
+
def self.init_all
|
178
|
+
flutter_main_project_root_dir = FileUtil.get_flutter_main_project_root_dir
|
64
179
|
|
65
180
|
# ----- Step-1 Begin -----
|
66
|
-
#
|
67
|
-
# - 检测当前
|
181
|
+
# 进行环境检测;若发现不合法的环境,则抛出异常,终止当前进程
|
182
|
+
# - 检测当前flutter主工程根目录是否存在 pubspec.yaml
|
68
183
|
#
|
69
184
|
|
70
185
|
begin
|
71
|
-
Checker.check_pubspec_file_is_existed(
|
186
|
+
Checker.check_pubspec_file_is_existed(flutter_main_project_root_dir)
|
187
|
+
rescue Exception => e
|
188
|
+
puts(e.message)
|
189
|
+
return
|
190
|
+
end
|
72
191
|
|
73
|
-
|
192
|
+
# ----- Step-1 End -----
|
74
193
|
|
75
|
-
|
194
|
+
puts("init all flutter projects now...")
|
195
|
+
|
196
|
+
# ----- Step-2 Begin -----
|
197
|
+
# 获取主工程和其所有子工程,对它们进行init_one操作
|
198
|
+
# - 获取flutter主工程根目录下所有的子工程目录
|
199
|
+
# - 初始化主工程
|
200
|
+
# - 初始化所有子工程
|
201
|
+
#
|
202
|
+
flutter_sub_project_root_dir_array = FileUtil.get_flutter_sub_project_root_dirs(flutter_main_project_root_dir)
|
203
|
+
|
204
|
+
puts("")
|
205
|
+
init_one(flutter_main_project_root_dir)
|
206
|
+
|
207
|
+
flutter_sub_project_root_dir_array.each do |flutter_project_root_dir|
|
208
|
+
puts("")
|
209
|
+
init_one(flutter_project_root_dir)
|
210
|
+
end
|
211
|
+
|
212
|
+
# ----- Step-2 End -----
|
213
|
+
|
214
|
+
# ----- Step-3 Begin -----
|
215
|
+
# 调用 flutter 工具,为主工程和所有子工程获取依赖
|
216
|
+
#
|
217
|
+
puts("")
|
218
|
+
puts("get dependencies for all flutter projects via execute \"flutter pub get\" now ...")
|
76
219
|
|
220
|
+
get_flutter_pub_cmd = "flutter pub get"
|
221
|
+
system(get_flutter_pub_cmd)
|
222
|
+
|
223
|
+
puts("[√]: get dependencies for all flutter projects done !!!")
|
224
|
+
|
225
|
+
# ----- Step-3 End -----
|
226
|
+
puts("")
|
227
|
+
puts("[√]: init all flutter projects done !!!")
|
228
|
+
|
229
|
+
puts("")
|
230
|
+
puts("[*]: if you want to know how to make a good resource structure for your flutter project, please run \"flr recommend\" ".tips_style)
|
231
|
+
end
|
232
|
+
|
233
|
+
# 对指定 flutter 工程进行初始化
|
234
|
+
def self.init_one(flutter_project_root_dir)
|
235
|
+
puts("------------------------------- init specified project -------------------------------")
|
236
|
+
|
237
|
+
puts("init #{flutter_project_root_dir} now...")
|
238
|
+
|
239
|
+
# ----- Step-1 Begin -----
|
240
|
+
# 进行环境检测;若发现不合法的环境,则抛出异常,终止当前进程
|
241
|
+
# - 检测 pubspec.yaml 是否存在
|
242
|
+
# - 检测 pubspec.yaml 是否合法
|
243
|
+
#
|
244
|
+
begin
|
245
|
+
Checker.check_pubspec_file_is_existed(flutter_project_root_dir)
|
246
|
+
pubspec_file_path = FileUtil.get_pubspec_file_path(flutter_project_root_dir)
|
247
|
+
pubspec_config = FileUtil.load_pubspec_config_from_file(pubspec_file_path)
|
77
248
|
rescue Exception => e
|
78
249
|
puts(e.message)
|
250
|
+
puts("[x]: init #{flutter_project_root_dir} failed".error_style)
|
251
|
+
puts("--------------------------------------------------------------------------------------")
|
79
252
|
return
|
80
253
|
end
|
81
254
|
|
82
255
|
# ----- Step-1 End -----
|
83
256
|
|
84
|
-
puts("init #{flutter_project_root_dir} now...")
|
85
|
-
|
86
257
|
# ----- Step-2 Begin -----
|
87
258
|
# 添加 flr_config 和 r_dart_library 的依赖声明到 pubspec.yaml
|
88
259
|
#
|
89
260
|
|
90
261
|
dependencies_config = pubspec_config["dependencies"]
|
91
262
|
|
92
|
-
# 添加
|
263
|
+
# 添加flr_config到pubspec.yaml:检测当前是否存在flr_config;若不存在,则添加flr_config;若存在,则按照以下步骤处理:
|
264
|
+
# - 读取dartfmt_line_length选项、assets选项和fonts选项的值(这些选项值若存在,则应用于新建的flr_config;需要注意,使用前需要判断选项值是否合法:dartfmt_line_length选项值 >=80;assets选项和fonts选项的值为数组)
|
265
|
+
# - 新建flr_config,然后使用旧值或者默认值设置各个选项
|
93
266
|
#
|
94
267
|
# flr_config: Flr的配置信息
|
95
268
|
# ```yaml
|
@@ -99,7 +272,33 @@ module Flr
|
|
99
272
|
# assets: []
|
100
273
|
# fonts: []
|
101
274
|
# ```
|
102
|
-
|
275
|
+
|
276
|
+
dartfmt_line_length = Flr::DARTFMT_LINE_LENGTH
|
277
|
+
asset_resource_dir_array = []
|
278
|
+
font_resource_dir_array = []
|
279
|
+
|
280
|
+
old_flr_config = pubspec_config["flr"]
|
281
|
+
if old_flr_config.is_a?(Hash)
|
282
|
+
dartfmt_line_length = old_flr_config["dartfmt_line_length"]
|
283
|
+
if dartfmt_line_length.nil? or dartfmt_line_length.is_a?(Integer) == false
|
284
|
+
dartfmt_line_length = Flr::DARTFMT_LINE_LENGTH
|
285
|
+
end
|
286
|
+
if dartfmt_line_length < Flr::DARTFMT_LINE_LENGTH
|
287
|
+
dartfmt_line_length = Flr::DARTFMT_LINE_LENGTH
|
288
|
+
end
|
289
|
+
|
290
|
+
asset_resource_dir_array = old_flr_config["assets"]
|
291
|
+
if asset_resource_dir_array.nil? or asset_resource_dir_array.is_a?(Array) == false
|
292
|
+
asset_resource_dir_array = []
|
293
|
+
end
|
294
|
+
|
295
|
+
font_resource_dir_array = old_flr_config["fonts"]
|
296
|
+
if font_resource_dir_array.nil? or font_resource_dir_array.is_a?(Array) == false
|
297
|
+
font_resource_dir_array = []
|
298
|
+
end
|
299
|
+
end
|
300
|
+
|
301
|
+
flr_config = Hash["core_version" => "#{Flr::CORE_VERSION}", "dartfmt_line_length" => dartfmt_line_length, "assets" => asset_resource_dir_array, "fonts" => font_resource_dir_array]
|
103
302
|
pubspec_config["flr"] = flr_config
|
104
303
|
|
105
304
|
# 添加 r_dart_library(https://github.com/YK-Unit/r_dart_library)的依赖声明
|
@@ -108,14 +307,10 @@ module Flr
|
|
108
307
|
#
|
109
308
|
# r_dart_library的依赖声明:
|
110
309
|
# ```yaml
|
111
|
-
# r_dart_library:
|
112
|
-
# git:
|
113
|
-
# url: "https://github.com/YK-Unit/r_dart_library.git"
|
114
|
-
# ref: 0.1.1
|
310
|
+
# r_dart_library: 0.1.1
|
115
311
|
# ```
|
116
312
|
r_dart_library_version = get_r_dart_library_version
|
117
|
-
|
118
|
-
dependencies_config["r_dart_library"] = r_dart_library_config
|
313
|
+
dependencies_config["r_dart_library"] = r_dart_library_version
|
119
314
|
pubspec_config["dependencies"] = dependencies_config
|
120
315
|
|
121
316
|
puts("add flr configuration into pubspec.yaml done!")
|
@@ -130,6 +325,9 @@ module Flr
|
|
130
325
|
#
|
131
326
|
|
132
327
|
flutter_config = pubspec_config["flutter"]
|
328
|
+
if flutter_config.nil?
|
329
|
+
flutter_config = {}
|
330
|
+
end
|
133
331
|
|
134
332
|
flutter_assets = flutter_config["assets"]
|
135
333
|
should_rm_flutter_assets_Key = true
|
@@ -156,25 +354,67 @@ module Flr
|
|
156
354
|
# 保存 pubspec.yaml
|
157
355
|
FileUtil.dump_pubspec_config_to_file(pubspec_config, pubspec_file_path)
|
158
356
|
|
159
|
-
puts("
|
357
|
+
puts("[√]: init #{flutter_project_root_dir} done !!!")
|
358
|
+
puts("--------------------------------------------------------------------------------------")
|
160
359
|
|
161
|
-
|
162
|
-
|
360
|
+
end
|
361
|
+
|
362
|
+
def self.generate_all
|
363
|
+
flutter_main_project_root_dir = FileUtil.get_flutter_main_project_root_dir
|
364
|
+
|
365
|
+
# ----- Step-1 Begin -----
|
366
|
+
# 进行环境检测;若发现不合法的环境,则抛出异常,终止当前进程。
|
367
|
+
# - 检测当前flutter主工程根目录是否存在 pubspec.yaml
|
368
|
+
#
|
369
|
+
begin
|
370
|
+
Checker.check_pubspec_file_is_existed(flutter_main_project_root_dir)
|
371
|
+
rescue Exception => e
|
372
|
+
puts(e.message)
|
373
|
+
return
|
374
|
+
end
|
375
|
+
|
376
|
+
# ----- Step-1 End -----
|
377
|
+
|
378
|
+
puts("generate for all flutter projects now...")
|
379
|
+
|
380
|
+
# ----- Step-2 Begin -----
|
381
|
+
# 获取主工程和其所有子工程,对它们进行generate_one操作
|
382
|
+
# - 获取flutter主工程根目录下所有的子工程目录
|
383
|
+
# - 对主工程执行generate_one操作
|
384
|
+
# - 对所有子工程执行generate_one操作
|
385
|
+
#
|
386
|
+
flutter_sub_project_root_dir_array = FileUtil.get_flutter_sub_project_root_dirs(flutter_main_project_root_dir)
|
387
|
+
|
388
|
+
puts("")
|
389
|
+
generate_one(flutter_main_project_root_dir)
|
390
|
+
|
391
|
+
flutter_sub_project_root_dir_array.each do |flutter_project_root_dir|
|
392
|
+
puts("")
|
393
|
+
generate_one(flutter_project_root_dir)
|
394
|
+
end
|
395
|
+
|
396
|
+
# ----- Step-2 End -----
|
397
|
+
|
398
|
+
# ----- Step-3 Begin -----
|
399
|
+
# 调用 flutter 工具,为主工程和所有子工程获取依赖
|
400
|
+
#
|
401
|
+
puts("")
|
402
|
+
puts("get dependencies for all flutter projects via execute \"flutter pub get\" now ...")
|
163
403
|
|
164
404
|
get_flutter_pub_cmd = "flutter pub get"
|
165
405
|
system(get_flutter_pub_cmd)
|
166
406
|
|
167
|
-
puts("get
|
168
|
-
|
169
|
-
# ----- Step-4 End -----
|
407
|
+
puts("[√]: get dependencies for all flutter projects done !!!")
|
170
408
|
|
171
|
-
|
409
|
+
# ----- Step-3 End -----
|
410
|
+
puts("")
|
411
|
+
puts("[√]: generate for all flutter projects done !!!")
|
172
412
|
end
|
173
413
|
|
174
|
-
#
|
175
|
-
def self.
|
176
|
-
|
177
|
-
flutter_project_root_dir
|
414
|
+
# 为指定 flutter 工程扫描资源目录,自动为资源添加声明到 pubspec.yaml 和生成 r.g.dart
|
415
|
+
def self.generate_one(flutter_project_root_dir)
|
416
|
+
puts("--------------------------- generate for specified project ---------------------------")
|
417
|
+
puts("generate for #{flutter_project_root_dir} now...")
|
178
418
|
|
179
419
|
# 警告日志数组
|
180
420
|
warning_messages = []
|
@@ -190,7 +430,7 @@ module Flr
|
|
190
430
|
begin
|
191
431
|
Checker.check_pubspec_file_is_existed(flutter_project_root_dir)
|
192
432
|
|
193
|
-
pubspec_file_path = FileUtil.get_pubspec_file_path
|
433
|
+
pubspec_file_path = FileUtil.get_pubspec_file_path(flutter_project_root_dir)
|
194
434
|
|
195
435
|
pubspec_config = FileUtil.load_pubspec_config_from_file(pubspec_file_path)
|
196
436
|
|
@@ -198,20 +438,26 @@ module Flr
|
|
198
438
|
|
199
439
|
flr_config = pubspec_config["flr"]
|
200
440
|
|
201
|
-
resource_dir_result_tuple = Checker.check_flr_assets_is_legal(flr_config)
|
441
|
+
resource_dir_result_tuple = Checker.check_flr_assets_is_legal(flutter_project_root_dir, flr_config)
|
202
442
|
|
203
443
|
rescue Exception => e
|
204
444
|
puts(e.message)
|
445
|
+
puts("[x]: generate for #{flutter_project_root_dir} failed".error_style)
|
446
|
+
puts("--------------------------------------------------------------------------------------")
|
205
447
|
return
|
206
448
|
end
|
207
449
|
|
450
|
+
is_package_project_type = FileUtil.is_package_project_type?(flutter_project_root_dir)
|
208
451
|
package_name = pubspec_config["name"]
|
209
452
|
|
210
453
|
# ----- Step-1 End -----
|
211
454
|
|
212
455
|
# ----- Step-2 Begin -----
|
213
456
|
# 进行核心逻辑版本检测:
|
214
|
-
# 检测
|
457
|
+
# 检测flr_config中的core_version和当前工具的core_version是否一致;若不一致,则按照以下规则处理:
|
458
|
+
# - 更新flr_config中的core_version的值为当前工具的core_version;
|
459
|
+
# - 生成“核心逻辑版本不一致”的警告日志,存放到警告日志数组。
|
460
|
+
#
|
215
461
|
|
216
462
|
flr_core_version = flr_config["core_version"]
|
217
463
|
|
@@ -220,9 +466,13 @@ module Flr
|
|
220
466
|
end
|
221
467
|
|
222
468
|
if flr_core_version != Flr::CORE_VERSION
|
469
|
+
flr_config["core_version"] = Flr::CORE_VERSION
|
470
|
+
|
223
471
|
message = <<-MESSAGE
|
224
|
-
#{"[!]: warning,
|
225
|
-
#{"[*]: to fix it, you
|
472
|
+
#{"[!]: warning, some team members may be using Flr tool with core_version #{flr_core_version}, while you are using Flr tool with core_version #{Flr::CORE_VERSION}".warning_style}
|
473
|
+
#{"[*]: to fix it, you and your team members should use the Flr tool with same core_version".tips_style}
|
474
|
+
#{"[*]: \"core_version\" is the core logic version of Flr tool, you can run \"flr version\" to get it".tips_style}
|
475
|
+
|
226
476
|
MESSAGE
|
227
477
|
|
228
478
|
warning_messages.push(message)
|
@@ -257,16 +507,18 @@ module Flr
|
|
257
507
|
puts("scan assets now ...")
|
258
508
|
|
259
509
|
# ----- Step-4 Begin -----
|
260
|
-
# 扫描assets_legal_resource_dir数组中的legal_resource_dir
|
510
|
+
# 扫描assets_legal_resource_dir数组中的legal_resource_dir,输出有序的image_asset数组、non_svg_image_asset数组、svg_image_asset数组、illegal_image_file数组:
|
261
511
|
# - 创建image_asset数组、illegal_image_file数组;
|
262
512
|
# - 遍历assets_legal_resource_dir数组,按照如下处理每个资源目录:
|
263
|
-
# -
|
513
|
+
# - 扫描当前资源目录和其所有层级的子目录,查找所有image_file;
|
264
514
|
# - 根据legal_resource_file的标准,筛选查找结果生成legal_image_file子数组和illegal_image_file子数组;illegal_image_file子数组合并到illegal_image_file数组;
|
265
515
|
# - 根据image_asset的定义,遍历legal_image_file子数组,生成image_asset子数;组;image_asset子数组合并到image_asset数组。
|
266
516
|
# - 对image_asset数组做去重处理;
|
267
517
|
# - 按照字典顺序对image_asset数组做升序排列(一般使用开发语言提供的默认的sort算法即可);
|
268
|
-
# -
|
269
|
-
#
|
518
|
+
# - 按照SVG分类,从image_asset数组筛选得到有序的non_svg_image_asset数组和svg_image_asset数组:
|
519
|
+
# - 按照SVG分类,从image_asset数组筛选得到non_svg_image_asset数组和svg_image_asset数组;
|
520
|
+
# - 按照字典顺序对non_svg_image_asset数组和svg_image_asset数组做升序排列(一般使用开发语言提供的默认的sort算法即可);
|
521
|
+
# - 输出有序的image_asset数组、non_svg_image_asset数组、svg_image_asset数组、illegal_image_file数组。
|
270
522
|
|
271
523
|
image_asset_array = []
|
272
524
|
illegal_image_file_array = []
|
@@ -278,13 +530,28 @@ module Flr
|
|
278
530
|
|
279
531
|
illegal_image_file_array += illegal_image_file_subarray
|
280
532
|
|
281
|
-
image_asset_subarray = AssetUtil.generate_image_assets(
|
533
|
+
image_asset_subarray = AssetUtil.generate_image_assets(flutter_project_root_dir, package_name, legal_image_file_subarray)
|
282
534
|
image_asset_array += image_asset_subarray
|
283
535
|
end
|
284
536
|
|
285
537
|
image_asset_array.uniq!
|
286
538
|
image_asset_array.sort!
|
287
539
|
|
540
|
+
non_svg_image_asset_array = []
|
541
|
+
svg_image_asset_array = []
|
542
|
+
|
543
|
+
image_asset_array.each do |image_asset|
|
544
|
+
if FileUtil.is_svg_image_resource_file?(image_asset)
|
545
|
+
svg_image_asset_array.push(image_asset)
|
546
|
+
else
|
547
|
+
non_svg_image_asset_array.push(image_asset)
|
548
|
+
end
|
549
|
+
|
550
|
+
end
|
551
|
+
|
552
|
+
non_svg_image_asset_array.sort!
|
553
|
+
svg_image_asset_array.sort!
|
554
|
+
|
288
555
|
# ----- Step-4 End -----
|
289
556
|
|
290
557
|
# ----- Step-5 Begin -----
|
@@ -309,7 +576,7 @@ module Flr
|
|
309
576
|
|
310
577
|
illegal_text_file_array += illegal_text_file_subarray
|
311
578
|
|
312
|
-
text_asset_subarray = AssetUtil.generate_text_assets(
|
579
|
+
text_asset_subarray = AssetUtil.generate_text_assets(flutter_project_root_dir, package_name, legal_text_file_subarray)
|
313
580
|
text_asset_array += text_asset_subarray
|
314
581
|
end
|
315
582
|
|
@@ -353,7 +620,7 @@ module Flr
|
|
353
620
|
next
|
354
621
|
end
|
355
622
|
|
356
|
-
font_asset_config_array = AssetUtil.generate_font_asset_configs(
|
623
|
+
font_asset_config_array = AssetUtil.generate_font_asset_configs(flutter_project_root_dir, package_name, legal_font_file_array)
|
357
624
|
font_asset_config_array.sort!{|a, b| a["asset"] <=> b["asset"]}
|
358
625
|
|
359
626
|
font_family_config = Hash["family" => font_family_name , "fonts" => font_asset_config_array]
|
@@ -389,23 +656,36 @@ module Flr
|
|
389
656
|
|
390
657
|
# ----- Step-8 Begin -----
|
391
658
|
# 为扫描得到的legal_resource_file添加资源声明到pubspec.yaml:
|
392
|
-
# - 合并image_asset数组和text_asset数组为
|
659
|
+
# - 合并image_asset数组和text_asset数组为new_asset_array(image_asset数组元素在前);
|
660
|
+
# - 读取pubspec.yaml中flutter-assets配置,获得old_asset_array,然后和new_asset_array合并为asset数组;
|
393
661
|
# - 修改pubspec.yaml中flutter-assets配置的值为asset数组;
|
394
662
|
# - 修改pubspec.yaml中flutter-fonts配置的值为font_family_config数组。
|
395
663
|
|
396
|
-
|
664
|
+
flutter_config = pubspec_config["flutter"]
|
665
|
+
if flutter_config.nil?
|
666
|
+
flutter_config = {}
|
667
|
+
end
|
668
|
+
|
669
|
+
new_asset_array = image_asset_array + text_asset_array
|
670
|
+
old_asset_array = flutter_config["assets"]
|
671
|
+
if old_asset_array.nil? or old_asset_array.is_a?(Array) == false
|
672
|
+
old_asset_array = []
|
673
|
+
end
|
674
|
+
|
675
|
+
asset_array = AssetUtil.mergeFlutterAssets(flutter_project_root_dir, package_name, new_asset_array, old_asset_array)
|
397
676
|
if asset_array.length > 0
|
398
|
-
|
677
|
+
flutter_config["assets"] = asset_array
|
399
678
|
else
|
400
|
-
|
679
|
+
flutter_config.delete("assets")
|
401
680
|
end
|
402
681
|
|
403
682
|
if font_family_config_array.length > 0
|
404
|
-
|
683
|
+
flutter_config["fonts"] = font_family_config_array
|
405
684
|
else
|
406
|
-
|
685
|
+
flutter_config.delete("fonts")
|
407
686
|
end
|
408
687
|
|
688
|
+
pubspec_config["flutter"] = flutter_config
|
409
689
|
FileUtil.dump_pubspec_config_to_file(pubspec_config, pubspec_file_path)
|
410
690
|
|
411
691
|
# ----- Step-8 End -----
|
@@ -413,26 +693,31 @@ module Flr
|
|
413
693
|
puts("specify scanned assets in pubspec.yaml done !!!")
|
414
694
|
|
415
695
|
# ----- Step-9 Begin -----
|
416
|
-
#
|
417
|
-
#
|
418
|
-
#
|
696
|
+
# 分别遍历non_svg_image_asset数组、svg_image_asset数组、text_asset数组,
|
697
|
+
# 根据asset_id生成算法,分别输出non_svg_image_asset_id字典、svg_image_asset_id 字典、text_asset_id字典。
|
698
|
+
# 字典的key为asset,value为asset_id。
|
419
699
|
#
|
700
|
+
non_svg_image_asset_id_dict = Hash[]
|
701
|
+
svg_image_asset_id_dict = Hash[]
|
702
|
+
text_asset_id_dict = Hash[]
|
703
|
+
|
704
|
+
non_svg_image_asset_array.each do |asset|
|
705
|
+
used_asset_id_array = non_svg_image_asset_id_dict.values
|
706
|
+
asset_id = CodeUtil.generate_asset_id(asset, used_asset_id_array, Flr::PRIOR_NON_SVG_IMAGE_FILE_TYPE)
|
707
|
+
non_svg_image_asset_id_dict[asset] = asset_id
|
708
|
+
end
|
420
709
|
|
421
|
-
|
422
|
-
|
423
|
-
|
424
|
-
|
425
|
-
file_extname = File.extname(image_asset).downcase
|
426
|
-
|
427
|
-
if file_extname.eql?(".svg")
|
428
|
-
svg_image_asset_array.push(image_asset)
|
429
|
-
else
|
430
|
-
non_svg_image_asset_array.push(image_asset)
|
431
|
-
end
|
710
|
+
svg_image_asset_array.each do |asset|
|
711
|
+
used_asset_id_array = svg_image_asset_id_dict.values
|
712
|
+
asset_id = CodeUtil.generate_asset_id(asset, used_asset_id_array, Flr::PRIOR_SVG_IMAGE_FILE_TYPE)
|
713
|
+
svg_image_asset_id_dict[asset] = asset_id
|
432
714
|
end
|
433
715
|
|
434
|
-
|
435
|
-
|
716
|
+
text_asset_array.each do |asset|
|
717
|
+
used_asset_id_array = text_asset_id_dict.values
|
718
|
+
asset_id = CodeUtil.generate_asset_id(asset, used_asset_id_array, Flr::PRIOR_TEXT_FILE_TYPE)
|
719
|
+
text_asset_id_dict[asset] = asset_id
|
720
|
+
end
|
436
721
|
|
437
722
|
# ----- Step-9 End -----
|
438
723
|
|
@@ -471,7 +756,7 @@ module Flr
|
|
471
756
|
#
|
472
757
|
|
473
758
|
r_dart_file.puts("\n")
|
474
|
-
g__R_Image_AssetResource_class_code = CodeUtil.generate__R_Image_AssetResource_class(non_svg_image_asset_array, package_name)
|
759
|
+
g__R_Image_AssetResource_class_code = CodeUtil.generate__R_Image_AssetResource_class(non_svg_image_asset_array, non_svg_image_asset_id_dict, package_name, is_package_project_type)
|
475
760
|
r_dart_file.puts(g__R_Image_AssetResource_class_code)
|
476
761
|
|
477
762
|
# ----- Step-13 End -----
|
@@ -481,7 +766,7 @@ module Flr
|
|
481
766
|
#
|
482
767
|
|
483
768
|
r_dart_file.puts("\n")
|
484
|
-
g__R_Svg_AssetResource_class_code = CodeUtil.generate__R_Svg_AssetResource_class(svg_image_asset_array, package_name)
|
769
|
+
g__R_Svg_AssetResource_class_code = CodeUtil.generate__R_Svg_AssetResource_class(svg_image_asset_array, svg_image_asset_id_dict, package_name, is_package_project_type)
|
485
770
|
r_dart_file.puts(g__R_Svg_AssetResource_class_code)
|
486
771
|
|
487
772
|
# ----- Step-14 End -----
|
@@ -491,7 +776,7 @@ module Flr
|
|
491
776
|
#
|
492
777
|
|
493
778
|
r_dart_file.puts("\n")
|
494
|
-
g__R_Text_AssetResource_class_code = CodeUtil.generate__R_Text_AssetResource_class(text_asset_array, package_name)
|
779
|
+
g__R_Text_AssetResource_class_code = CodeUtil.generate__R_Text_AssetResource_class(text_asset_array, text_asset_id_dict, package_name, is_package_project_type)
|
495
780
|
r_dart_file.puts(g__R_Text_AssetResource_class_code)
|
496
781
|
|
497
782
|
# ----- Step-15 End -----
|
@@ -502,7 +787,7 @@ module Flr
|
|
502
787
|
#
|
503
788
|
|
504
789
|
r_dart_file.puts("\n")
|
505
|
-
g__R_Image_class_code = CodeUtil.generate__R_Image_class(non_svg_image_asset_array, package_name)
|
790
|
+
g__R_Image_class_code = CodeUtil.generate__R_Image_class(non_svg_image_asset_array, non_svg_image_asset_id_dict, package_name)
|
506
791
|
r_dart_file.puts(g__R_Image_class_code)
|
507
792
|
|
508
793
|
# ----- Step-16 End -----
|
@@ -512,7 +797,7 @@ module Flr
|
|
512
797
|
#
|
513
798
|
|
514
799
|
r_dart_file.puts("\n")
|
515
|
-
g__R_Svg_class_code = CodeUtil.generate__R_Svg_class(svg_image_asset_array, package_name)
|
800
|
+
g__R_Svg_class_code = CodeUtil.generate__R_Svg_class(svg_image_asset_array, svg_image_asset_id_dict, package_name)
|
516
801
|
r_dart_file.puts(g__R_Svg_class_code)
|
517
802
|
|
518
803
|
# ----- Step-17 End -----
|
@@ -522,7 +807,7 @@ module Flr
|
|
522
807
|
#
|
523
808
|
|
524
809
|
r_dart_file.puts("\n")
|
525
|
-
g__R_Text_class_code = CodeUtil.generate__R_Text_class(text_asset_array, package_name)
|
810
|
+
g__R_Text_class_code = CodeUtil.generate__R_Text_class(text_asset_array, text_asset_id_dict, package_name)
|
526
811
|
r_dart_file.puts(g__R_Text_class_code)
|
527
812
|
|
528
813
|
# ----- Step-18 End -----
|
@@ -566,19 +851,6 @@ module Flr
|
|
566
851
|
# ----- Step-21 End -----
|
567
852
|
|
568
853
|
# ----- Step-22 Begin -----
|
569
|
-
# 调用flutter工具,为flutter工程获取依赖
|
570
|
-
#
|
571
|
-
|
572
|
-
get_flutter_pub_cmd = "flutter pub get"
|
573
|
-
puts("execute \"#{get_flutter_pub_cmd}\" now ...")
|
574
|
-
system(get_flutter_pub_cmd)
|
575
|
-
puts("execute \"#{get_flutter_pub_cmd}\" done !!!")
|
576
|
-
|
577
|
-
# ----- Step-22 End -----
|
578
|
-
|
579
|
-
puts("[√]: generate done !!!")
|
580
|
-
|
581
|
-
# ----- Step-23 Begin -----
|
582
854
|
# 判断警告日志数组是否为空,若不为空,输出所有警告日志
|
583
855
|
#
|
584
856
|
|
@@ -589,87 +861,125 @@ module Flr
|
|
589
861
|
end
|
590
862
|
end
|
591
863
|
|
592
|
-
# ----- Step-
|
864
|
+
# ----- Step-22 End -----
|
865
|
+
|
866
|
+
puts("[√]: generate for #{flutter_project_root_dir} done !!!")
|
867
|
+
puts("--------------------------------------------------------------------------------------")
|
593
868
|
|
594
869
|
end
|
595
870
|
|
596
|
-
#
|
871
|
+
# 启动一个资源变化监控服务,若检测到flutter主工程和其子工程有资源变化,就自动执行generate_all操作;
|
872
|
+
# 手动输入`Ctrl-C`,可终止当前服务
|
597
873
|
def self.start_monitor
|
598
874
|
|
599
|
-
|
875
|
+
flutter_main_project_root_dir = FileUtil.get_flutter_main_project_root_dir
|
600
876
|
|
601
877
|
# ----- Step-1 Begin -----
|
602
|
-
#
|
603
|
-
#
|
604
|
-
# - 检测当前pubspec.yaml中是否存在Flr的配置
|
605
|
-
# - 检测当前flr_config中的resource_dir配置是否合法:
|
606
|
-
# 判断合法的标准是:assets配置或者fonts配置了至少1个legal_resource_dir
|
878
|
+
# 对flutter主工程进行环境检测:
|
879
|
+
# - 检测当前flutter主工程根目录是否存在 pubspec.yaml
|
607
880
|
#
|
608
881
|
|
609
882
|
begin
|
610
|
-
Checker.check_pubspec_file_is_existed(
|
611
|
-
|
612
|
-
pubspec_file_path = FileUtil.get_pubspec_file_path
|
613
|
-
|
614
|
-
pubspec_config = FileUtil.load_pubspec_config_from_file(pubspec_file_path)
|
615
|
-
|
616
|
-
Checker.check_flr_config_is_existed(pubspec_config)
|
617
|
-
|
618
|
-
flr_config = pubspec_config["flr"]
|
619
|
-
|
620
|
-
resource_dir_result_tuple = Checker.check_flr_assets_is_legal(flr_config)
|
621
|
-
|
883
|
+
Checker.check_pubspec_file_is_existed(flutter_main_project_root_dir)
|
622
884
|
rescue Exception => e
|
623
885
|
puts(e.message)
|
624
886
|
return
|
625
887
|
end
|
626
888
|
|
627
|
-
package_name = pubspec_config["name"]
|
628
|
-
|
629
889
|
# ----- Step-1 End -----
|
630
890
|
|
891
|
+
|
631
892
|
# ----- Step-2 Begin -----
|
632
|
-
#
|
893
|
+
# 对flutter工程进行合法资源目录检测:
|
894
|
+
# - 获取主工程的所有子工程根目录,生成工程根目录数组flutter_project_root_dir_array
|
895
|
+
# - 遍历flutter_project_root_dir_array,获取每个工程的legal_resource_dir数组:
|
896
|
+
# - 从flr_config中的assets配置获取assets_legal_resource_dir数组;
|
897
|
+
# - 从flr_config中的fonts配置获取fonts_legal_resource_dir数组;
|
898
|
+
# - 合并assets_legal_resource_dir数组和fonts_legal_resource_dir数组到legal_resource_dir数组。
|
899
|
+
# - 检测legal_resource_dir数组是否为空,为空则结束运行。
|
633
900
|
#
|
901
|
+
puts("")
|
902
|
+
puts("get the valid resource directories of all projects now ...")
|
634
903
|
|
635
|
-
|
636
|
-
|
637
|
-
|
638
|
-
|
639
|
-
|
640
|
-
|
641
|
-
|
642
|
-
|
643
|
-
|
904
|
+
flutter_main_project_root_dir = FileUtil.get_flutter_main_project_root_dir
|
905
|
+
flutter_sub_project_root_dir_array = FileUtil.get_flutter_sub_project_root_dirs(flutter_main_project_root_dir)
|
906
|
+
|
907
|
+
flutter_project_root_dir_array = []
|
908
|
+
flutter_project_root_dir_array.push(flutter_main_project_root_dir)
|
909
|
+
flutter_project_root_dir_array += flutter_sub_project_root_dir_array
|
910
|
+
|
911
|
+
# 合法的资源目录数组
|
912
|
+
legal_resource_dir_array = []
|
913
|
+
# 非法的资源目录数组
|
914
|
+
illegal_resource_dir_array = []
|
915
|
+
|
916
|
+
flutter_project_root_dir_array.each do |flutter_project_root_dir|
|
917
|
+
begin
|
918
|
+
puts("")
|
919
|
+
puts("--------------------------- get info of specified project ----------------------------")
|
920
|
+
puts("get the valid resource directories from #{flutter_project_root_dir} now...")
|
921
|
+
|
922
|
+
Checker.check_pubspec_file_is_existed(flutter_project_root_dir)
|
923
|
+
|
924
|
+
pubspec_file_path = FileUtil.get_pubspec_file_path(flutter_project_root_dir)
|
925
|
+
|
926
|
+
pubspec_config = FileUtil.load_pubspec_config_from_file(pubspec_file_path)
|
927
|
+
|
928
|
+
Checker.check_flr_config_is_existed(pubspec_config)
|
929
|
+
|
930
|
+
flr_config = pubspec_config["flr"]
|
931
|
+
|
932
|
+
resource_dir_result_tuple = Checker.check_flr_assets_is_legal(flutter_project_root_dir, flr_config)
|
933
|
+
|
934
|
+
assets_legal_resource_dir_array = resource_dir_result_tuple[0]
|
935
|
+
fonts_legal_resource_dir_array = resource_dir_result_tuple[1]
|
936
|
+
legal_resource_dir_array += (assets_legal_resource_dir_array + fonts_legal_resource_dir_array)
|
937
|
+
|
938
|
+
illegal_resource_dir_array += resource_dir_result_tuple[2]
|
939
|
+
puts("get the valid resource directories from #{flutter_project_root_dir} done !!!")
|
940
|
+
puts("--------------------------------------------------------------------------------------")
|
941
|
+
rescue Exception => e
|
942
|
+
puts(e.message)
|
943
|
+
puts("[x]: #{flutter_project_root_dir} has no valid resource directories".error_style)
|
944
|
+
puts("--------------------------------------------------------------------------------------")
|
945
|
+
end
|
946
|
+
end
|
947
|
+
|
948
|
+
if legal_resource_dir_array.length <= 0
|
949
|
+
puts("")
|
950
|
+
puts("[x]: have no valid resource directories to be monitored".error_style)
|
951
|
+
return
|
952
|
+
end
|
953
|
+
|
954
|
+
puts("")
|
955
|
+
puts("get the valid resource directories of all projects done !!!")
|
644
956
|
|
645
957
|
# ----- Step-2 End -----
|
646
958
|
|
959
|
+
|
647
960
|
# ----- Step-3 Begin -----
|
648
|
-
#
|
649
|
-
# - 从flr_config中的assets配置获取assets_legal_resource_dir数组;
|
650
|
-
# - 从flr_config中的fonts配置获取fonts_legal_resource_dir数组;
|
651
|
-
# - 合并assets_legal_resource_dir数组和fonts_legal_resource_dir数组为legal_resource_dir数组。
|
961
|
+
# 执行一次 generate_all 操作
|
652
962
|
#
|
653
963
|
|
654
|
-
|
655
|
-
|
656
|
-
|
657
|
-
|
658
|
-
|
659
|
-
|
660
|
-
# 非法的资源目录数组
|
661
|
-
illegal_resource_dir_array = resource_dir_result_tuple[2]
|
964
|
+
puts("")
|
965
|
+
puts("now generate for all projects once before launching the monitoring service ...")
|
966
|
+
puts("")
|
967
|
+
generate_all
|
968
|
+
puts("")
|
969
|
+
puts("did generate for all projects, now is going to launching the monitoring service ...")
|
662
970
|
|
663
971
|
# ----- Step-3 End -----
|
664
972
|
|
973
|
+
|
665
974
|
# ----- Step-4 Begin -----
|
666
975
|
# 启动资源监控服务
|
667
976
|
# - 启动一个文件监控服务,对 legal_resource_dir 数组中的资源目录进行文件监控
|
668
977
|
# - 若服务检测到资源变化(资源目录下的发生增/删/改文件),则执行一次 flr generate 操作
|
669
978
|
#
|
670
979
|
|
980
|
+
puts("")
|
671
981
|
now_str = Time.now.to_s
|
672
|
-
puts("
|
982
|
+
puts("----------------------------- #{now_str} -----------------------------")
|
673
983
|
puts("launch a monitoring service now ...")
|
674
984
|
puts("launching ...")
|
675
985
|
# stop the monitoring service if exists
|
@@ -686,7 +996,7 @@ module Flr
|
|
686
996
|
puts(" - #{resource_dir}".warning_style)
|
687
997
|
end
|
688
998
|
end
|
689
|
-
puts("
|
999
|
+
puts("--------------------------------------------------------------------------------------")
|
690
1000
|
puts("\n")
|
691
1001
|
|
692
1002
|
# Allow array of directories as input #92
|
@@ -694,16 +1004,16 @@ module Flr
|
|
694
1004
|
@@listener = Listen.to(*legal_resource_dir_array, ignore: [/\.DS_Store/], latency: 0.5, wait_for_delay: 5, relative: true) do |modified, added, removed|
|
695
1005
|
# for example: 2013-03-30 03:13:14 +0900
|
696
1006
|
now_str = Time.now.to_s
|
697
|
-
puts("
|
1007
|
+
puts("----------------------------- #{now_str} -----------------------------")
|
698
1008
|
puts("modified resource files: #{modified}")
|
699
1009
|
puts("added resource files: #{added}")
|
700
1010
|
puts("removed resource files: #{removed}")
|
701
|
-
puts("
|
1011
|
+
puts("generate for all projects now ...")
|
702
1012
|
puts("\n")
|
703
|
-
|
1013
|
+
generate_all
|
704
1014
|
puts("\n")
|
705
|
-
puts("
|
706
|
-
puts("
|
1015
|
+
puts("generate for all projects done !!!")
|
1016
|
+
puts("--------------------------------------------------------------------------------------")
|
707
1017
|
puts("\n")
|
708
1018
|
puts("[*]: the monitoring service is monitoring the asset changes, and then auto scan assets, specifies assets and generates \"r.g.dart\" ...".tips_style)
|
709
1019
|
puts("[*]: you can press \"Ctrl-C\" to terminate it".tips_style)
|