define_env

Creator: coderz1093

Last updated:

0 purchases

define_env Image
define_env Images

Languages

Categories

Add to Cart

Description:

define env

define_env #
Load variables from a .env file into a dart-define (also known as Environment declarations) string and copy it to your IDE Config or to the
clipboard.


Usage #
Get the latest version from pub:
$ dart pub global activate define_env
copied to clipboard
You can add the Pub Cache directory to execute the command easily.
Learn More
Print #
$ define_env # generate dart define string and print it to stdout
copied to clipboard
You can skip printing using the --no-print flag
Copy to clipboard #
$ define_env -c # generate dart define string and copy to clipboard
copied to clipboard
CI/CD #
You can generate and pass the dart define strings to your CI/CD pipeline.
To do this with doppler, you can do the following:
dartdefines=`doppler secrets download --format=env --no-file | define_env -f -`
flutter build apk $dartdefines
copied to clipboard
Copy to IDE #
Note

When copying to IDE config, define_env tries to preserve existing arguments and overwrites only
the dart-define statements. This is not thoroughly tested and if you face problems with additional
arguments please create an issue.

VS Code launch.json
$ define_env -l # generate dart define string and copy it to launch.json
copied to clipboard
By default, all configurations in launch.json are updated. If you want to update only a specific
configuration, you can do the following
$ define_env -l -n staging # generate dart define string and copy it to "staging" configuration in launch.json
copied to clipboard
Note

launch.json may sometimes contain comments. These comments cannot be preserved as of now. If
this is important then you should avoid this package

Android Studio
$ define_env -a # generate dart define string and copy it to all run configs
copied to clipboard
By default, all configurations in .idea/workspace.xml and .run/ are updated. If you want to
update only a specific configuration, you can do the following
$ define_env -a -n staging # generate dart define string and copy it to "staging" configuration only
copied to clipboard
Env Validation #
You can add validation for your env by defining a define_env.yaml or adding a define_envsection
to your pubspec.yaml
define_env:
file_path: example
class: MyEnv
fields:
<FIELD_NAME>:
type: enum # String | bool | int | enum
default: # If it is set the field in the env is optional.
enum: # Defines the possible values of the enum. Required field when the type is enum.
values:
- value1
- value2
copied to clipboard
Env Class Generation #
Running define_env will automatically generate an Env Class for you to use in your project. The
class name is defined by class and File Path is defined by file_path in define_env section of
your define_env.yaml or pubspec.yaml. If you don't want a class to be generated, you can pass
the --no-generate flag.
$ define_env --no-generate # Skip Env Class generation
copied to clipboard
Discussion #
Use the issue tracker for bug reports and feature requests.
Roadmap #

✅ Add support for Android Studio and Intellij.
✅ Add validation support to see warn if any environment variable is missing.
✅ Generate Config class from .env files which extract values from environment.
❌ Make Android Studio and VS Code extensions and plugins to update config automatically
when .env files are updated.
❌ Copy config name directly from .env files. ex .env.staging is copied to staging config.
❌ Simplify command usage. ex define_env:print define_env:copy define_env:vscode etc.
❌ Add Stdin support.
❌ Add support for config files created with melos

License

For personal and professional use. You cannot resell or redistribute these repositories in their original state.

Files In This Product:

Customer Reviews

There are no reviews.