diff --git a/CHANGELOG.md b/CHANGELOG.md index 0b43381..31654a5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,15 @@ +## 1.2.2 + +- Lists colorized, generated colors in terminal + + ``` + $ gator -c colors.yaml + Generated Material Color (0xff062091) Royal Blue + Generated Material Color (0xffd6d6d6) Grey + Generated Material Color (0xff663399) Rebecca Purple + 🖍 Created file: my_colors.g.dart! + ``` + ## 1.2.1 - Adds better error messages diff --git a/README.md b/README.md index 967d084..04da492 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -# 🎨 Gator +# 🖍 Gator Generate shades and tints from primary colors hex values for easy setup. diff --git a/example/README.md b/example/README.md index 41606c4..36f0796 100644 --- a/example/README.md +++ b/example/README.md @@ -15,7 +15,11 @@ gator: Run: ```sh -gator -c colors.yaml +$ gator -c colors.yaml +Generated Material Color (0xff062091) Royal Blue +Generated Material Color (0xffd6d6d6) Grey +Generated Material Color (0xff663399) Rebecca Purple +🖍 Created file: my_colors.g.dart! ``` Generates: @@ -23,57 +27,70 @@ Generates: ```dart import 'package:flutter/material.dart' show Color, MaterialColor; +/// **MyColors** +/// {@template gator_header} +/// *was generated by [gator](https://pub.dev/packages/gator).* +/// {@endtemplate} class MyColors { MyColors._(); - static const int _royalBluePrimaryValue = 0xff062091; + static const _royalBluePrimaryValue = 0xff062091; + + /// **Royal Blue** + /// {@macro gator_header} static const royalBlue = MaterialColor( _royalBluePrimaryValue, { - 050: Color(0xff122b97), - 100: Color(0xff1f369c), + 050: Color(0xff6a79bd), + 100: Color(0xff5163b2), 200: Color(0xff384da7), - 300: Color(0xff5163b2), - 400: Color(0xff6a79bd), + 300: Color(0xff1f369c), + 400: Color(0xff062091), 500: Color(_royalBluePrimaryValue), - 600: Color(0xff041357), - 700: Color(0xff041666), - 800: Color(0xff051a74), - 900: Color(0xff051d83), + 600: Color(0xff051d83), + 700: Color(0xff051a74), + 800: Color(0xff041666), + 900: Color(0xff041357), }, ); - static const int _greyPrimaryValue = 0xffd6d6d6; + static const _greyPrimaryValue = 0xffd6d6d6; + + /// **Grey** + /// {@macro gator_header} static const grey = MaterialColor( _greyPrimaryValue, { - 050: Color(0xffd8d8d8), - 100: Color(0xffdadada), + 050: Color(0xffe6e6e6), + 100: Color(0xffe2e2e2), 200: Color(0xffdedede), - 300: Color(0xffe2e2e2), - 400: Color(0xffe6e6e6), + 300: Color(0xffdadada), + 400: Color(0xffd6d6d6), 500: Color(_greyPrimaryValue), - 600: Color(0xff808080), - 700: Color(0xff969696), - 800: Color(0xffababab), - 900: Color(0xffc1c1c1), + 600: Color(0xffc1c1c1), + 700: Color(0xffababab), + 800: Color(0xff969696), + 900: Color(0xff808080), }, ); - static const int _rebeccaPurplePrimaryValue = 0xff663399; + static const _rebeccaPurplePrimaryValue = 0xff663399; + + /// **Rebecca Purple** + /// {@macro gator_header} static const rebeccaPurple = MaterialColor( _rebeccaPurplePrimaryValue, { - 050: Color(0xff6e3d9e), - 100: Color(0xff7547a3), + 050: Color(0xffa385c2), + 100: Color(0xff9470b8), 200: Color(0xff855cad), - 300: Color(0xff9470b8), - 400: Color(0xffa385c2), + 300: Color(0xff7547a3), + 400: Color(0xff663399), 500: Color(_rebeccaPurplePrimaryValue), - 600: Color(0xff3d1f5c), - 700: Color(0xff47246b), - 800: Color(0xff52297a), - 900: Color(0xff5c2e8a), + 600: Color(0xff5c2e8a), + 700: Color(0xff52297a), + 800: Color(0xff47246b), + 900: Color(0xff3d1f5c), }, ); } diff --git a/lib/commands/gator_command.dart b/lib/commands/gator_command.dart index 2f237d1..f2c9385 100644 --- a/lib/commands/gator_command.dart +++ b/lib/commands/gator_command.dart @@ -34,17 +34,15 @@ class GatorCommand extends Command { final configSource = _results['config'] as String; final resultsOutput = _results['output'] as String; - if (!File(configSource).existsSync()) { - throw FileSystemException('Cannot read file', configSource); - } - try { + if (!File(configSource).existsSync()) { + throw FileSystemException('Cannot read file', configSource); + } + final yaml = yamlDoc(configSource); final config = GatorConfig.fromYaml(yaml); final colors = createTintsAndShades(config.colors); - final _output = config.outputPath ?? resultsOutput; - final fields = _buildFieldsForColor(colors); final constructors = [Constructor((b) => b.name = '_')]; final directive = Directive( @@ -56,6 +54,12 @@ class GatorCommand extends Command { final generatedClass = Class( (b) => b + ..docs = ListBuilder( + [ + '/// **${config.className.pascalCase}**', + ..._header, + ], + ) ..constructors = ListBuilder(constructors) ..name = config.className.pascalCase ..fields = ListBuilder(fields), @@ -65,17 +69,15 @@ class GatorCommand extends Command { (b) => b ..body = ListBuilder([generatedClass]) ..directives = ListBuilder([directive]), - ); + ).accept(_emitter); - final generatedCode = _formatter.format( - '${library.accept(_emitter)}', - ); + final generatedCode = _formatter.format('$library'); File(_output) ..writeAsStringSync(generatedCode) ..createSync(recursive: true); - _logger.success('🎨 Generated $_output!'); + _logger.success('🖍 Created file: $_output!'); return 0; } on FileSystemException catch (e) { @@ -97,6 +99,7 @@ class GatorCommand extends Command { '050', '100', '200', '300', '400', // '500', '600', '700', '800', '900', ]; + colors.forEach( (configColor, shadeColors) { assert( @@ -129,6 +132,10 @@ class GatorCommand extends Command { final materialColorField = Field((b) { b + ..docs = ListBuilder([ + '/// **${configColor.name.titleCase}**', + '/// {@macro gator_header}', + ]) ..static = true ..modifier = FieldModifier.constant ..name = fieldName @@ -137,6 +144,15 @@ class GatorCommand extends Command { ); }); + final underlineName = styleUnderlined.wrap(fieldName.titleCase); + final colorizedHex = ansiColorizer( + color: configColor, + message: configColor.hex, + ); + _logger.info( + 'Generated Material Color ($colorizedHex) $underlineName', + ); + fields.addAll([primaryValueField, materialColorField]); }, ); @@ -150,4 +166,11 @@ class GatorCommand extends Command { @override String get name => 'gator'; + + // '/// {@macro gator_header}', + static const _header = [ + '/// {@template gator_header}', + '/// *was generated by [gator](https://pub.dev/packages/gator).*', + '/// {@endtemplate}', + ]; } diff --git a/lib/utils/ansi_colorizer.dart b/lib/utils/ansi_colorizer.dart new file mode 100644 index 0000000..ad08264 --- /dev/null +++ b/lib/utils/ansi_colorizer.dart @@ -0,0 +1,16 @@ +import 'package:ansicolor/ansicolor.dart'; +import 'package:gator/gator.dart'; + +/// Creates an ansi-compatable colored message from the color provided. +String ansiColorizer({ + required Color color, + required String message, +}) { + final pen = AnsiPen() + ..rgb( + r: color.red / 255, + g: color.green / 255, + b: color.blue / 255, + ); + return pen.write(message); +} diff --git a/lib/utils/utils.dart b/lib/utils/utils.dart index 3121008..5bf196b 100644 --- a/lib/utils/utils.dart +++ b/lib/utils/utils.dart @@ -1,3 +1,4 @@ +export 'ansi_colorizer.dart'; export 'asserts.dart'; export 'tinter_and_shader.dart'; export 'yaml_doc.dart'; diff --git a/pubspec.lock b/pubspec.lock index d5267f3..419790b 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -15,6 +15,13 @@ packages: url: "https://pub.dartlang.org" source: hosted version: "3.2.0" + ansicolor: + dependency: "direct main" + description: + name: ansicolor + url: "https://pub.dartlang.org" + source: hosted + version: "2.0.1" args: dependency: "direct main" description: diff --git a/pubspec.yaml b/pubspec.yaml index 24951f6..84e86af 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,12 +1,13 @@ name: gator -description: Generate shades and tints from primary colors hex values for easy setup. -version: 1.2.1 +description: Generate MaterialColor shades and tints from primary colors hex values for easy setup. +version: 1.2.2 repository: https://github.com/Luckey-Elijah/gator environment: sdk: '>=2.15.1 <3.0.0' dependencies: + ansicolor: ^2.0.1 args: ^2.3.0 built_collection: ^5.1.1 code_builder: ^4.1.0 @@ -24,4 +25,3 @@ dev_dependencies: executables: gator: -