@@ -4,50 +4,42 @@ import 'dart:io';
44import 'package:analyzer/dart/analysis/utilities.dart' ;
55import 'package:args/command_runner.dart' ;
66import 'package:dart_dev/dart_dev.dart' ;
7- import 'package:dart_dev/src/dart_dev_tool.dart' ;
8- import 'package:dart_dev/src/utils/format_tool_builder.dart' ;
9- import 'package:dart_dev/src/utils/parse_flag_from_args.dart' ;
107import 'package:io/ansi.dart' ;
118import 'package:io/io.dart' show ExitCode;
129import 'package:logging/logging.dart' ;
1310import 'package:path/path.dart' as p;
1411
15- import '../utils.dart' ;
1612import 'dart_dev_runner.dart' ;
1713import 'tools/over_react_format_tool.dart' ;
1814import 'utils/assert_dir_is_dart_package.dart' ;
15+ import 'utils/cached_pubspec.dart' ;
16+ import 'utils/dart_dev_paths.dart' ;
1917import 'utils/dart_tool_cache.dart' ;
2018import 'utils/ensure_process_exit.dart' ;
19+ import 'utils/format_tool_builder.dart' ;
2120import 'utils/logging.dart' ;
21+ import 'utils/parse_flag_from_args.dart' ;
2222
2323typedef _ConfigGetter = Map <String , DevTool > Function ();
2424
25- final _runScriptPath = p. join (cacheDirPath, 'run.dart' );
25+ final paths = DartDevPaths ( );
2626
27- final _runScript = File (_runScriptPath);
28-
29- const _configPath = 'tool/dart_dev/config.dart' ;
30-
31- const _oldDevDartPath = 'tool/dev.dart' ;
32-
33- final _relativeDevDartPath = p.relative (
34- p.absolute (_configPath),
35- from: p.absolute (p.dirname (_runScriptPath)),
36- );
27+ final _runScript = File (paths.runScript);
3728
3829Future <void > run (List <String > args) async {
3930 attachLoggerToStdio (args);
40- final configExists = File (_configPath).existsSync ();
41- final oldDevDartExists = File (_oldDevDartPath).existsSync ();
31+
32+ final configExists = File (paths.config).existsSync ();
33+ final oldDevDartExists = File (paths.legacyConfig).existsSync ();
4234
4335 if (! configExists) {
44- log.fine ('No custom `tool/dart_dev/config.dart ` file found; '
36+ log.fine ('No custom `${ paths . config } ` file found; '
4537 'using default config.' );
4638 }
4739 if (oldDevDartExists) {
4840 log.warning (yellow.wrap (
49- 'dart_dev v3 now expects configuration to be at `$_configPath `,\n '
50- 'but `$_oldDevDartPath ` still exists. View the guide to see how to upgrade:\n '
41+ 'dart_dev v3 now expects configuration to be at `${ paths . config } `,\n '
42+ 'but `${ paths . legacyConfig } ` still exists. View the guide to see how to upgrade:\n '
5143 'https://github.com/Workiva/dart_dev/blob/master/doc/v3-upgrade-guide.md' ));
5244 }
5345
@@ -59,7 +51,7 @@ Future<void> run(List<String> args) async {
5951
6052 generateRunScript ();
6153 final process = await Process .start (
62- Platform .executable, [_runScriptPath , ...args],
54+ Platform .executable, [paths.runScript , ...args],
6355 mode: ProcessStartMode .inheritStdio);
6456 ensureProcessExit (process);
6557 exitCode = await process.exitCode;
@@ -69,7 +61,7 @@ Future<void> handleFastFormat(List<String> args) async {
6961 assertDirIsDartPackage ();
7062
7163 DevTool formatTool;
72- final configFile = File (_configPath );
64+ final configFile = File (paths.config );
7365 if (configFile.existsSync ()) {
7466 final toolBuilder = FormatToolBuilder ();
7567 parseString (content: configFile.readAsStringSync ())
@@ -115,13 +107,13 @@ bool get shouldWriteRunScript =>
115107 _runScript.readAsStringSync () != buildDartDevRunScriptContents ();
116108
117109String buildDartDevRunScriptContents () {
118- final hasCustomToolDevDart = File (_configPath ).existsSync ();
110+ final hasCustomToolDevDart = File (paths.config ).existsSync ();
119111 return '''
120112import 'dart:io';
121113
122114import 'package:dart_dev/src/core_config.dart';
123115import 'package:dart_dev/src/executable.dart' as executable;
124- ${hasCustomToolDevDart ? "import '$_relativeDevDartPath ' as custom_dev;" : "" }
116+ ${hasCustomToolDevDart ? "import '${ paths . configFromRunScriptForDart } ' as custom_dev;" : "" }
125117
126118void main(List<String> args) async {
127119 await executable.runWithConfig(args,
@@ -146,8 +138,7 @@ Future<void> runWithConfig(
146138 config = configGetter ();
147139 } catch (error) {
148140 stderr
149- ..writeln (
150- 'Invalid "tool/dart_dev/config.dart" in ${p .absolute (p .current )}' )
141+ ..writeln ('Invalid "${paths .config }" in ${p .absolute (p .current )}' )
151142 ..writeln ()
152143 ..writeln ('It should provide a `Map<String, DevTool> config;` getter,'
153144 ' but it either does not exist or threw unexpectedly:' )
0 commit comments