-
Notifications
You must be signed in to change notification settings - Fork 38
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: optional path build.yaml option (#83)
* Update to have optional path * 🔀 resolve merge conflicts * ♻️ refactor code * ♻️ refactor code * ✅ add path override tests * ✅ add path override tests * 📝 update readme --------- Co-authored-by: Marcel Ploch <[email protected]>
- Loading branch information
Showing
7 changed files
with
120 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
/// Represents the options passed to the build runner via build.yaml. | ||
/// | ||
/// For example | ||
/// | ||
/// ```yaml | ||
/// targets: | ||
/// $default: | ||
/// builders: | ||
/// envied_generator|envied: | ||
/// options: | ||
/// path: .env.test | ||
/// override: true | ||
/// ``` | ||
class BuildOptions { | ||
const BuildOptions({ | ||
this.override, | ||
this.path, | ||
}); | ||
|
||
final String? path; | ||
final bool? override; | ||
|
||
factory BuildOptions.fromMap(Map<String, dynamic> map) => BuildOptions( | ||
override: map['override'] as bool?, | ||
path: map['path'] as String?, | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 2 additions & 0 deletions
2
packages/envied_generator/test/.env.example_with_path_override
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
foo=bar | ||
baz=qux |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,33 @@ | ||
import 'package:envied_generator/envied_generator.dart'; | ||
import 'package:envied_generator/src/build_options.dart'; | ||
import 'package:source_gen_test/source_gen_test.dart'; | ||
|
||
Future<void> main() async { | ||
// for annotated elements | ||
initializeBuildLogTracking(); | ||
final reader = await initializeLibraryReaderForDirectory( | ||
'test/src', | ||
'generator_tests.dart', | ||
); | ||
|
||
// print(Platform.environment['SYSTEM_VAR']); | ||
|
||
testAnnotatedElements( | ||
reader, | ||
EnviedGenerator(), | ||
await initializeLibraryReaderForDirectory( | ||
'test/src', | ||
'generator_tests.dart', | ||
), | ||
EnviedGenerator( | ||
const BuildOptions(), | ||
), | ||
); | ||
|
||
testAnnotatedElements( | ||
await initializeLibraryReaderForDirectory( | ||
'test/src', | ||
'generator_tests_with_path_override.dart', | ||
), | ||
EnviedGenerator( | ||
const BuildOptions( | ||
path: 'test/.env.example_with_path_override', | ||
override: true, | ||
), | ||
), | ||
); | ||
} |
37 changes: 37 additions & 0 deletions
37
packages/envied_generator/test/src/generator_tests_with_path_override.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
// ignore_for_file: unnecessary_nullable_for_final_variable_declarations | ||
|
||
import 'package:envied/envied.dart'; | ||
import 'package:source_gen_test/annotations.dart'; | ||
|
||
@ShouldGenerate(''' | ||
// coverage:ignore-file | ||
// ignore_for_file: type=lint | ||
final class _EnvWithPathOverride0 {} | ||
''') | ||
@Envied() | ||
abstract class EnvWithPathOverride0 {} | ||
|
||
@ShouldGenerate(''' | ||
// coverage:ignore-file | ||
// ignore_for_file: type=lint | ||
final class _EnvWithPathOverride1 {} | ||
''') | ||
@Envied(requireEnvFile: true) | ||
abstract class EnvWithPathOverride1 {} | ||
|
||
@ShouldGenerate(''' | ||
// coverage:ignore-file | ||
// ignore_for_file: type=lint | ||
final class _EnvWithPathOverride2 { | ||
static const String foo = 'bar'; | ||
static const String baz = 'qux'; | ||
} | ||
''') | ||
@Envied() | ||
abstract class EnvWithPathOverride2 { | ||
@EnviedField() | ||
static const String? foo = null; | ||
@EnviedField() | ||
static const String? baz = null; | ||
} |