Update language_color_generator
refactor code
generate const map
move to /tool directory
MODIFY
lib/src/const/language_color.dart
lib/src/const/language_color.dart
// GENERATED CODE - DO NOT MODIFY BY HAND
-// VERSION OF 2019-06-30T14:13:12.668020
+// VERSION OF 2019-07-09T09:46:59.065183
-Map<String, String> languagesColor = <String, String>{
+const languagesColor = <String, String>{
'1C Enterprise': '#814CCC',
'ABAP': '#E8274B',
'ABNF': '#000000',

DELETE
lib/src/tool/language_color_generator.dart
-import 'dart:io';
-
-import 'package:http/http.dart' as http;
-import 'package:yaml/yaml.dart';
-
-class LanguageColorGenerator {
- static final String indent = ' ';
- static final String path = './lib/src/const/language_color.dart';
- static final String url = 'https://raw.githubusercontent.com/'
- 'github/linguist/master/lib/linguist/languages.yml';
-
- static Future buildColorMap() async {
- http.Response response = await http.Client().get(url);
-
- YamlMap yaml = loadYaml(response.body) as YamlMap;
- StringBuffer stringBuffer = StringBuffer();
-
- stringBuffer.writeln('// GENERATED CODE - DO NOT MODIFY BY HAND');
- stringBuffer.writeln('// VERSION OF ${DateTime.now().toIso8601String()}');
- stringBuffer.writeln();
-
- stringBuffer
- .writeln('Map<String, String> languagesColor = <String, String>{');
-
- String color;
-
- YamlMap map = yaml.value;
- List<String> languages = List.from(map.keys);
- languages.sort();
-
- languages.forEach(
- (language) {
- color = map[language]['color']?.toString()?.toUpperCase() ?? '#000000';
-
- language = language.replaceAll("'", "\\'");
-
- stringBuffer.writeln("$indent'$language': '$color',");
- },
- );
-
- stringBuffer.writeln('};');
-
- File output = File(path);
-
- output.createSync();
- output.writeAsStringSync(stringBuffer.toString());
-
- print('File created with success');
- }
-}
-
-void main() {
- LanguageColorGenerator.buildColorMap();
-}

ADD
tool/language_color_generator.dart
+import 'dart:io';
+
+import 'package:http/http.dart' as http;
+import 'package:yaml/yaml.dart';
+
+const _indent = ' ';
+const _path = './lib/src/const/language_color.dart';
+const _url = 'https://raw.githubusercontent.com/'
+ 'github/linguist/master/lib/linguist/languages.yml';
+
+Future main() async {
+ var response = await http.Client().get(_url);
+
+ var yaml = loadYaml(response.body) as YamlMap;
+ var stringBuffer = StringBuffer()
+ ..writeln('// GENERATED CODE - DO NOT MODIFY BY HAND')
+ ..writeln('// VERSION OF ${DateTime.now().toIso8601String()}')
+ ..writeln()
+ ..writeln('const languagesColor = <String, String>{');
+
+ var map = yaml.value as YamlMap;
+ var languages = map.keys.cast<String>().toList(growable: false)..sort();
+
+ for (var language in languages) {
+ var color = map[language]['color']?.toString()?.toUpperCase() ?? '#000000';
+
+ language = language.replaceAll("'", "\\'");
+
+ stringBuffer.writeln("$_indent'$language': '$color',");
+ }
+
+ stringBuffer.writeln('};');
+
+ File(_path)
+ ..createSync()
+ ..writeAsStringSync(stringBuffer.toString());
+
+ print('File created with success');
+}

Update language_color_generator

- refactor code
- generate const map
- move to /tool directory