Skip to content

Commit

Permalink
Add dart-define-from-file build arg example
Browse files Browse the repository at this point in the history
  • Loading branch information
lijy91 committed Nov 26, 2023
1 parent b7beaf8 commit 694cec2
Show file tree
Hide file tree
Showing 9 changed files with 41 additions and 30 deletions.
6 changes: 4 additions & 2 deletions examples/hello_world/distribute_options.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
output: dist/
variables:
FLUTTER_ROOT: ~/fvm/versions/3.10.0
FLUTTER_ROOT: ~/fvm/versions/3.10.3
# PGYER_API_KEY: your api key
releases:
- name: dev-profile
Expand Down Expand Up @@ -79,7 +79,7 @@ releases:
jobs:
- name: android-aab
variables:
FLUTTER_ROOT: ~/fvm/versions/3.10.2
FLUTTER_ROOT: ~/fvm/versions/3.10.3
package:
platform: android
target: aab
Expand Down Expand Up @@ -113,6 +113,8 @@ releases:
package:
platform: macos
target: dmg
build_args:
dart-define-from-file: env.json
- name: macos-pkg
package:
platform: macos
Expand Down
3 changes: 3 additions & 0 deletions examples/hello_world/env.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"APP_ENV": "dev"
}
8 changes: 8 additions & 0 deletions examples/hello_world/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,10 @@ class MyHomePage extends StatefulWidget {
class _MyHomePageState extends State<MyHomePage> {
int _counter = 0;

String get _appEnv {
return const String.fromEnvironment('APP_ENV');
}

String get _buildName {
return const String.fromEnvironment('FLUTTER_BUILD_NAME');
}
Expand Down Expand Up @@ -110,6 +114,10 @@ class _MyHomePageState extends State<MyHomePage> {
'$_counter',
style: Theme.of(context).textTheme.headlineMedium,
),
Text(
'APP_ENV: $_appEnv',
style: Theme.of(context).textTheme.bodyMedium,
),
Text(
'FLUTTER_BUILD_NAME: $_buildName',
style: Theme.of(context).textTheme.bodyMedium,
Expand Down
8 changes: 4 additions & 4 deletions examples/hello_world/pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,10 @@ packages:
dependency: "direct main"
description:
name: cupertino_icons
sha256: e35129dc44c9118cee2a5603506d823bab99c68393879edb440e0090d07586be
sha256: d57953e10f9f8327ce64a508a355f0b1ec902193f66288e8cb5070e7c47eeb2d
url: "https://pub.dev"
source: hosted
version: "1.0.5"
version: "1.0.6"
fake_async:
dependency: transitive
description:
Expand All @@ -66,10 +66,10 @@ packages:
dependency: "direct dev"
description:
name: flutter_lints
sha256: aeb0b80a8b3709709c9cc496cdc027c5b3216796bc0af0ce1007eaf24464fd4c
sha256: a25a15ebbdfc33ab1cd26c63a6ee519df92338a9c10f122adda92938253bef04
url: "https://pub.dev"
source: hosted
version: "2.0.1"
version: "2.0.3"
flutter_test:
dependency: "direct dev"
description: flutter
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ abstract class AppBuilder {
);

if (processResult.exitCode != 0) {
throw BuildError();
throw BuildError('${processResult.stderr}');
}

return resultResolver.resolve(config)..duration = time.elapsed;
Expand Down
8 changes: 7 additions & 1 deletion packages/flutter_app_builder/lib/src/commands/flutter.dart
Original file line number Diff line number Diff line change
Expand Up @@ -56,14 +56,20 @@ class _Flutter extends Command {
String flutterRoot = environment?['FLUTTER_ROOT'] ?? '';
if (flutterRoot.isNotEmpty) {
flutterRoot = pathExpansion(flutterRoot, environment ?? {});
if (!Directory(flutterRoot).existsSync()) {
throw CommandError(
this,
'FLUTTER_ROOT environment variable is set to a path that does not exist: $flutterRoot',
);
}
return p.join(flutterRoot, 'bin', 'flutter');
}
return 'flutter';
}

Map<String, String>? environment;

withEnv(Map<String, String>? environment) {
_Flutter withEnv(Map<String, String>? environment) {
this.environment = environment;
return this;
}
Expand Down
1 change: 1 addition & 0 deletions packages/shell_executor/lib/shell_executor.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
library shell_executor;

export 'src/command.dart';
export 'src/command_error.dart';
export 'src/shell_executor.dart';
export 'src/utils/path_expansion.dart';
22 changes: 0 additions & 22 deletions packages/shell_executor/lib/src/command.dart
Original file line number Diff line number Diff line change
Expand Up @@ -30,26 +30,4 @@ abstract class Command {
runInShell: runInShell,
);
}

Future<ProcessResult> run(
List<String> arguments, {
Map<String, String>? environment,
}) {
return exec(
arguments,
environment: environment,
);
}

ProcessResult runSync(
List<String> arguments, {
Map<String, String>? environment,
bool runInShell = false,
}) {
return execSync(
arguments,
environment: environment,
runInShell: runInShell,
);
}
}
13 changes: 13 additions & 0 deletions packages/shell_executor/lib/src/command_error.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import 'package:shell_executor/src/command.dart';

class CommandError extends Error {
CommandError(this.command, [this.message]);

final Command command;
final String? message;

@override
String toString() {
return (message != null) ? 'CommandError: $message' : 'CommandError';
}
}

0 comments on commit 694cec2

Please sign in to comment.