@@ -2,6 +2,8 @@ import 'dart:io';
22import 'package:fontsource/api.dart' ;
33import 'package:yaml/yaml.dart' ;
44
5+ import '../utils.dart' ;
6+
57class FontConfig {
68 List <String > subsets;
79 List <int > weights;
@@ -16,12 +18,19 @@ class FontConfig {
1618 }
1719}
1820
19- typedef FontsourceConfig = Map <String , FontConfig >;
21+ class FontsourceConfig {
22+ Map <String , FontConfig > fonts;
23+ FontsourceConfig (this .fonts);
24+ @override
25+ String toString () {
26+ return '{fonts: $fonts }' ;
27+ }
28+ }
2029
2130Future <FontsourceConfig > getConfig () async {
2231 dynamic configYaml;
2332 try {
24- File fontsourceFile = File ('fontsource.yaml' );
33+ File fontsourceFile = File (cwdJoin ( 'fontsource.yaml' ) );
2534 if (fontsourceFile.existsSync ()) {
2635 String fontsourceFileString = fontsourceFile.readAsStringSync ();
2736
@@ -30,7 +39,7 @@ Future<FontsourceConfig> getConfig() async {
3039 }
3140 }
3241 if (configYaml == null ) {
33- File pubspecFile = File ('pubspec.yaml' );
42+ File pubspecFile = File (cwdJoin ( 'pubspec.yaml' ) );
3443
3544 if (pubspecFile.existsSync ()) {
3645 dynamic pubspecYaml = loadYaml (pubspecFile.readAsStringSync ());
@@ -45,9 +54,10 @@ Future<FontsourceConfig> getConfig() async {
4554 throw Exception ('Fontsource config not found.' );
4655 }
4756
48- Map configDynamicMap = configYaml;
49- FontsourceConfig config = {};
50- await Future .wait (configDynamicMap.keys.map ((id) async {
57+ Map configMap = configYaml;
58+ Map fontsMap = configMap['fonts' ] ?? {};
59+ final config = FontsourceConfig ({});
60+ await Future .wait (fontsMap.keys.map ((id) async {
5161 FontMetadata metadata;
5262 try {
5363 metadata = (await listFontMetadata (id: id))[0 ];
@@ -58,11 +68,10 @@ Future<FontsourceConfig> getConfig() async {
5868 List <String > subsets;
5969 List <int > weights;
6070 List <String > styles;
61- if (configDynamicMap[id]? ['subsets' ] == null ||
62- configDynamicMap[id]['subsets' ] == 'all' ) {
71+ if (fontsMap[id]? ['subsets' ] == null || fontsMap[id]['subsets' ] == 'all' ) {
6372 subsets = metadata.subsets;
6473 } else {
65- subsets = (configDynamicMap [id]['subsets' ] as YamlList )
74+ subsets = (fontsMap [id]['subsets' ] as YamlList )
6675 .map ((subset) => subset as String )
6776 .toList ();
6877 for (var subset in subsets) {
@@ -72,11 +81,10 @@ Future<FontsourceConfig> getConfig() async {
7281 }
7382 }
7483 }
75- if (configDynamicMap[id]? ['weights' ] == null ||
76- configDynamicMap[id]['weights' ] == 'all' ) {
84+ if (fontsMap[id]? ['weights' ] == null || fontsMap[id]['weights' ] == 'all' ) {
7785 weights = metadata.weights;
7886 } else {
79- weights = (configDynamicMap [id]['weights' ] as YamlList )
87+ weights = (fontsMap [id]['weights' ] as YamlList )
8088 .map ((weight) => weight as int )
8189 .toList ();
8290 for (var weight in weights) {
@@ -86,11 +94,10 @@ Future<FontsourceConfig> getConfig() async {
8694 }
8795 }
8896 }
89- if (configDynamicMap[id]? ['weights' ] == null ||
90- configDynamicMap[id]['styles' ] == 'all' ) {
97+ if (fontsMap[id]? ['weights' ] == null || fontsMap[id]['styles' ] == 'all' ) {
9198 styles = metadata.styles;
9299 } else {
93- styles = (configDynamicMap [id]['styles' ] as YamlList )
100+ styles = (fontsMap [id]['styles' ] as YamlList )
94101 .map ((style) => style as String )
95102 .toList ();
96103 for (var style in styles) {
@@ -99,10 +106,10 @@ Future<FontsourceConfig> getConfig() async {
99106 }
100107 }
101108 }
102- String ? version = configDynamicMap [id]? ['version' ];
109+ String ? version = fontsMap [id]? ['version' ];
103110 if (version == 'latest' ) version = null ;
104- config[id] = FontConfig (
105- subsets, weights, styles, metadata, configDynamicMap [id]? ['version' ]);
111+ config.fonts [id] = FontConfig (
112+ subsets, weights, styles, metadata, fontsMap [id]? ['version' ]);
106113 }));
107114
108115 return config;
0 commit comments