define_env 0.3.1 define_env: ^0.3.1 copied to clipboard
Load variables from a `.env` file into a dart-define string and copy it to your IDE Config or to the clipboard.
define_env #
Load variables from a .env
file into a dart-define 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
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
You can skip printing using the --no-print
flag
Copy to clipboard #
$ define_env -c # generate dart define string and copy 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
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
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
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
Env Validation #
You can add validation for your env by defining a define_env.yaml
or adding a define_env
section
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_values: # Defines the possible values of the enum. Required field when the type is enum.
- value1
- value2
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
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.