-
Notifications
You must be signed in to change notification settings - Fork 15
Expand file tree
/
Copy pathcode_outputs.dart
More file actions
31 lines (28 loc) · 1.05 KB
/
code_outputs.dart
File metadata and controls
31 lines (28 loc) · 1.05 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
import 'package:celest_cli/src/codegen/client_code_generator.dart';
import 'package:celest_cli/src/context.dart';
import 'package:collection/collection.dart';
final class CodeOutputs extends DelegatingMap<String, String> {
const CodeOutputs(super.base, {required this.codegenDependencies});
/// Dependencies added as part of the code generation process.
///
/// These must be added to the respective pubspec.yaml after generation
/// to ensure referenced types are available.
final CodegenDependencies codegenDependencies;
Future<void> write() async {
final outputFutures = <Future<void>>[];
forEach((path, library) {
assert(p.isAbsolute(path), 'Path must be absolute: $path');
outputFutures.add(
Future<void>(() async {
final file = fileSystem.file(path);
await file.create(recursive: true);
await file.writeAsString(library);
}),
);
});
if (codegenDependencies.isNotEmpty) {
outputFutures.add(codegenDependencies.save());
}
await Future.wait(outputFutures);
}
}