Skip to content

Commit

Permalink
Some QoL updates
Browse files Browse the repository at this point in the history
  • Loading branch information
Luckey-Elijah committed Feb 12, 2022
1 parent 1878d8e commit f8b5dae
Show file tree
Hide file tree
Showing 8 changed files with 119 additions and 43 deletions.
12 changes: 12 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# 🎨 Gator
# 🖍 Gator

Generate shades and tints from primary colors hex values for easy setup.

Expand Down
73 changes: 45 additions & 28 deletions example/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,65 +15,82 @@ 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:
```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,
<int, Color>{
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,
<int, Color>{
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,
<int, Color>{
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),
},
);
}
Expand Down
45 changes: 34 additions & 11 deletions lib/commands/gator_command.dart
Original file line number Diff line number Diff line change
Expand Up @@ -34,17 +34,15 @@ class GatorCommand extends Command<int> {
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(
Expand All @@ -56,6 +54,12 @@ class GatorCommand extends Command<int> {

final generatedClass = Class(
(b) => b
..docs = ListBuilder<String>(
<String>[
'/// **${config.className.pascalCase}**',
..._header,
],
)
..constructors = ListBuilder<Constructor>(constructors)
..name = config.className.pascalCase
..fields = ListBuilder<Field>(fields),
Expand All @@ -65,17 +69,15 @@ class GatorCommand extends Command<int> {
(b) => b
..body = ListBuilder(<Spec>[generatedClass])
..directives = ListBuilder(<Directive>[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) {
Expand All @@ -97,6 +99,7 @@ class GatorCommand extends Command<int> {
'050', '100', '200', '300', '400', //
'500', '600', '700', '800', '900',
];

colors.forEach(
(configColor, shadeColors) {
assert(
Expand Down Expand Up @@ -129,6 +132,10 @@ class GatorCommand extends Command<int> {

final materialColorField = Field((b) {
b
..docs = ListBuilder<String>(<String>[
'/// **${configColor.name.titleCase}**',
'/// {@macro gator_header}',
])
..static = true
..modifier = FieldModifier.constant
..name = fieldName
Expand All @@ -137,6 +144,15 @@ class GatorCommand extends Command<int> {
);
});

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]);
},
);
Expand All @@ -150,4 +166,11 @@ class GatorCommand extends Command<int> {

@override
String get name => 'gator';

// '/// {@macro gator_header}',
static const _header = [
'/// {@template gator_header}',
'/// *was generated by [gator](https://pub.dev/packages/gator).*',
'/// {@endtemplate}',
];
}
16 changes: 16 additions & 0 deletions lib/utils/ansi_colorizer.dart
Original file line number Diff line number Diff line change
@@ -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);
}
1 change: 1 addition & 0 deletions lib/utils/utils.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
export 'ansi_colorizer.dart';
export 'asserts.dart';
export 'tinter_and_shader.dart';
export 'yaml_doc.dart';
7 changes: 7 additions & 0 deletions pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
6 changes: 3 additions & 3 deletions pubspec.yaml
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -24,4 +25,3 @@ dev_dependencies:

executables:
gator:

0 comments on commit f8b5dae

Please sign in to comment.