@@ -28,6 +28,10 @@ typedef DirectoryWatcherBuilder = DirectoryWatcher Function(
2828 String directory,
2929);
3030
31+ /// Typedef for [RestorableDirectoryGeneratorTarget.new]
32+ typedef RestorableDirectoryGeneratorTargetBuilder
33+ = RestorableDirectoryGeneratorTarget Function (Logger ? logger);
34+
3135/// Typedef for [io.exit] .
3236typedef Exit = dynamic Function (int exitCode);
3337
@@ -49,7 +53,7 @@ class DevCommand extends DartFrogCommand {
4953 super .logger,
5054 DirectoryWatcherBuilder ? directoryWatcher,
5155 GeneratorBuilder ? generator,
52- RestorableDirectoryGeneratorTarget ? generatorTarget,
56+ RestorableDirectoryGeneratorTargetBuilder ? generatorTarget,
5357 Exit ? exit,
5458 bool ? isWindows,
5559 ProcessRun ? runProcess,
@@ -62,7 +66,7 @@ class DevCommand extends DartFrogCommand {
6266 _runProcess = runProcess ?? io.Process .run,
6367 _sigint = sigint ?? io.ProcessSignal .sigint,
6468 _startProcess = startProcess ?? io.Process .start,
65- _generatorTarget = generatorTarget ?? _defaultGeneratorTarget (logger) {
69+ _generatorTarget = generatorTarget ?? _defaultGeneratorTarget {
6670 argParser.addOption (
6771 'port' ,
6872 abbr: 'p' ,
@@ -78,7 +82,7 @@ class DevCommand extends DartFrogCommand {
7882 final ProcessRun _runProcess;
7983 final io.ProcessSignal _sigint;
8084 final ProcessStart _startProcess;
81- final RestorableDirectoryGeneratorTarget _generatorTarget;
85+ final RestorableDirectoryGeneratorTargetBuilder _generatorTarget;
8286
8387 @override
8488 final String description = 'Run a local development server.' ;
@@ -91,6 +95,7 @@ class DevCommand extends DartFrogCommand {
9195 var reloading = false ;
9296 var hotReloadEnabled = false ;
9397 final port = io.Platform .environment['PORT' ] ?? results['port' ] as String ;
98+ final target = _generatorTarget (logger);
9499 final generator = await _generator (dartFrogDevServerBundle);
95100
96101 Future <void > codegen () async {
@@ -104,7 +109,7 @@ class DevCommand extends DartFrogCommand {
104109
105110 logger.detail ('[codegen] running generate...' );
106111 final _ = await generator.generate (
107- _generatorTarget ,
112+ target ,
108113 vars: vars,
109114 fileConflictResolution: FileConflictResolution .overwrite,
110115 );
@@ -151,7 +156,7 @@ class DevCommand extends DartFrogCommand {
151156 _exit (1 );
152157 }
153158
154- await _generatorTarget .rollback ();
159+ await target .rollback ();
155160 });
156161
157162 process.stdout.listen ((_) {
@@ -160,7 +165,7 @@ class DevCommand extends DartFrogCommand {
160165 if (containsHotReload) hotReloadEnabled = true ;
161166 if (message.isNotEmpty) logger.info (message);
162167 final shouldCacheSnapshot = containsHotReload && ! hasError;
163- if (shouldCacheSnapshot) _generatorTarget .cacheLatestSnapshot ();
168+ if (shouldCacheSnapshot) target .cacheLatestSnapshot ();
164169 hasError = false ;
165170 });
166171 }
0 commit comments