Skip to content
Open
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
14 changes: 14 additions & 0 deletions build.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
targets:
$default:
builders:
'environment_config:env_config_generator':
enabled: true


builders:
env_config_generator:
import: 'package:environment_config/builder.dart'
builder_factories: ["generateConfig"]
build_extensions:
'.yaml': ['.dart']
auto_apply: dependents
30 changes: 30 additions & 0 deletions example/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# Created by .ignore support plugin (hsz.mobi)
### Dart template
# See https://www.dartlang.org/guides/libraries/private-files

# Files and directories created by pub
.dart_tool/
.packages
build/
# If you're building an application, you may want to check-in your pubspec.lock
pubspec.lock

# Directory created by dartdoc
# If you don't generate documentation locally you can remove this line.
doc/api/

# Avoid committing generated Javascript files:
*.dart.js
*.info.json # Produced by the --dump-info flag.
*.js # When generated by dart2js. Don't specify *.js if your
# project includes source files written in JavaScript.
*.js_
*.js.deps
*.js.map

.flutter-plugins
.flutter-plugins-dependencies

!lib/generated
lib/generated/**
!**/.gitkeep
6 changes: 6 additions & 0 deletions example/build.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
targets:
$default:
builders:
'environment_config:env_config_generator':
options:
"--config-extension": "dev"
17 changes: 17 additions & 0 deletions example/environment_config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Config example. Run `flutter pub run environment_config:generate --env=YOUR_VALUE` to see example
environment_config:
path: generated/environment_config.dart
fields:
hello:

imports:
- dart:io

extensions:
dev:
fields:
hello:
default: 'Hello, Config!'

imports:
- dart:async
1 change: 1 addition & 0 deletions example/lib/example.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export 'package:environment_config_example/generated/environment_config.dart';
Empty file added example/lib/generated/.gitkeep
Empty file.
11 changes: 4 additions & 7 deletions example/main.dart
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
/// 1. Install your project dependencies
///
/// 2. Run `flutter pub run environment_config:generate` with key and values specified
/// in your YAML config
///
/// 3. Import generated file
import 'package:environment_config_example/example.dart';

import 'environment_config.dart';
void main() {
print(EnvironmentConfig.hello);
}
6 changes: 6 additions & 0 deletions example/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
name: environment_config_example

dev_dependencies:
build_runner: "^1.10.0"
environment_config:
path: ../
24 changes: 24 additions & 0 deletions lib/builder.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import 'dart:async';

import 'package:build/build.dart';
import 'package:environment_config/generator.dart' as gen;

Builder generateConfig(BuilderOptions builderOptions) =>
_GenerateConfig(builderOptions);

class _GenerateConfig extends Builder {
final List<String> arguments;

_GenerateConfig(BuilderOptions builderOptions)
: arguments = builderOptions.config.entries
.map((e) => e.value != null ? '${e.key}=${e.value}' : e.key)
.toList(growable: false);

@override
final buildExtensions = const {
'.yaml': ['.dart']
};

@override
Future<void> build(BuildStep buildStep) => gen.generateConfig(arguments);
}
36 changes: 32 additions & 4 deletions pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@ packages:
name: _fe_analyzer_shared
url: "https://pub.dartlang.org"
source: hosted
version: "1.0.1"
version: "7.0.0"
analyzer:
dependency: transitive
description:
name: analyzer
url: "https://pub.dartlang.org"
source: hosted
version: "0.39.2+1"
version: "0.39.17"
args:
dependency: "direct main"
description:
Expand All @@ -29,6 +29,13 @@ packages:
url: "https://pub.dartlang.org"
source: hosted
version: "2.4.1"
build:
dependency: "direct main"
description:
name: build
url: "https://pub.dartlang.org"
source: hosted
version: "1.3.0"
built_collection:
dependency: transitive
description:
Expand All @@ -50,6 +57,13 @@ packages:
url: "https://pub.dartlang.org"
source: hosted
version: "1.1.3"
cli_util:
dependency: transitive
description:
name: cli_util
url: "https://pub.dartlang.org"
source: hosted
version: "0.2.0"
code_builder:
dependency: "direct main"
description:
Expand Down Expand Up @@ -91,7 +105,7 @@ packages:
name: dart_style
url: "https://pub.dartlang.org"
source: hosted
version: "1.3.3"
version: "1.3.6"
fixnum:
dependency: transitive
description:
Expand Down Expand Up @@ -120,6 +134,13 @@ packages:
url: "https://pub.dartlang.org"
source: hosted
version: "0.6.1+1"
logging:
dependency: transitive
description:
name: logging
url: "https://pub.dartlang.org"
source: hosted
version: "0.11.4"
matcher:
dependency: transitive
description:
Expand Down Expand Up @@ -183,6 +204,13 @@ packages:
url: "https://pub.dartlang.org"
source: hosted
version: "2.1.3"
source_gen:
dependency: "direct main"
description:
name: source_gen
url: "https://pub.dartlang.org"
source: hosted
version: "0.9.5"
source_span:
dependency: transitive
description:
Expand Down Expand Up @@ -233,4 +261,4 @@ packages:
source: hosted
version: "2.2.0"
sdks:
dart: ">=2.3.0 <3.0.0"
dart: ">=2.7.0 <3.0.0"
19 changes: 2 additions & 17 deletions pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,20 +13,5 @@ dependencies:
code_builder: ">=3.0.0 <4.0.0"
args: ">=1.0.0 <2.0.0"
yaml: ">=2.0.0 <3.0.0"

# Config example. Run `flutter pub run environment_config:generate --env=YOUR_VALUE` to see example
environment_config:
fields:
env:

imports:
- some:package

extensions:
dev:
fields:
env:
default: some value

imports:
- other:package
build: ">=1.3.0"
source_gen: ">=0.9.5"