Skip to content

Commit 4d55491

Browse files
authored
Merge branch 'main' into Add-lint-package
2 parents 513d9d8 + ec77e97 commit 4d55491

File tree

69 files changed

+25923
-1585
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

69 files changed

+25923
-1585
lines changed

.github/workflows/dart_frog_new.yaml

-1
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,5 @@ jobs:
1616
build:
1717
uses: VeryGoodOpenSource/very_good_workflows/.github/workflows/dart_package.yml@v1
1818
with:
19-
runs_on: macos-latest
2019
working_directory: bricks/dart_frog_new/hooks
2120
analyze_directories: .

.github/workflows/dart_frog_prod_server.yaml

-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ jobs:
1616
build:
1717
uses: VeryGoodOpenSource/very_good_workflows/.github/workflows/dart_package.yml@v1
1818
with:
19-
runs_on: macos-latest
2019
working_directory: bricks/dart_frog_prod_server/hooks
2120
analyze_directories: .
2221
report_on: "pre_gen.dart,post_gen.dart"

bricks/create_dart_frog/__brick__/analysis_options.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
include: package:very_good_analysis/analysis_options.4.0.0.yaml
1+
include: package:very_good_analysis/analysis_options.5.0.0.yaml
22
analyzer:
33
exclude:
44
- build/**

bricks/create_dart_frog/__brick__/pubspec.yaml

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,12 @@ version: 1.0.0+1
44
publish_to: none
55

66
environment:
7-
sdk: ">=2.19.0 <3.0.0"
7+
sdk: ">=3.0.0 <4.0.0"
88

99
dependencies:
1010
dart_frog: ^0.3.0
1111

1212
dev_dependencies:
1313
mocktail: ^0.3.0
1414
test: ^1.19.2
15-
very_good_analysis: ^4.0.0
15+
very_good_analysis: ^5.0.0
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
include: package:very_good_analysis/analysis_options.4.0.0.yaml
1+
include: package:very_good_analysis/analysis_options.5.0.0.yaml
+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name: create_dart_frog_hooks
22

33
environment:
4-
sdk: ">=2.19.0 <3.0.0"
4+
sdk: ">=3.0.0 <4.0.0"
55

66
dependencies:
77
mason: ^0.1.0-dev.39
@@ -10,4 +10,4 @@ dependencies:
1010
dev_dependencies:
1111
mocktail: ^0.3.0
1212
test: ^1.19.2
13-
very_good_analysis: ^4.0.0
13+
very_good_analysis: ^5.0.0
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
include: package:very_good_analysis/analysis_options.4.0.0.yaml
1+
include: package:very_good_analysis/analysis_options.5.0.0.yaml

bricks/dart_frog_dev_server/hooks/pubspec.yaml

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ name: dart_frog_dev_server_hooks
22
publish_to: none
33

44
environment:
5-
sdk: ">=2.19.0 <3.0.0"
5+
sdk: ">=3.0.0 <4.0.0"
66

77
dependencies:
88
dart_frog_gen: ^0.4.0
@@ -13,4 +13,4 @@ dev_dependencies:
1313
mocktail: ^0.3.0
1414
path: ^1.8.2
1515
test: ^1.19.2
16-
very_good_analysis: ^4.0.0
16+
very_good_analysis: ^5.0.0

bricks/dart_frog_new/hooks/analysis_options.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
include: package:very_good_analysis/analysis_options.4.0.0.yaml
1+
include: package:very_good_analysis/analysis_options.5.0.0.yaml
22

33
linter:
44
rules:

bricks/dart_frog_new/hooks/pubspec.yaml

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ name: dart_frog_new_hooks
22
publish_to: none
33

44
environment:
5-
sdk: ">=2.19.0 <3.0.0"
5+
sdk: ">=3.0.0 <4.0.0"
66

77
dependencies:
88
dart_frog_gen: ^0.4.0
@@ -12,4 +12,4 @@ dependencies:
1212
dev_dependencies:
1313
mocktail: ^0.3.0
1414
test: ^1.19.2
15-
very_good_analysis: ^4.0.0
15+
very_good_analysis: ^5.0.0

bricks/dart_frog_prod_server/__brick__/build/Dockerfile

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Official Dart image: https://hub.docker.com/_/dart
22
# Specify the Dart SDK base image version using dart:<version> (ex: dart:2.17)
3-
FROM dart:stable AS build
3+
FROM dart:{{dartVersion}} AS build
44

55
WORKDIR /app
66

@@ -28,4 +28,4 @@ COPY --from=build /app/bin/server /app/bin/
2828
{{#serveStaticFiles}}COPY --from=build /app/public /public/{{/serveStaticFiles}}
2929

3030
# Start server.
31-
CMD ["/app/bin/server"]
31+
CMD ["/app/bin/server"]

bricks/dart_frog_prod_server/brick.yaml

+7
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,10 @@ version: 0.1.0+1
44

55
environment:
66
mason: ">=0.1.0-dev <0.1.0"
7+
8+
vars:
9+
dartVersion:
10+
type: string
11+
description: Dart version to be used in the generated Dockerfile.
12+
default: stable
13+
prompt: Dart version?
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
include: package:very_good_analysis/analysis_options.4.0.0.yaml
1+
include: package:very_good_analysis/analysis_options.5.0.0.yaml

bricks/dart_frog_prod_server/hooks/pre_gen.dart

+1
Original file line numberDiff line numberDiff line change
@@ -93,5 +93,6 @@ Future<void> preGen(
9393
'invokeCustomEntrypoint': configuration.invokeCustomEntrypoint,
9494
'invokeCustomInit': configuration.invokeCustomInit,
9595
'pathDependencies': await getPathDependencies(projectDirectory),
96+
'dartVersion': context.vars['dartVersion'],
9697
};
9798
}

bricks/dart_frog_prod_server/hooks/pubspec.yaml

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ name: dart_frog_prod_server_hooks
22
publish_to: none
33

44
environment:
5-
sdk: ">=2.19.0 <3.0.0"
5+
sdk: ">=3.0.0 <4.0.0"
66

77
dependencies:
88
dart_frog_gen: ^0.4.0
@@ -14,4 +14,4 @@ dependencies:
1414
dev_dependencies:
1515
mocktail: ^0.3.0
1616
test: ^1.19.2
17-
very_good_analysis: ^4.0.0
17+
very_good_analysis: ^5.0.0

bricks/dart_frog_prod_server/hooks/test/post_gen_test.dart

+10-5
Original file line numberDiff line numberDiff line change
@@ -30,13 +30,19 @@ class _MockLogger extends Mock implements Logger {}
3030

3131
class _MockProgress extends Mock implements Progress {}
3232

33-
class _MockProcessResult extends Mock implements ProcessResult {}
34-
3533
void main() {
3634
group('postGen', () {
3735
late HookContext context;
3836
late Logger logger;
3937

38+
const processId = 42;
39+
final processResult = ProcessResult(
40+
processId,
41+
ExitCode.success.code,
42+
'',
43+
'',
44+
);
45+
4046
setUp(() {
4147
logger = _MockLogger();
4248
context = _FakeHookContext(logger: logger);
@@ -57,8 +63,7 @@ void main() {
5763
test('runs dart pub get and outputs next steps', () async {
5864
var processRunnerCallCount = 0;
5965
final exitCalls = <int>[];
60-
final result = _MockProcessResult();
61-
when(() => result.exitCode).thenReturn(ExitCode.success.code);
66+
6267
await postGen(
6368
context,
6469
runProcess: (
@@ -75,7 +80,7 @@ void main() {
7580
equals(path.join(Directory.current.path, 'build')),
7681
);
7782
expect(runInShell, isTrue);
78-
return result;
83+
return processResult;
7984
},
8085
exit: exitCalls.add,
8186
);

bricks/dart_frog_prod_server/hooks/test/pre_gen_test.dart

+7-3
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,8 @@ void main() {
3838

3939
setUp(() {
4040
logger = _MockLogger();
41-
context = _FakeHookContext(logger: logger);
41+
context = _FakeHookContext(logger: logger)
42+
..vars['dartVersion'] = 'stable';
4243

4344
when(() => logger.progress(any())).thenReturn(_MockProgress());
4445
});
@@ -217,7 +218,8 @@ dev_dependencies:
217218
'serveStaticFiles': false,
218219
'invokeCustomEntrypoint': true,
219220
'invokeCustomInit': false,
220-
'pathDependencies': <String>[]
221+
'pathDependencies': <String>[],
222+
'dartVersion': 'stable',
221223
}),
222224
);
223225
});
@@ -249,7 +251,8 @@ dev_dependencies:
249251
'serveStaticFiles': false,
250252
'invokeCustomEntrypoint': false,
251253
'invokeCustomInit': true,
252-
'pathDependencies': <String>[]
254+
'pathDependencies': <String>[],
255+
'dartVersion': 'stable',
253256
}),
254257
);
255258
});
@@ -383,6 +386,7 @@ dev_dependencies:
383386
'invokeCustomEntrypoint': false,
384387
'invokeCustomInit': false,
385388
'pathDependencies': <String>[],
389+
'dartVersion': 'stable',
386390
}),
387391
);
388392
},

bricks/dart_frog_prod_server/hooks/test/src/dart_pub_get_test.dart

+27-17
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,19 @@ class _MockLogger extends Mock implements Logger {}
2727

2828
class _MockProgress extends Mock implements Progress {}
2929

30-
class _MockProcessResult extends Mock implements ProcessResult {}
31-
3230
void main() {
3331
group('dartPubGet', () {
3432
late HookContext context;
3533
late Logger logger;
3634

35+
const processId = 42;
36+
final processResult = ProcessResult(
37+
processId,
38+
ExitCode.success.code,
39+
'',
40+
'',
41+
);
42+
3743
setUp(() {
3844
logger = _MockLogger();
3945
context = _FakeHookContext(logger: logger);
@@ -43,8 +49,7 @@ void main() {
4349

4450
test('completes when process succeeds', () async {
4551
final exitCalls = <int>[];
46-
final result = _MockProcessResult();
47-
when(() => result.exitCode).thenReturn(ExitCode.success.code);
52+
4853
await dartPubGet(
4954
context,
5055
workingDirectory: '.',
@@ -58,7 +63,7 @@ void main() {
5863
expect(args, equals(['pub', 'get']));
5964
expect(workingDirectory, equals('.'));
6065
expect(runInShell, isTrue);
61-
return result;
66+
return processResult;
6267
},
6368
exit: exitCalls.add,
6469
);
@@ -69,10 +74,14 @@ void main() {
6974
test('exits when process fails', () async {
7075
const error = 'oops something went wrong';
7176
final exitCalls = <int>[];
72-
final result = _MockProcessResult();
73-
final code = ExitCode.software.code;
74-
when(() => result.exitCode).thenReturn(code);
75-
when(() => result.stderr).thenReturn(error);
77+
78+
final processResult = ProcessResult(
79+
processId,
80+
ExitCode.software.code,
81+
'',
82+
error,
83+
);
84+
7685
await dartPubGet(
7786
context,
7887
workingDirectory: '.',
@@ -82,21 +91,17 @@ void main() {
8291
String? workingDirectory,
8392
bool? runInShell,
8493
}) async {
85-
return result;
94+
return processResult;
8695
},
8796
exit: exitCalls.add,
8897
);
89-
expect(exitCalls, equals([code]));
98+
expect(exitCalls, equals([ExitCode.software.code]));
9099
verify(() => logger.err(error)).called(1);
91100
});
92101

93102
test('exits when ProcessException occurs', () async {
94103
const error = 'oops something went wrong';
95104
final exitCalls = <int>[];
96-
final result = _MockProcessResult();
97-
final code = ExitCode.software.code;
98-
when(() => result.exitCode).thenReturn(code);
99-
when(() => result.stderr).thenReturn(error);
100105
await dartPubGet(
101106
context,
102107
workingDirectory: '.',
@@ -106,11 +111,16 @@ void main() {
106111
String? workingDirectory,
107112
bool? runInShell,
108113
}) async {
109-
throw ProcessException('dart', ['pub', 'get'], error, code);
114+
throw ProcessException(
115+
'dart',
116+
['pub', 'get'],
117+
error,
118+
ExitCode.software.code,
119+
);
110120
},
111121
exit: exitCalls.add,
112122
);
113-
expect(exitCalls, equals([code]));
123+
expect(exitCalls, equals([ExitCode.software.code]));
114124
verify(() => logger.err(error)).called(1);
115125
});
116126
});

docs/docs/basics/environments.md

+55
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
---
2+
sidebar_position: 7
3+
title: 🌱 Environments
4+
---
5+
6+
# Environments 🌱
7+
8+
There are many ways that environments can be configured in a Dart Frog application. The
9+
easiest way is to use environment variables via the Dart SDK.
10+
11+
As seen in the [dependency injection docs](dependency-injection.md), middleware can be used to provide dependencies to an application.
12+
13+
Following this approach, the snippet shows how a database client can be configured with different environments.
14+
15+
```dart
16+
Handler middleware(Handler handler) {
17+
return handler
18+
.use(provider<CardsRepository>((_) {
19+
return DatabaseClient(
20+
dbUrl: Platform.environment['DB_URL'],
21+
dbUser: Platform.environment['DB_USER'],
22+
dbPassword: Platform.environment['DB_PASSWORD'],
23+
);
24+
}),
25+
);
26+
}
27+
```
28+
29+
When running the server, these environment variables can be passed along directly to Dart Frog commands:
30+
31+
Development server:
32+
33+
```bash
34+
DB_URL=... DB_USER=... DB_PASSWORD=... dart_frog server
35+
```
36+
37+
Production server:
38+
39+
```bash
40+
DB_URL=... DB_USER=... DB_PASSWORD=... dart build/server.dart
41+
```
42+
43+
These variables can also be exported in the current session:
44+
45+
```bash
46+
EXPORT DB_URL=...
47+
EXPORT DB_USER=...
48+
EXPORT DB_PASSWORD=...
49+
```
50+
51+
:::warning
52+
Accessing variables through `String.fromEnvironment` in a Dart Frog application will not work.`String.fromEnvironment` is meant to accesses variables set by the Dart
53+
compiler or runtime, which does not apply to a Dart Frog application. Instead, use
54+
`Platform.environment`.
55+
:::

docs/docs/basics/resources.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
sidebar_position: 7
2+
sidebar_position: 8
33
title: 📚 Additional Resources
44
---
55

0 commit comments

Comments
 (0)