Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Update to have optional path #20

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion examples/envied_example/.env
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
KEY1=VALUE1
KEY2=VALUE2
KEY2=VALUE2
5 changes: 5 additions & 0 deletions examples/envied_example/.env.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
KEY1=DEBUG1
KEY2=DEBUG2
key3=DEBUG3
key4=1
key5=true
7 changes: 7 additions & 0 deletions examples/envied_example/build.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
targets:
$default:
builders:
envied_generator|envied:
options:
path: .env.test
override: true
2 changes: 1 addition & 1 deletion packages/envied_generator/lib/builder.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@ import 'package:source_gen/source_gen.dart';

/// Primary builder to build the generated code from the `EnviedGenerator`
Builder enviedBuilder(BuilderOptions options) =>
SharedPartBuilder([EnviedGenerator()], 'envied');
SharedPartBuilder([EnviedGenerator(options.config)], 'envied');
14 changes: 13 additions & 1 deletion packages/envied_generator/lib/src/generator.dart
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ import 'package:source_gen/source_gen.dart';
/// Will throw an [InvalidGenerationSourceError] if the annotated
/// element is not a [classElement].
class EnviedGenerator extends GeneratorForAnnotation<Envied> {
final Map<String, dynamic> _buildYamlConfigs;

EnviedGenerator(this._buildYamlConfigs);

@override
Future<String> generateForAnnotatedElement(
Element element,
Expand All @@ -28,8 +32,16 @@ class EnviedGenerator extends GeneratorForAnnotation<Envied> {
);
}

var path = annotation.read('path').literalValue as String?;
if (_buildYamlConfigs['override'] && _buildYamlConfigs['path'] != '') {
log.info('Taking options from config options');
path = _buildYamlConfigs['path'];
}

log.info(path);

final config = Envied(
path: annotation.read('path').literalValue as String?,
path: path,
requireEnvFile:
annotation.read('requireEnvFile').literalValue as bool? ?? false,
name: annotation.read('name').literalValue as String?,
Expand Down