Skip to content

Commit

Permalink
feat: rework environment variables
Browse files Browse the repository at this point in the history
Use envied instead of dart_define.
  • Loading branch information
lishaduck committed Dec 11, 2023
1 parent 2f79a68 commit e440a61
Show file tree
Hide file tree
Showing 12 changed files with 81 additions and 109 deletions.
22 changes: 12 additions & 10 deletions .github/workflows/dart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -59,13 +59,14 @@ jobs:
path: |
.dart_tool/
lib/gen/*.gen.dart
lib/**/*.g.dart
lib/**/*.gr.dart
lib/**/*.gm.dart
lib/**/*.freezed.dart
lib/features/**/*.g.dart
lib/features/**/*.freezed.dart
lib/utils/*.g.dart
lib/utils/*.freezed.dart
lib/app/*.gr.dart
lib/app/*.gm.dart
lib/l10n/app_localizations.dart
lib/l10n/app_localizations_*.dart
lib/widgetbook.generator.*.dart
key: ${{ runner.os }}-${{ env.FLUTTER_CHANNEL }}-dart-${{ hashFiles('**/build.yaml') }}
- name: 🔌 Generate files
run: |
Expand All @@ -78,13 +79,14 @@ jobs:
name: generated-files
path: |
lib/gen/*.gen.dart
lib/**/*.g.dart
lib/**/*.gr.dart
lib/**/*.gm.dart
lib/**/*.freezed.dart
lib/features/**/*.g.dart
lib/features/**/*.freezed.dart
lib/utils/*.g.dart
lib/utils/*.freezed.dart
lib/app/*.gr.dart
lib/app/*.gm.dart
lib/l10n/app_localizations.dart
lib/l10n/app_localizations_*.dart
lib/widgetbook.generator.*.dart
if-no-files-found: error

build:
Expand Down
9 changes: 0 additions & 9 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,7 @@
"request": "launch",
"type": "dart",
"program": "lib/main.dart",
"args": ["--dart-define-from-file=dart_define.json"],
"flutterMode": "debug"
},
{
"name": "Launch widgetbook",
"request": "launch",
"type": "dart",
"program": "lib/widgetbook.generator.dart",
"args": ["--dart-define-from-file=dart_define.json"],
"flutterMode": "release"
}
]
}
2 changes: 1 addition & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@
"*.dart": "${capture}.*.dart, ${capture}_*.dart",
"*cspell.json": ".markdownlint*, project_words.txt, mlc_config.json",
".flutter-plugins": ".flutter-plugins-dependencies",
"dart_define.json": "*.log, untranslated.json",
"untranslated.json": "*.log",
".env": ".env.example",
"app.iml": "*.iml"
},
Expand Down
21 changes: 1 addition & 20 deletions .vscode/tasks.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,24 +20,7 @@
"color": "terminal.ansiCyan",
"id": "gear"
},
"dependsOn": ["Dart: run dart_define", "Flutter: gen-l10n"]
},
{
"type": "dart",
"command": "dart",
"cwd": ".",
"args": ["run", "dart_define", "generate"],
"problemMatcher": [],
"group": "build",
"label": "Dart: run dart_define",
"detail": "Generate dart-defines.",
"runOptions": {
"runOn": "folderOpen"
},
"icon": {
"color": "terminal.ansiMagenta",
"id": "gear"
}
"dependsOn": ["Flutter: gen-l10n"]
},
{
"type": "dart",
Expand All @@ -60,7 +43,6 @@
"build",
"${input:target}",
"--release",
"--dart-define-from-file=dart_define.json"
],
"problemMatcher": [],
"group": "build",
Expand Down Expand Up @@ -91,7 +73,6 @@
"build",
"${input:target}",
"--release",
"--dart-define-from-file=dart_define.json"
],
"problemMatcher": [],
"group": "build",
Expand Down
6 changes: 6 additions & 0 deletions build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -51,3 +51,9 @@ targets:
# configs for the packageVersion generator...
options:
output: lib/gen/version.gen.dart
envied_generator:envied:
# configs for the @Envied generator
generate_for:
- lib/env/env.dart
options:
output: lib/gen/env.g.dart
2 changes: 1 addition & 1 deletion doc/docker.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ docker run -it --rm --volume /var/run/docker.sock:/var/run/docker.sock --volume
| ---- | ------ | ---- | ----- | ------ |
| All |||||

1. Verify that `.env.example` was renamed to `.env`, and that `direnv` works.
1. Verify that `.env.example` was renamed to `.env`.
1. Run the "Dart: run build_runner" VS Code task.
1. Launch the app using the VS Code Run and Debug launcher.
1. See if the app works.
Expand Down
27 changes: 27 additions & 0 deletions lib/env/env.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import "package:envied/envied.dart";

part "env.g.dart";

/// Environment variables.
@Envied(useConstantCase: true)
abstract class Env {
/// Appwrite project ID
@EnviedField(defaultValue: "pirate-code")
static const String projectId = _Env.projectId;

/// Appwrite API endpoint
@EnviedField(defaultValue: "http://localhost:80/v1")
static const String apiEndpoint = _Env.apiEndpoint;

/// Appwrite database ID
@EnviedField(defaultValue: "pirate-coins")
static const String databaseId = _Env.databaseId;

/// Appwrite collection ID
@EnviedField(defaultValue: "coins")
static const String collectionId = _Env.collectionId;

/// If the Appwrite Server uses self-signed certificates.
@EnviedField(defaultValue: false)
static const bool selfSigned = _Env.selfSigned;
}
12 changes: 6 additions & 6 deletions lib/utils/api.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import "package:flutter/foundation.dart";
import "package:freezed_annotation/freezed_annotation.dart";
import "package:riverpod_annotation/riverpod_annotation.dart";

import "../dart_define.gen.dart";
import "../env/env.dart";

part "api.freezed.dart";
part "api.g.dart";
Expand Down Expand Up @@ -49,11 +49,11 @@ abstract interface class ApiRepository {

/// The Appwrite API information, gotten via passed in environment variables.
const ApiRepository apiInfo = Api(
projectId: DartDefine.projectId,
url: DartDefine.apiEndpoint,
databaseId: DartDefine.databaseId,
collectionId: DartDefine.collectionId,
isSelfSigned: DartDefine.selfSigned,
projectId: Env.projectId,
url: Env.apiEndpoint,
databaseId: Env.databaseId,
collectionId: Env.collectionId,
isSelfSigned: Env.selfSigned,
);

/// Get the Appwrite client.
Expand Down
6 changes: 1 addition & 5 deletions netlify.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
collections = [] # only needed for DecapCMS
media_folder = "" # unneeded, but required by the schema


[build]
# The relative path to the directory to be published
publish = "build/web"
Expand All @@ -16,17 +15,14 @@ command = """
&& flutter/bin/flutter pub get \
&& flutter/bin/flutter gen-l10n \
&& flutter/bin/cache/dart-sdk/bin/dart run build_runner build \
&& flutter/bin/cache/dart-sdk/bin/dart run dart_define generate \
&& flutter/bin/flutter build web --release --dart-define-from-file=dart_define.json
&& flutter/bin/flutter build web --release
"""


# The following redirect is intended for use with most SPAs
# that handle routing internally.
[[redirects]]
from = "/*"
status = 200
to = "/index.html"


[backend]
1 change: 0 additions & 1 deletion project_words.txt
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@ dartdoc
data
Decap
dhttpd
direnv
endtemplate
fullscreen
gbaccetta
Expand Down
56 changes: 24 additions & 32 deletions pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -257,14 +257,6 @@ packages:
url: "https://pub.dev"
source: hosted
version: "1.1.1"
cmd_plus:
dependency: transitive
description:
name: cmd_plus
sha256: "270ff868ef27cbb50fea7c43e782a68cf77de47a6d3516ac71654dde0e372f0a"
url: "https://pub.dev"
source: hosted
version: "1.3.3"
code_builder:
dependency: transitive
description:
Expand Down Expand Up @@ -353,14 +345,6 @@ packages:
url: "https://pub.dev"
source: hosted
version: "0.5.7"
dart_define:
dependency: "direct dev"
description:
name: dart_define
sha256: d8f7e28c252d625d4de4e3bbc7ba13cb974959561a1da384e65088d1b9a13d55
url: "https://pub.dev"
source: hosted
version: "2.1.1"
dart_style:
dependency: transitive
description:
Expand Down Expand Up @@ -401,6 +385,22 @@ packages:
url: "https://pub.dev"
source: hosted
version: "4.0.1"
envied:
dependency: "direct main"
description:
name: envied
sha256: c4af8bb99203d7f216cea41f2ec70874f9dd826b2a5782cdc5bd25389c5adcc1
url: "https://pub.dev"
source: hosted
version: "0.5.2"
envied_generator:
dependency: "direct dev"
description:
name: envied_generator
sha256: "637901d274db3974afb3919ca9ba2e1a97f110fd57350ac13a3adcd20ad7d530"
url: "https://pub.dev"
source: hosted
version: "0.5.2"
equatable:
dependency: transitive
description:
Expand Down Expand Up @@ -677,14 +677,6 @@ packages:
url: "https://pub.dev"
source: hosted
version: "0.1.2"
logger:
dependency: transitive
description:
name: logger
sha256: "7ad7215c15420a102ec687bb320a7312afd449bac63bfb1c60d9787c27b9767f"
url: "https://pub.dev"
source: hosted
version: "1.4.0"
logging:
dependency: transitive
description:
Expand All @@ -693,14 +685,6 @@ packages:
url: "https://pub.dev"
source: hosted
version: "1.2.0"
mankeli_core:
dependency: transitive
description:
name: mankeli_core
sha256: ac834e86c7d2c66686f1af95cea7d61d516fb56daa8eaec83e4ce31f8df3cbe3
url: "https://pub.dev"
source: hosted
version: "0.0.5"
mason:
dependency: transitive
description:
Expand Down Expand Up @@ -933,6 +917,14 @@ packages:
url: "https://pub.dev"
source: hosted
version: "1.2.3"
recase:
dependency: transitive
description:
name: recase
sha256: e4eb4ec2dcdee52dcf99cb4ceabaffc631d7424ee55e56f280bc039737f89213
url: "https://pub.dev"
source: hosted
version: "4.1.0"
riverpod:
dependency: transitive
description:
Expand Down
26 changes: 2 additions & 24 deletions pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ dependencies:
auto_size_text: ^3.0.0
build_version: ^2.1.1
cupertino_icons: 1.0.6 # Only required if you use Cupertino (iOS style) icons
envied: ^0.5.2
flutter:
sdk: flutter
flutter_hooks: 0.20.3
Expand All @@ -60,8 +61,8 @@ dev_dependencies:
build_runner: 2.4.7
build_web_compilers: 4.0.7
custom_lint: 0.5.7
dart_define: 2.1.1
dhttpd: 4.0.1
envied_generator: ^0.5.2
flutter_gen_runner: 5.3.2
flutter_launcher_icons: 0.13.1
flutter_native_splash: 2.3.8
Expand Down Expand Up @@ -115,29 +116,6 @@ flutter:
style: normal
weight: 400

dart_define:
variables:
- name: PROJECT_ID
description: Appwrite project ID
default: pirate-code
required: false
- name: API_ENDPOINT
description: Appwrite API endpoint
default: http://localhost:80/v1
required: false
- name: DATABASE_ID
description: Appwrite database ID
default: pirate-coins
required: false
- name: COLLECTION_ID
description: Appwrite collection ID
default: coins
required: false
- name: SELF_SIGNED
description: If the Appwrite Server uses self-signed certificates.
default: true
required: false

# dart run flutter_launcher_icons
flutter_launcher_icons:
image_path: "assets/icon/icon.png"
Expand Down

0 comments on commit e440a61

Please sign in to comment.