Skip to content

Commit fa2b7f0

Browse files
committed
可执行安装
1 parent 2264615 commit fa2b7f0

File tree

3 files changed

+206
-38
lines changed

3 files changed

+206
-38
lines changed

bin/main.dart

+35-38
Original file line numberDiff line numberDiff line change
@@ -3,50 +3,47 @@ import 'dart:io';
33
import 'package:yaml/yaml.dart';
44
import 'package:io/ansi.dart';
55

6+
import 'temp.dart';
7+
68
main(List<String> arguments) {
7-
Platform.environment.forEach((k,v)=>print('$k $v'));
9+
// Platform.environment.forEach((k,v)=>print('$k $v'));
810
// 执行命令
911
// Process.run(executable, arguments);
1012
File pubspec = File("./pubspec.yaml");
1113
var pubspecDoc = loadYaml(pubspec.readAsStringSync());
12-
List excludes;
13-
if (pubspecDoc['flutter_icons'] != null &&
14-
pubspecDoc['flutter_icons']['excludes'] != null) {
15-
excludes = pubspecDoc['flutter_icons']['excludes'];
16-
File packages = File('./.packages');
17-
if (!packages.existsSync()) {
18-
print(yellow.wrap("${DateTime.now()}: Get the dependencies first"));
19-
return;
20-
}
21-
List<String> lines = packages.readAsLinesSync();
22-
// flutter_icons:file:///Users/makisu/development/flutter/.pub-cache/hosted/pub.flutter-io.cn/flutter_icons-1.0.0+1/lib/
23-
var flutterIconPath;
24-
for (var i = 0; i < lines.length; i++) {
25-
if (lines[i].contains("flutter_icons")) {
26-
flutterIconPath = lines[i]
27-
.replaceAll("flutter_icons:file://", "")
28-
.replaceAll("/lib/", "");
29-
break;
30-
}
31-
}
32-
if (flutterIconPath == null) {
33-
print(yellow.wrap("${DateTime.now()}: Get the flutter_icons dependency first"));
34-
return;
14+
File packages = File('./.packages');
15+
if (!packages.existsSync()) {
16+
print(yellow.wrap("${DateTime.now()}: Get the dependencies first"));
17+
return;
18+
}
19+
List<String> lines = packages.readAsLinesSync();
20+
// flutter_icons:file:///Users/makisu/development/flutter/.pub-cache/hosted/pub.flutter-io.cn/flutter_icons-1.0.0+1/lib/
21+
var flutterIconPath;
22+
for (var i = 0; i < lines.length; i++) {
23+
if (lines[i].contains("flutter_icons")) {
24+
flutterIconPath = lines[i]
25+
.replaceAll("flutter_icons:file://${Platform.isWindows?'/':''}", "")
26+
.replaceAll("/lib/", "");
27+
break;
3528
}
36-
File flutterIconsFile = File(flutterIconPath + '/pubspec.yaml');
37-
var iconsDoc = loadYaml(flutterIconsFile.readAsStringSync());
38-
Map iconMap = Map.of(iconsDoc);
39-
Map flutter = Map.of(iconMap['flutter']);
40-
Map environment = Map.of(iconMap['environment']);
41-
environment["sdk"] = "\"${environment['sdk']}\"";
42-
List fonts = List.of(flutter['fonts']);
43-
fonts.retainWhere((font)=>!excludes.contains(font['family']));
44-
flutter['fonts'] = fonts;
45-
iconMap['flutter'] = flutter;
46-
iconMap['environment'] = environment;
47-
print(iconMap['environment']['sdk']);
48-
// flutterIconsFile.writeAsStringSync(iconMap.toString());
4929
}
30+
if (flutterIconPath == null) {
31+
print(yellow
32+
.wrap("${DateTime.now()}: Get the flutter_icons dependency first"));
33+
return;
34+
}
35+
File flutterIconsFile = File(flutterIconPath + '/pubspec.yaml');
36+
List includes;
37+
String yamlString = tempYaml;
38+
if (pubspecDoc['flutter_icons'] != null &&
39+
pubspecDoc['flutter_icons']['includes'] != null) {
40+
includes = pubspecDoc['flutter_icons']['includes'];
41+
includes.forEach((key){
42+
yamlString += fontsMap[key];
43+
});
44+
}else{
45+
yamlString += allFonts;
46+
}
47+
flutterIconsFile.writeAsStringSync(yamlString);
5048
print(green.wrap("${DateTime.now()}: Finish the work"));
51-
5249
}

bin/temp.dart

+168
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,168 @@
1+
const String tempYaml = '''
2+
name: flutter_icons
3+
description: Customizable Icons for Flutter,you can use with over 3K+ icons in your flutter project
4+
version: 1.1.0
5+
author: flutter-studio<[email protected]>
6+
homepage: https://github.com/flutter-studio/flutter-icons.git
7+
8+
environment:
9+
sdk: ">=2.0.0-dev.68.0 <3.0.0"
10+
11+
dependencies:
12+
flutter:
13+
sdk: flutter
14+
15+
dev_dependencies:
16+
flutter_test:
17+
sdk: flutter
18+
19+
flutter:
20+
fonts:
21+
''';
22+
const String allFonts = '''
23+
- family: Ionicons
24+
fonts:
25+
- asset: fonts/Ionicons.ttf
26+
- family: AntDesign
27+
fonts:
28+
- asset: fonts/AntDesign.ttf
29+
- family: FontAwesome
30+
fonts:
31+
- asset: fonts/FontAwesome.ttf
32+
- family: MaterialIcons
33+
fonts:
34+
- asset: fonts/MaterialIcons.ttf
35+
- family: Entypo
36+
fonts:
37+
- asset: fonts/Entypo.ttf
38+
- family: EvilIcons
39+
fonts:
40+
- asset: fonts/EvilIcons.ttf
41+
- family: Feather
42+
fonts:
43+
- asset: fonts/Feather.ttf
44+
- family: Foundation
45+
fonts:
46+
- asset: fonts/Foundation.ttf
47+
- family: MaterialCommunityIcons
48+
fonts:
49+
- asset: fonts/MaterialCommunityIcons.ttf
50+
- family: Octicons
51+
fonts:
52+
- asset: fonts/Octicons.ttf
53+
- family: SimpleLineIcons
54+
fonts:
55+
- asset: fonts/SimpleLineIcons.ttf
56+
- family: Zocial
57+
fonts:
58+
- asset: fonts/Zocial.ttf
59+
- family: FontAwesome5
60+
fonts:
61+
- asset: fonts/FontAwesome5_Regular.ttf
62+
- family: FontAwesome5_Brands
63+
fonts:
64+
- asset: fonts/FontAwesome5_Brands.ttf
65+
- family: FontAwesome5_Solid
66+
fonts:
67+
- asset: fonts/FontAwesome5_Solid.ttf
68+
- family: WeatherIcons
69+
fonts:
70+
- asset: fonts/weathericons.ttf
71+
''';
72+
//Ant Design Icons -> ant,
73+
//Entypo Icons -> ent,
74+
//Evil Icons -> evi,
75+
//Feather Icons -> fea,
76+
//Font Awesome Icons -> faw,
77+
//Foundation Icons -> fou,
78+
//Ionicons Icons -> ion,
79+
//Material Community Icons -> mco,
80+
//Material Icons -> mdi,
81+
//Octicons Icons -> oct,
82+
//Simple Line Icons -> sli,
83+
//Zocial Icons -> zoc,
84+
//Weather Icons -> wea
85+
Map<String,String> fontsMap = {
86+
"ant":'''
87+
- family: AntDesign
88+
fonts:
89+
- asset: fonts/AntDesign.ttf
90+
''',
91+
"ion":"""
92+
- family: Ionicons
93+
fonts:
94+
- asset: fonts/Ionicons.ttf
95+
""",
96+
"faw":'''
97+
- family: FontAwesome
98+
fonts:
99+
- asset: fonts/FontAwesome.ttf
100+
''',
101+
"mdi":'''
102+
- family: MaterialIcons
103+
fonts:
104+
- asset: fonts/MaterialIcons.ttf
105+
''',
106+
"ent":'''
107+
- family: Entypo
108+
fonts:
109+
- asset: fonts/Entypo.ttf
110+
''',
111+
"evi":'''
112+
- family: EvilIcons
113+
fonts:
114+
- asset: fonts/EvilIcons.ttf
115+
''',
116+
"fea":'''
117+
- family: Feather
118+
fonts:
119+
- asset: fonts/Feather.ttf
120+
''',
121+
"fou":'''
122+
- family: Foundation
123+
fonts:
124+
- asset: fonts/Foundation.ttf
125+
''',
126+
"mco":'''
127+
- family: MaterialCommunityIcons
128+
fonts:
129+
- asset: fonts/MaterialCommunityIcons.ttf
130+
''',
131+
"oct":'''
132+
- family: Octicons
133+
fonts:
134+
- asset: fonts/Octicons.ttf
135+
''',
136+
"sli":'''
137+
- family: SimpleLineIcons
138+
fonts:
139+
- asset: fonts/SimpleLineIcons.ttf
140+
''',
141+
"zoc":'''
142+
- family: Zocial
143+
fonts:
144+
- asset: fonts/Zocial.ttf
145+
''',
146+
"faw5":'''
147+
- family: FontAwesome5
148+
fonts:
149+
- asset: fonts/FontAwesome5_Regular.ttf
150+
''',
151+
"faw5b":'''
152+
- family: FontAwesome5_Brands
153+
fonts:
154+
- asset: fonts/FontAwesome5_Brands.ttf
155+
''',
156+
"faw5s":'''
157+
- family: FontAwesome5_Solid
158+
fonts:
159+
- asset: fonts/FontAwesome5_Solid.ttf
160+
''',
161+
"wea":'''
162+
- family: WeatherIcons
163+
fonts:
164+
- asset: fonts/weathericons.ttf
165+
'''
166+
167+
168+
};

pubspec.yaml

+3
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,6 @@ dev_dependencies:
1414
pedantic: ^1.7.0
1515
test: ^1.5.0
1616
yaml: ^2.2.0
17+
18+
executables:
19+
split_icon:

0 commit comments

Comments
 (0)