패키지, 저장소 및 앱 카테고리 검색

GitHub 저장소Nialixus/env_reader

env_reader

.env 파일에서 환경 변수를 읽거나 암호화하거나 생성하여 오브스쿠레이티드 Dart 모델에 넣습니다.

env_reader 프로젝트 이미지
스타
3
포크
2
최근 푸시(UTC)
2023. 12. 9.
프로젝트 상태
활성

원본 README

아래는 영문 원문 스냅샷입니다. 최신 내용은 GitHub에서 확인하세요.


Env Reader

Read, encrypt, or generate environment variables from .env file into an obfuscated Dart model.

Features 🚀

  • Automated Generation: Transform your .env files into dynamic Dart models directly. No need to add annotation. ✨
  • Seamless Integration: Directly update your pubspec.yaml and .gitignore on command. No need manual labor. 🛠️
  • Fortified Encryption: Shield your precious .env configurations with an encryption. Say no to prying eyes.🔒
  • Data Diversity Unleashed: Whether they're integers, decimals, booleans, or strings. Automatic interpretation is at your service. 🎮
  • Versatile Sourcing: Load your .env from various sources: assets, files, memory, network, and strings. The choice is yours. 🔄

Install 🚀

Get started with these quick commands:

🔥 Add env_reader to your pubspec.yaml with a single line:

dart pub add env_reader

✨ Unlock the magic by activating the env_reader CLI:

dart pub global activate env_reader

Usage 🚀

Now elevate your development experience with these straightforward steps:

1. Set up your configuration

Start by crafting your .env file in the root directory of your project, right alongside your trusty pubspec.yaml.

API_KEY=VYIUJ7tLdJFqrBesnOJEpkbceBB5GNz0t1aYgHxK3BMxbJOc/g==
DEBUG=true
PORT=8080
DATABASE_URL=postgresql://user:password@localhost:5432/mydb

2. Run the command (Optional)

Now, if you want to generate encrypted env file, run this command in your terminal:

env_reader --input=".env" --output="assets/env/" --key="MyOptionalSecretKey"

[!NOTE] output: .env successfully encrypted into assets/env/.env 🚀

also if you want to generate dart model from this env file, use tihs:

env_reader --input-".env" --model="lib/src/env_model.dart" --null-safety

[!NOTE] output: .env successfully generated into lib/src/env_model.dart 🎉


3. Loading your .env

Load the env_reader instance:

import 'package:env_reader/env_reader.dart';
import 'package:flutter/services.dart';

await Env.load(
  EnvStringLoader(await rootBundle.loadString('assets/env/.env')),
  "MyOptionalSecretKey");

// Or you can load by creating your own `EnvReader` instance.

EnvReader production = EnvReader();
await production.load(
  EnvStringLoader(await rootBundle.loadString('assets/env/.env')),
  "MyOptionalSecretKey");

4. Access your configuration

To get and read the value of your env:

import 'package:env_reader/env_reader.dart';
import 'package:my_package/src/env_model.dart';

String api = Env.read("API_KEY") ?? "Got'cha 😎";
bool debug = Env.read<bool>("DEBUG") ?? false;

// If you make your own instance, call it like this

String api = production.read("API_KEY") ?? "Got'cha 😎";
bool debug = production.read<bool>("DEBUG") ?? false;

Text(
  text:
    debug ? "🤫 pssst, this is my api key y'all \n\n $api" : "Nothing to see here 🤪",
);

// Or you can access the value directly from env generated model earlier

Text(
  text:
    EnvModel.debug ? "🤫 pssst, this is my api key y'all \n\n ${EnvModel.apiKey}" : "Nothing to see here 🤪",
);

Env Reader Command 🚀

Available commands:

Flag Description
-i, --input (mandatory) Input path of the .env file
-o, --output Output path for the encrypted .env file
-s, --key Secrey key for encryption & decryption
--model Generate dart model file to your desired file path
--null-safety Make the model null safety
--[no-]obfuscate Obfuscating generated values of model
(defaults to on)
--[no-]pubspec Insert asset path to pubspec.yaml
(defaults to on)
--[no-]gitignore Insert .env input & output file into .gitignore
(defaults to on)
-h, --help Print usage information

Example usage:

env_reader -i ".env" -o "assets/env/" -s "MyOptionalSecretKey" --model="lib/src/env_model.dart" --null-safety

Example 🚀

Nialixus GitHub avatar
GitHub 작성자

Nialixus ↗

언어Dart

분류

이 저장소가 배포한 패키지

사용 중인 의존성

의존성 목록 3 개

프로젝트에 맞는 저장소를 선택하려면?

사용 목적에 따라 검색하고 개발 활동을 비교한 뒤 원본 저장소에서 요구 사항을 확인하세요.

  1. 이름, 작성자 또는 설명으로 검색하고 기술 주제로 범위를 좁힙니다.
  2. 스타, 포크, 최근 푸시를 함께 비교하세요. 스타는 관심의 지표이며 품질을 보장하지 않습니다.
  3. 사용하기 전에 GitHub에서 README, 라이선스, Issues를 확인하세요.

출처 및 관리

“A repository is the most basic element of GitHub.”

GitHub Docs — About repositories ↗