flr 2.0.0 → 3.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.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/CHANGELOG.md +13 -0
- data/Gemfile.lock +1 -1
- data/lib/flr/checker.rb +11 -11
- data/lib/flr/command.rb +58 -7
- data/lib/flr/util/asset_util.rb +50 -26
- data/lib/flr/util/code_util.rb +75 -24
- data/lib/flr/util/file_util.rb +66 -4
- data/lib/flr/version.rb +2 -2
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4e7b9ee5330233ba9aac3017cd51d403139365b6f95bd0729e188671dfadfb35
|
4
|
+
data.tar.gz: 8be015c230dc9581326c39f7b5dd53074779e7f6291c911a18f9e9afac20ef7c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3ae44108a8e59cd1680700276f5b1d47a6235c5624566c6195f17bd522d901b02182faecee8dba056c200723f57f54e379ca37a8483c0493dc6dfe5a3678e7e2
|
7
|
+
data.tar.gz: 98b5bf07ab3bce3305572555d58ef71037d9c6822aa1f4842fcb1d07e8090bf9a198b40cd269e08bbdd18103c4419d6b2b30f38b8cff6ce7300c9c2c613e937d
|
data/.gitignore
CHANGED
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,16 @@
|
|
1
|
+
## 3.0.0
|
2
|
+
|
3
|
+
- Support for processing non-implied resource file
|
4
|
+
|
5
|
+
> - non-implied resource file: the resource file which is outside of `lib/` directory, for example:
|
6
|
+
> - `~/path/to/flutter_r_demo/assets/images/test.png`
|
7
|
+
> - `~/path/to/flutter_r_demo/assets/images/3.0x/test.png`
|
8
|
+
> - implied resource file: the resource file which is inside of `lib/` directory, for example:
|
9
|
+
> - `~/path/to/flutter_r_demo/lib/assets/images/hot_foot_N.png`
|
10
|
+
> - `~/path/to/flutter_r_demo/lib/assets/images/3.0x/hot_foot_N.png`
|
11
|
+
|
12
|
+
- New recommended flutter resource structure
|
13
|
+
|
1
14
|
## 2.0.0
|
2
15
|
|
3
16
|
- New asset generation algorithm to support all kinds of standard or nonstandard image/text resource structure
|
data/Gemfile.lock
CHANGED
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(
|
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,12 +88,12 @@ module Flr
|
|
88
88
|
# 判断flr的assets配置合法的标准是:assets配置的resource_dir数组中的legal_resource_dir数量大于0。
|
89
89
|
#
|
90
90
|
# === Examples
|
91
|
-
#
|
91
|
+
# flutter_project_dir = "~/path/to/flutter_r_demo"
|
92
92
|
# assets_legal_resource_dir_array = ["~/path/to/flutter_r_demo/lib/assets/images", "~/path/to/flutter_r_demo/lib/assets/texts"]
|
93
93
|
# fonts_legal_resource_dir_array = ["~/path/to/flutter_r_demo/lib/assets/fonts"]
|
94
94
|
# illegal_resource_dir_array = ["~/path/to/flutter_r_demo/to/non-existed_folder"]
|
95
95
|
#
|
96
|
-
def self.check_flr_assets_is_legal(
|
96
|
+
def self.check_flr_assets_is_legal(flutter_project_dir, flr_config)
|
97
97
|
core_version = flr_config["core_version"]
|
98
98
|
dartfmt_line_length = flr_config["dartfmt_line_length"]
|
99
99
|
assets_resource_dir_array = flr_config["assets"]
|
@@ -121,7 +121,7 @@ module Flr
|
|
121
121
|
illegal_resource_dir_array = []
|
122
122
|
|
123
123
|
assets_resource_dir_array.each do |relative_resource_dir|
|
124
|
-
resource_dir =
|
124
|
+
resource_dir = flutter_project_dir + "/" + relative_resource_dir
|
125
125
|
if File.exist?(resource_dir) == true
|
126
126
|
assets_legal_resource_dir_array.push(resource_dir)
|
127
127
|
else
|
@@ -130,7 +130,7 @@ module Flr
|
|
130
130
|
end
|
131
131
|
|
132
132
|
fonts_resource_dir_array.each do |relative_resource_dir|
|
133
|
-
resource_dir =
|
133
|
+
resource_dir = flutter_project_dir + "/" + relative_resource_dir
|
134
134
|
if File.exist?(resource_dir) == true
|
135
135
|
fonts_legal_resource_dir_array.push(resource_dir)
|
136
136
|
else
|
data/lib/flr/command.rb
CHANGED
@@ -36,7 +36,9 @@ module Flr
|
|
36
36
|
# display recommended flutter resource structure
|
37
37
|
def self.display_recommended_flutter_resource_structure
|
38
38
|
message = <<-MESSAGE
|
39
|
-
Flr recommends the following flutter resource structure:
|
39
|
+
Flr recommends the following flutter resource structure schemes:
|
40
|
+
|
41
|
+
#{"------------------------------ scheme 1 ------------------------------".bold.bg_red}
|
40
42
|
|
41
43
|
flutter_project_root_dir
|
42
44
|
├── build
|
@@ -84,6 +86,54 @@ Flr recommends the following flutter resource structure:
|
|
84
86
|
#{"fonts:".tips_style}
|
85
87
|
#{"- lib/assets/fonts".tips_style}
|
86
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}
|
87
137
|
MESSAGE
|
88
138
|
|
89
139
|
puts(message)
|
@@ -126,7 +176,7 @@ Flr recommends the following flutter resource structure:
|
|
126
176
|
begin
|
127
177
|
Checker.check_pubspec_file_is_existed(flutter_project_root_dir)
|
128
178
|
|
129
|
-
pubspec_file_path = FileUtil.get_pubspec_file_path
|
179
|
+
pubspec_file_path = FileUtil.get_pubspec_file_path(flutter_project_root_dir)
|
130
180
|
|
131
181
|
pubspec_config = FileUtil.load_pubspec_config_from_file(pubspec_file_path)
|
132
182
|
|
@@ -278,7 +328,7 @@ Flr recommends the following flutter resource structure:
|
|
278
328
|
begin
|
279
329
|
Checker.check_pubspec_file_is_existed(flutter_project_root_dir)
|
280
330
|
|
281
|
-
pubspec_file_path = FileUtil.get_pubspec_file_path
|
331
|
+
pubspec_file_path = FileUtil.get_pubspec_file_path(flutter_project_root_dir)
|
282
332
|
|
283
333
|
pubspec_config = FileUtil.load_pubspec_config_from_file(pubspec_file_path)
|
284
334
|
|
@@ -293,6 +343,7 @@ Flr recommends the following flutter resource structure:
|
|
293
343
|
return
|
294
344
|
end
|
295
345
|
|
346
|
+
is_package_project_type = FileUtil.is_package_project_type?(flutter_project_root_dir)
|
296
347
|
package_name = pubspec_config["name"]
|
297
348
|
|
298
349
|
# ----- Step-1 End -----
|
@@ -588,7 +639,7 @@ Flr recommends the following flutter resource structure:
|
|
588
639
|
#
|
589
640
|
|
590
641
|
r_dart_file.puts("\n")
|
591
|
-
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)
|
642
|
+
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)
|
592
643
|
r_dart_file.puts(g__R_Image_AssetResource_class_code)
|
593
644
|
|
594
645
|
# ----- Step-13 End -----
|
@@ -598,7 +649,7 @@ Flr recommends the following flutter resource structure:
|
|
598
649
|
#
|
599
650
|
|
600
651
|
r_dart_file.puts("\n")
|
601
|
-
g__R_Svg_AssetResource_class_code = CodeUtil.generate__R_Svg_AssetResource_class(svg_image_asset_array, svg_image_asset_id_dict, package_name)
|
652
|
+
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)
|
602
653
|
r_dart_file.puts(g__R_Svg_AssetResource_class_code)
|
603
654
|
|
604
655
|
# ----- Step-14 End -----
|
@@ -608,7 +659,7 @@ Flr recommends the following flutter resource structure:
|
|
608
659
|
#
|
609
660
|
|
610
661
|
r_dart_file.puts("\n")
|
611
|
-
g__R_Text_AssetResource_class_code = CodeUtil.generate__R_Text_AssetResource_class(text_asset_array, text_asset_id_dict, package_name)
|
662
|
+
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)
|
612
663
|
r_dart_file.puts(g__R_Text_AssetResource_class_code)
|
613
664
|
|
614
665
|
# ----- Step-15 End -----
|
@@ -726,7 +777,7 @@ Flr recommends the following flutter resource structure:
|
|
726
777
|
begin
|
727
778
|
Checker.check_pubspec_file_is_existed(flutter_project_root_dir)
|
728
779
|
|
729
|
-
pubspec_file_path = FileUtil.get_pubspec_file_path
|
780
|
+
pubspec_file_path = FileUtil.get_pubspec_file_path(flutter_project_root_dir)
|
730
781
|
|
731
782
|
pubspec_config = FileUtil.load_pubspec_config_from_file(pubspec_file_path)
|
732
783
|
|
data/lib/flr/util/asset_util.rb
CHANGED
@@ -34,12 +34,12 @@ module Flr
|
|
34
34
|
return false
|
35
35
|
end
|
36
36
|
|
37
|
-
# generate_main_asset(
|
37
|
+
# generate_main_asset(flutter_project_dir, package_name, legal_resource_file) -> main_asset
|
38
38
|
#
|
39
39
|
# 为当前资源文件生成 main_asset
|
40
40
|
#
|
41
41
|
# === Examples
|
42
|
-
#
|
42
|
+
# flutter_project_dir = "~/path/to/flutter_r_demo"
|
43
43
|
# package_name = "flutter_r_demo"
|
44
44
|
#
|
45
45
|
# === Example-1
|
@@ -58,7 +58,15 @@ module Flr
|
|
58
58
|
# legal_resource_file = "~/path/to/flutter_r_demo/lib/assets/fonts/Amiri/Amiri-Regular.ttf"
|
59
59
|
# main_asset = "packages/flutter_r_demo/fonts/Amiri/Amiri-Regular.ttf"
|
60
60
|
#
|
61
|
-
|
61
|
+
# === Example-4
|
62
|
+
# legal_resource_file = "~/path/to/flutter_r_demo/assets/images/test.png"
|
63
|
+
# main_asset = "assets/images/test.png"
|
64
|
+
#
|
65
|
+
# === Example-5
|
66
|
+
# legal_resource_file = "~/path/to/flutter_r_demo/assets/images/3.0x/test.png"
|
67
|
+
# main_asset = "assets/images/test.png"
|
68
|
+
#
|
69
|
+
def self.generate_main_asset(flutter_project_dir, package_name, legal_resource_file)
|
62
70
|
# legal_resource_file: ~/path/to/flutter_r_demo/lib/assets/images/3.0x/test.png
|
63
71
|
# to get main_resource_file: ~/path/to/flutter_r_demo/lib/assets/images/test.png
|
64
72
|
main_resource_file = legal_resource_file
|
@@ -74,39 +82,55 @@ module Flr
|
|
74
82
|
end
|
75
83
|
|
76
84
|
# main_resource_file: ~/path/to/flutter_r_demo/lib/assets/images/test.png
|
77
|
-
# main_relative_resource_file: lib/assets/images/test.png
|
78
|
-
|
79
|
-
flutter_dir_prefix = "#{flutter_dir}/"
|
85
|
+
# to get main_relative_resource_file: lib/assets/images/test.png
|
86
|
+
flutter_project_dir_prefix = "#{flutter_project_dir}/"
|
80
87
|
main_relative_resource_file = main_resource_file
|
81
|
-
if main_relative_resource_file =~ /\A#{
|
82
|
-
main_relative_resource_file["#{
|
88
|
+
if main_relative_resource_file =~ /\A#{flutter_project_dir_prefix}/
|
89
|
+
main_relative_resource_file["#{flutter_project_dir_prefix}"] = ""
|
83
90
|
end
|
91
|
+
|
92
|
+
# 判断 main_relative_resource_file 是不是 implied_resource_file 类型
|
93
|
+
# implied_resource_file 的定义是:放置在 "lib/" 目录内 resource_file
|
94
|
+
# 具体实现是:main_relative_resource_file 的前缀若是 "lib/" ,则其是 implied_resource_file 类型;
|
95
|
+
#
|
96
|
+
# implied_relative_resource_file 生成 main_asset 的算法是: main_asset = "packages/#{package_name}/#{asset_name}"
|
97
|
+
# non-implied_relative_resource_file 生成 main_asset 的算法是: main_asset = "#{asset_name}"
|
98
|
+
#
|
84
99
|
lib_prefix = "lib/"
|
85
|
-
|
86
|
-
|
87
|
-
|
100
|
+
if main_relative_resource_file =~ /\A#{lib_prefix}/
|
101
|
+
# main_relative_resource_file: lib/assets/images/test.png
|
102
|
+
# to get asset_name: assets/images/test.png
|
103
|
+
asset_name = main_relative_resource_file
|
104
|
+
asset_name[lib_prefix] = ""
|
105
|
+
|
106
|
+
main_asset = "packages/#{package_name}/#{asset_name}"
|
107
|
+
return main_asset
|
108
|
+
else
|
109
|
+
# main_relative_resource_file: assets/images/test.png
|
110
|
+
# to get asset_name: assets/images/test.png
|
111
|
+
asset_name = main_relative_resource_file
|
112
|
+
|
113
|
+
main_asset = asset_name
|
114
|
+
return main_asset
|
88
115
|
end
|
89
|
-
|
90
|
-
main_asset = "packages/#{package_name}/#{main_implied_relative_resource_file}"
|
91
|
-
return main_asset
|
92
116
|
end
|
93
117
|
|
94
|
-
# generate_image_assets(
|
118
|
+
# generate_image_assets(flutter_project_dir, package_name, legal_image_file_array) -> image_asset_array
|
95
119
|
#
|
96
120
|
# 遍历指定资源目录下扫描找到的legal_image_file数组生成image_asset数组
|
97
121
|
#
|
98
122
|
# === Examples
|
99
|
-
#
|
123
|
+
# flutter_project_dir = "~/path/to/flutter_r_demo"
|
100
124
|
# package_name = "flutter_r_demo"
|
101
125
|
# legal_image_file_array = ["~/path/to/flutter_r_demo/lib/assets/images/test.png", "~/path/to/flutter_r_demo/lib/assets/images/3.0x/test.png"]
|
102
126
|
# image_asset_array = ["packages/flutter_r_demo/assets/images/test.png"]
|
103
127
|
#
|
104
|
-
def self.generate_image_assets(
|
128
|
+
def self.generate_image_assets(flutter_project_dir, package_name, legal_image_file_array)
|
105
129
|
|
106
130
|
image_asset_array = []
|
107
131
|
|
108
132
|
legal_image_file_array.each do |legal_image_file|
|
109
|
-
image_asset = generate_main_asset(
|
133
|
+
image_asset = generate_main_asset(flutter_project_dir, package_name, legal_image_file)
|
110
134
|
image_asset_array.push(image_asset)
|
111
135
|
end
|
112
136
|
|
@@ -114,22 +138,22 @@ module Flr
|
|
114
138
|
return image_asset_array
|
115
139
|
end
|
116
140
|
|
117
|
-
# generate_text_assets(
|
141
|
+
# generate_text_assets(flutter_project_dir, package_name, legal_text_file_array) -> text_asset_array
|
118
142
|
#
|
119
143
|
# 遍历指定资源目录下扫描找到的legal_text_file数组生成text_asset数组
|
120
144
|
#
|
121
145
|
# === Examples
|
122
|
-
#
|
146
|
+
# flutter_project_dir = "~/path/to/flutter_r_demo"
|
123
147
|
# package_name = "flutter_r_demo"
|
124
148
|
# legal_text_file_array = ["~path/to/flutter_r_demo/lib/assets/jsons/test.json"]
|
125
149
|
# text_asset_array = ["packages/flutter_r_demo/assets/jsons/test.json"]
|
126
150
|
#
|
127
|
-
def self.generate_text_assets(
|
151
|
+
def self.generate_text_assets(flutter_project_dir, package_name, legal_text_file_array)
|
128
152
|
|
129
153
|
text_asset_array = []
|
130
154
|
|
131
155
|
legal_text_file_array.each do |legal_text_file|
|
132
|
-
text_asset = generate_main_asset(
|
156
|
+
text_asset = generate_main_asset(flutter_project_dir, package_name, legal_text_file)
|
133
157
|
text_asset_array.push(text_asset)
|
134
158
|
end
|
135
159
|
|
@@ -137,22 +161,22 @@ module Flr
|
|
137
161
|
return text_asset_array
|
138
162
|
end
|
139
163
|
|
140
|
-
# generate_font_asset_configs(
|
164
|
+
# generate_font_asset_configs(flutter_project_dir, package_name, legal_font_file_array) -> font_asset_config_array
|
141
165
|
#
|
142
166
|
# 遍历指定资源目录下扫描找到的legal_font_file数组生成font_asset_config数组
|
143
167
|
#
|
144
168
|
# === Examples
|
145
|
-
#
|
169
|
+
# flutter_project_dir = "~/path/to/flutter_r_demo"
|
146
170
|
# package_name = "flutter_r_demo"
|
147
171
|
# legal_font_file_array = ["~path/to/flutter_r_demo/lib/assets/fonts/Amiri/Amiri-Regular.ttf"]
|
148
172
|
# font_asset_config_array -> [{"asset": "packages/flutter_r_demo/assets/fonts/Amiri/Amiri-Regular.ttf"}]
|
149
173
|
#
|
150
|
-
def self.generate_font_asset_configs(
|
174
|
+
def self.generate_font_asset_configs(flutter_project_dir, package_name, legal_font_file_array)
|
151
175
|
|
152
176
|
font_asset_config_array = []
|
153
177
|
|
154
178
|
legal_font_file_array.each do |legal_font_file|
|
155
|
-
font_asset = generate_main_asset(
|
179
|
+
font_asset = generate_main_asset(flutter_project_dir, package_name, legal_font_file)
|
156
180
|
font_asset_config = Hash["asset" => font_asset]
|
157
181
|
font_asset_config_array.push(font_asset_config)
|
158
182
|
end
|
data/lib/flr/util/code_util.rb
CHANGED
@@ -210,54 +210,105 @@ class AssetResource {
|
|
210
210
|
# 为当前asset生成注释
|
211
211
|
#
|
212
212
|
# === Examples
|
213
|
-
# asset = "packages/flutter_r_demo/assets/images/test.png"
|
214
213
|
# package_name = "flutter_r_demo"
|
214
|
+
#
|
215
|
+
# === Example-1
|
216
|
+
# asset = "packages/flutter_r_demo/assets/images/test.png"
|
217
|
+
# asset_comment = "asset: lib/assets/images/test.png"
|
218
|
+
#
|
219
|
+
# === Example-2
|
220
|
+
# asset = "assets/images/test.png"
|
215
221
|
# asset_comment = "asset: assets/images/test.png"
|
216
222
|
#
|
217
223
|
def self.generate_asset_comment (asset, package_name)
|
224
|
+
packages_prefix = "packages/#{package_name}/"
|
225
|
+
|
226
|
+
if asset =~ /\A#{packages_prefix}/
|
227
|
+
# asset: packages/flutter_r_demo/assets/images/test.png
|
228
|
+
# to get assetName: assets/images/test.png
|
229
|
+
asset_name = asset.dup
|
230
|
+
asset_name[packages_prefix] = ""
|
231
|
+
|
232
|
+
asset_comment = "asset: lib/#{asset_name}"
|
233
|
+
return asset_comment
|
234
|
+
else
|
235
|
+
# asset: assets/images/test.png
|
236
|
+
# to get assetName: assets/images/test.png
|
237
|
+
asset_name = asset.dup
|
238
|
+
|
239
|
+
asset_comment = "asset: #{asset_name}"
|
240
|
+
return asset_comment
|
241
|
+
end
|
218
242
|
|
219
|
-
asset_name = asset.dup
|
220
|
-
asset_name["packages/#{package_name}/"] = ""
|
221
|
-
|
222
|
-
asset_comment = "asset: #{asset_name}"
|
223
|
-
|
224
|
-
return asset_comment
|
225
243
|
end
|
226
244
|
|
227
|
-
# generate_AssetResource_property(asset, asset_id_dict, package_name, prior_asset_type) -> string
|
245
|
+
# generate_AssetResource_property(asset, asset_id_dict, package_name, is_package_project_type, prior_asset_type) -> string
|
228
246
|
#
|
229
247
|
# 为当前 asset 生成 AssetResource property 的代码
|
230
248
|
#
|
231
|
-
def self.generate_AssetResource_property(asset, asset_id_dict, package_name, prior_asset_type = ".*")
|
232
|
-
|
249
|
+
def self.generate_AssetResource_property(asset, asset_id_dict, package_name, is_package_project_type, prior_asset_type = ".*")
|
233
250
|
asset_id = asset_id_dict[asset]
|
234
251
|
asset_comment = generate_asset_comment(asset, package_name)
|
235
252
|
|
236
|
-
asset_name =
|
237
|
-
|
253
|
+
asset_name = ""
|
254
|
+
needPackage = false
|
255
|
+
|
256
|
+
packages_prefix = "packages/#{package_name}/"
|
257
|
+
if asset =~ /\A#{packages_prefix}/
|
258
|
+
# asset: packages/flutter_r_demo/assets/images/test.png
|
259
|
+
# to get asset_name: assets/images/test.png
|
260
|
+
asset_name = asset.dup
|
261
|
+
asset_name[packages_prefix] = ""
|
262
|
+
|
263
|
+
needPackage = true
|
264
|
+
else
|
265
|
+
# asset: assets/images/test.png
|
266
|
+
# to get asset_name: assets/images/test.png
|
267
|
+
asset_name = asset.dup
|
268
|
+
|
269
|
+
if is_package_project_type
|
270
|
+
needPackage = true
|
271
|
+
else
|
272
|
+
needPackage = false
|
273
|
+
end
|
274
|
+
|
275
|
+
end
|
276
|
+
|
238
277
|
# 对字符串中的 '$' 进行转义处理:'$' -> '\$'
|
278
|
+
# asset_name: assets/images/test$.png
|
279
|
+
# to get escaped_asset_name: assets/images/test\$.png
|
239
280
|
escaped_asset_name = asset_name.gsub(/[$]/, "\\$")
|
240
281
|
|
241
|
-
|
282
|
+
if needPackage
|
283
|
+
code = <<-CODE
|
242
284
|
/// #{asset_comment}
|
243
285
|
// ignore: non_constant_identifier_names
|
244
286
|
final #{asset_id} = const AssetResource("#{escaped_asset_name}", packageName: R.package);
|
245
|
-
|
287
|
+
CODE
|
246
288
|
|
247
|
-
|
289
|
+
return code
|
290
|
+
else
|
291
|
+
code = <<-CODE
|
292
|
+
/// #{asset_comment}
|
293
|
+
// ignore: non_constant_identifier_names
|
294
|
+
final #{asset_id} = const AssetResource("#{escaped_asset_name}", packageName: null);
|
295
|
+
CODE
|
296
|
+
|
297
|
+
return code
|
298
|
+
end
|
248
299
|
end
|
249
300
|
|
250
|
-
# generate__R_Image_AssetResource_class(non_svg_image_asset_array, non_svg_image_asset_id_dict, package_name) -> string
|
301
|
+
# generate__R_Image_AssetResource_class(non_svg_image_asset_array, non_svg_image_asset_id_dict, package_name, is_package_project_type) -> string
|
251
302
|
#
|
252
303
|
# 根据模板,为 non_svg_image_asset_array(非svg类的图片资产数组)生成 _R_Image_AssetResource class 的代码
|
253
304
|
#
|
254
|
-
def self.generate__R_Image_AssetResource_class(non_svg_image_asset_array, non_svg_image_asset_id_dict, package_name)
|
305
|
+
def self.generate__R_Image_AssetResource_class(non_svg_image_asset_array, non_svg_image_asset_id_dict, package_name, is_package_project_type)
|
255
306
|
|
256
307
|
all_g_AssetResource_property_code = ""
|
257
308
|
|
258
309
|
non_svg_image_asset_array.each do |image_asset|
|
259
310
|
all_g_AssetResource_property_code += "\n"
|
260
|
-
g_AssetResource_property_code = generate_AssetResource_property(image_asset, non_svg_image_asset_id_dict, package_name, Flr::PRIOR_NON_SVG_IMAGE_FILE_TYPE)
|
311
|
+
g_AssetResource_property_code = generate_AssetResource_property(image_asset, non_svg_image_asset_id_dict, package_name, is_package_project_type, Flr::PRIOR_NON_SVG_IMAGE_FILE_TYPE)
|
261
312
|
all_g_AssetResource_property_code += g_AssetResource_property_code
|
262
313
|
end
|
263
314
|
|
@@ -272,17 +323,17 @@ class _R_Image_AssetResource {
|
|
272
323
|
return code
|
273
324
|
end
|
274
325
|
|
275
|
-
# generate__R_Svg_AssetResource_class(svg_image_asset_array, svg_image_asset_id_dict, package_name) -> string
|
326
|
+
# generate__R_Svg_AssetResource_class(svg_image_asset_array, svg_image_asset_id_dict, package_name, is_package_project_type) -> string
|
276
327
|
#
|
277
328
|
# 根据模板,为 svg_image_asset_array(svg类的图片资产数组)生成 _R_Svg_AssetResource class 的代码
|
278
329
|
#
|
279
|
-
def self.generate__R_Svg_AssetResource_class(svg_image_asset_array, svg_image_asset_id_dict, package_name)
|
330
|
+
def self.generate__R_Svg_AssetResource_class(svg_image_asset_array, svg_image_asset_id_dict, package_name, is_package_project_type)
|
280
331
|
|
281
332
|
all_g_AssetResource_property_code = ""
|
282
333
|
|
283
334
|
svg_image_asset_array.each do |image_asset|
|
284
335
|
all_g_AssetResource_property_code += "\n"
|
285
|
-
g_AssetResource_property_code = generate_AssetResource_property(image_asset, svg_image_asset_id_dict, package_name, Flr::PRIOR_SVG_IMAGE_FILE_TYPE)
|
336
|
+
g_AssetResource_property_code = generate_AssetResource_property(image_asset, svg_image_asset_id_dict, package_name, is_package_project_type, Flr::PRIOR_SVG_IMAGE_FILE_TYPE)
|
286
337
|
all_g_AssetResource_property_code += g_AssetResource_property_code
|
287
338
|
end
|
288
339
|
|
@@ -297,17 +348,17 @@ class _R_Svg_AssetResource {
|
|
297
348
|
return code
|
298
349
|
end
|
299
350
|
|
300
|
-
# generate__R_Text_AssetResource_class(text_asset_array, text_asset_id_dict, package_name) -> string
|
351
|
+
# generate__R_Text_AssetResource_class(text_asset_array, text_asset_id_dict, package_name, is_package_project_typ) -> string
|
301
352
|
#
|
302
353
|
# 根据模板,为 text_asset_array(文本资产数组)生成 _R_Text_AssetResource class 的代码
|
303
354
|
#
|
304
|
-
def self.generate__R_Text_AssetResource_class(text_asset_array, text_asset_id_dict, package_name)
|
355
|
+
def self.generate__R_Text_AssetResource_class(text_asset_array, text_asset_id_dict, package_name, is_package_project_type)
|
305
356
|
|
306
357
|
all_g_AssetResource_property_code = ""
|
307
358
|
|
308
359
|
text_asset_array.each do |text_asset|
|
309
360
|
all_g_AssetResource_property_code += "\n"
|
310
|
-
g_AssetResource_property_code = generate_AssetResource_property(text_asset, text_asset_id_dict, package_name, Flr::PRIOR_TEXT_FILE_TYPE)
|
361
|
+
g_AssetResource_property_code = generate_AssetResource_property(text_asset, text_asset_id_dict, package_name, is_package_project_type, Flr::PRIOR_TEXT_FILE_TYPE)
|
311
362
|
all_g_AssetResource_property_code += g_AssetResource_property_code
|
312
363
|
end
|
313
364
|
|
data/lib/flr/util/file_util.rb
CHANGED
@@ -15,13 +15,16 @@ module Flr
|
|
15
15
|
return flutter_project_root_dir
|
16
16
|
end
|
17
17
|
|
18
|
-
# get_pubspec_file_path -> String
|
18
|
+
# get_pubspec_file_path(flutter_project_dir) -> String
|
19
19
|
#
|
20
20
|
# 获取当前flutter工程的pubspec.yaml文件的路径
|
21
21
|
#
|
22
|
-
|
23
|
-
|
24
|
-
|
22
|
+
# === Examples
|
23
|
+
# flutter_project_dir = "~/path/to/flutter_r_demo"
|
24
|
+
# pubspec_file_path = "~/path/to/flutter_r_demo/pubspec.yaml"
|
25
|
+
#
|
26
|
+
def self.get_pubspec_file_path(flutter_project_dir)
|
27
|
+
file_path = flutter_project_dir + "/pubspec.yaml"
|
25
28
|
return file_path
|
26
29
|
end
|
27
30
|
|
@@ -79,6 +82,65 @@ module Flr
|
|
79
82
|
return true
|
80
83
|
end
|
81
84
|
|
85
|
+
# is_package_project_type?(flutter_project_dir) -> true or false
|
86
|
+
#
|
87
|
+
# 判断当前flutter工程的工程类型是不是Package工程类型
|
88
|
+
#
|
89
|
+
# flutter工程共有4种工程类型:
|
90
|
+
# - app:Flutter App工程,用于开发纯Flutter的App
|
91
|
+
# - module:Flutter Component工程,用于开发Flutter组件以嵌入iOS和Android原生工程
|
92
|
+
# - package:General Dart Package工程,用于开发一个供应用层开发者使用的包
|
93
|
+
# - plugin:Plugin Package工程(属于特殊的Dart Package工程),用于开发一个调用特定平台API的包
|
94
|
+
#
|
95
|
+
# flutter工程的工程类型可从flutter工程目录的 .metadata 文件中读取获得
|
96
|
+
# 如果不存在 .metadata 文件,则判断 pubspec.yaml 是否存在 author 配置,若存在,说明是一个 Package工程
|
97
|
+
#
|
98
|
+
def self.is_package_project_type?(flutter_project_dir)
|
99
|
+
metadata_file_path = flutter_project_dir + "/.metadata"
|
100
|
+
|
101
|
+
if File.exist?(metadata_file_path)
|
102
|
+
begin
|
103
|
+
metadata_file = File.open(metadata_file_path, 'r')
|
104
|
+
metadata_config = YAML.load(metadata_file)
|
105
|
+
project_type = metadata_config["project_type"]
|
106
|
+
if project_type.nil?
|
107
|
+
project_type = "unknown"
|
108
|
+
end
|
109
|
+
project_type = project_type.downcase
|
110
|
+
|
111
|
+
if project_type == "package" || project_type == "plugin"
|
112
|
+
return true
|
113
|
+
end
|
114
|
+
|
115
|
+
rescue YAML::SyntaxError => e
|
116
|
+
puts("YAML Syntax Error: #{e}".error_style)
|
117
|
+
puts("")
|
118
|
+
ensure
|
119
|
+
metadata_file.close
|
120
|
+
end
|
121
|
+
else
|
122
|
+
message = <<-MESSAGE
|
123
|
+
#{"[!]: warning, metadata file is missed, flr can not make sure to get a right project type of this flutter project".warning_style}
|
124
|
+
#{"[!]: then flr maybe generate buggy r.g.dart".warning_style}
|
125
|
+
#{"[*]: to fix it, you can manually copy the metadata file of a flutter project with same project type to #{metadata_file_path}".tips_style}
|
126
|
+
|
127
|
+
MESSAGE
|
128
|
+
puts(message)
|
129
|
+
|
130
|
+
begin
|
131
|
+
pubspec_file_path = get_pubspec_file_path(flutter_project_dir)
|
132
|
+
pubspec_config = load_pubspec_config_from_file(pubspec_file_path)
|
133
|
+
if pubspec_config.has_key?("author")
|
134
|
+
return true
|
135
|
+
end
|
136
|
+
rescue Exception => e
|
137
|
+
puts(e.message)
|
138
|
+
end
|
139
|
+
end
|
140
|
+
|
141
|
+
return false
|
142
|
+
end
|
143
|
+
|
82
144
|
# 判断当前文件是不是非SVG类图片资源文件
|
83
145
|
def self.is_non_svg_image_resource_file?(file)
|
84
146
|
file_extname = File.extname(file).downcase
|
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.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- York
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-04-
|
11
|
+
date: 2020-04-21 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|