Skip to content

Commit

Permalink
Add example placeholder
Browse files Browse the repository at this point in the history
  • Loading branch information
PlugFox committed Aug 4, 2023
1 parent 9de40ad commit 7e9b9c6
Show file tree
Hide file tree
Showing 43 changed files with 4,604 additions and 13 deletions.
4 changes: 2 additions & 2 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
"version": "0.2.0",
"configurations": [
{
"name": "Console (example)",
"name": "Example",
"request": "launch",
"type": "dart",
"program": "examples/console/bin/main.dart",
"program": "example",
"env": {
"ENVIRONMENT": "local"
},
Expand Down
69 changes: 69 additions & 0 deletions .vscode/tasks.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,75 @@
},
"problemMatcher": []
},
{
"label": "Get protoc plugin",
"type": "shell",
"command": ["dart pub global activate protoc_plugin"],
"dependsOn": ["Dependencies"],
"group": {
"kind": "none",
"isDefault": true
},
"problemMatcher": []
},
{
"label": "Generate protobuf",
"type": "shell",
"command": [
"protoc",
"--proto_path=lib/src/transport/protobuf",
"--dart_out=lib/src/transport/protobuf lib/src/transport/protobuf/client.proto"
],
"dependsOn": ["Get protoc plugin"],
"group": {
"kind": "none",
"isDefault": true
},
"problemMatcher": []
},
{
"label": "Codegenerate",
"type": "shell",
"command": ["dart run build_runner build --delete-conflicting-outputs"],
"dependsOn": ["Dependencies"],
"group": {
"kind": "none",
"isDefault": true
},
"problemMatcher": []
},
{
"label": "Format",
"type": "shell",
"command": [
"dart format --fix -l 80 lib/src/model/pubspec.yaml.g.dart lib/src/transport/protobuf/"
],
"group": {
"kind": "none",
"isDefault": true
},
"problemMatcher": []
},
{
"label": "Prepare example",
"type": "shell",
"options": {
"cwd": "${workspaceFolder}/example"
},
"command": [
"dart pub global activate intl_utils",
"dart pub global run intl_utils:generate",
"fvm flutter pub get",
/* "&& fvm flutter gen-l10n --arb-dir lib/src/common/localization --output-dir lib/src/common/localization/generated --template-arb-file intl_en.arb", */
"&& fvm flutter pub run build_runner build --delete-conflicting-outputs",
"&& dart format --fix -l 80 ."
],
"group": {
"kind": "none",
"isDefault": true
},
"problemMatcher": []
},
{
"label": "Start Centrifugo Server",
"type": "shell",
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ get:
test: get
@dart test --debug --coverage=.coverage --platform chrome,vm

publish:
publish: generate
@yes | dart pub publish

deploy: publish
Expand Down
70 changes: 70 additions & 0 deletions example/lib/src/common/constant/config.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
/// Config for app.
abstract final class Config {
/// Environment flavor.
/// e.g. development, staging, production
static final EnvironmentFlavor environment = EnvironmentFlavor.from(
const String.fromEnvironment('ENVIRONMENT', defaultValue: 'development'));

// --- Centrifuge --- //

/// Centrifuge url.
/// e.g. https://domain.tld
static const String centrifugeBaseUrl = String.fromEnvironment(
'CENTRIFUGE_BASE_URL',
defaultValue: 'http://127.0.0.1:8000');

/// Centrifuge timeout in milliseconds.
/// e.g. 15000 ms
static const Duration centrifugeTimeout = Duration(
milliseconds:
int.fromEnvironment('CENTRIFUGE_TIMEOUT', defaultValue: 15000));

/// Secret for HMAC token.
static const String passwordMinLength =
String.fromEnvironment('CENTRIFUGE_TOKEN_HMAC_SECRET');

// --- Layout --- //

/// Maximum screen layout width for screen with list view.
static const int maxScreenLayoutWidth =
int.fromEnvironment('MAX_LAYOUT_WIDTH', defaultValue: 768);
}

/// Environment flavor.
/// e.g. development, staging, production
enum EnvironmentFlavor {
/// Development
development('development'),

/// Staging
staging('staging'),

/// Production
production('production');

/// {@nodoc}
const EnvironmentFlavor(this.value);

/// {@nodoc}
factory EnvironmentFlavor.from(String? value) =>
switch (value?.trim().toLowerCase()) {
'development' || 'debug' || 'develop' || 'dev' => development,
'staging' || 'profile' || 'stage' || 'stg' => staging,
'production' || 'release' || 'prod' || 'prd' => production,
_ => const bool.fromEnvironment('dart.vm.product')
? production
: development,
};

/// development, staging, production
final String value;

/// Whether the environment is development.
bool get isDevelopment => this == development;

/// Whether the environment is staging.
bool get isStaging => this == staging;

/// Whether the environment is production.
bool get isProduction => this == production;
}
Loading

0 comments on commit 7e9b9c6

Please sign in to comment.