11import 'package:celest_cli/src/codegen/client_code_generator.dart' ;
22import 'package:celest_cli/src/context.dart' ;
3- import 'package:celest_cli/src/pub/project_dependency.dart' ;
4- import 'package:celest_cli/src/pub/pub_action.dart' ;
5- import 'package:celest_cli/src/pub/pubspec.dart' ;
63import 'package:collection/collection.dart' ;
7- import 'package:logging/logging.dart' ;
8- import 'package:pub_semver/pub_semver.dart' ;
9- import 'package:pubspec_parse/pubspec_parse.dart' ;
104
115final class CodeOutputs extends DelegatingMap <String , String > {
126 const CodeOutputs (super .base , {required this .codegenDependencies});
@@ -17,8 +11,6 @@ final class CodeOutputs extends DelegatingMap<String, String> {
1711 /// to ensure referenced types are available.
1812 final CodegenDependencies codegenDependencies;
1913
20- static final Logger _logger = Logger ('CodeOutputs' );
21-
2214 Future <void > write () async {
2315 final outputFutures = < Future <void >> [];
2416 forEach ((path, library) {
@@ -32,49 +24,7 @@ final class CodeOutputs extends DelegatingMap<String, String> {
3224 );
3325 });
3426 if (codegenDependencies.isNotEmpty) {
35- var (pubspec, pubspecYaml) =
36- p.equals (codegenDependencies.rootDir, projectPaths.projectRoot)
37- ? (celestProject.pubspec, celestProject.pubspecYaml)
38- : (celestProject.clientPubspec, celestProject.clientPubspecYaml);
39- final pubspecFile = fileSystem
40- .directory (codegenDependencies.rootDir)
41- .childFile ('pubspec.yaml' );
42- final currentDependencies = Set .of (pubspec.dependencies.keys);
43- final missingDependencies = codegenDependencies.difference (
44- currentDependencies,
45- );
46- if (missingDependencies.isNotEmpty) {
47- _logger.fine (
48- 'Adding dependencies to ${pubspecFile .path }: '
49- '${missingDependencies .toList ()}' ,
50- );
51- pubspec = pubspec.addDeps (
52- dependencies: {
53- for (final dependency in codegenDependencies)
54- dependency:
55- ProjectDependency .all[dependency]? .pubDependency ??
56- HostedDependency (version: VersionConstraint .any),
57- },
58- );
59- if (pubspecFile.existsSync ()) {
60- outputFutures.add (
61- pubspecFile.writeAsString (pubspec.toYaml (source: pubspecYaml)).then (
62- (_) {
63- return runPub (
64- action: PubAction .get ,
65- workingDirectory: pubspecFile.parent.path,
66- );
67- },
68- ),
69- );
70- } else {
71- _logger.fine (
72- 'Skipping dependency update' ,
73- 'Pubspec not found: ${pubspecFile .path }' ,
74- StackTrace .current,
75- );
76- }
77- }
27+ outputFutures.add (codegenDependencies.save ());
7828 }
7929 await Future .wait (outputFutures);
8030 }
0 commit comments