-
Notifications
You must be signed in to change notification settings - Fork 40
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add and use an abstraction over system and URL paths
- Loading branch information
1 parent
7ed1cef
commit 1ad8316
Showing
4 changed files
with
125 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import 'package:path/path.dart' as p; | ||
|
||
/// A collection of paths to files and directories constructed to be compatible | ||
/// with a given [p.Context]. | ||
class DartDevPaths { | ||
final p.Context _context; | ||
|
||
DartDevPaths({p.Context context}) : _context = context ?? p.context; | ||
|
||
String cache([String subPath]) => _context.normalize( | ||
_context.joinAll([..._cacheParts, if (subPath != null) subPath])); | ||
|
||
String get _cacheForDart => p.url.joinAll(_cacheParts); | ||
|
||
final List<String> _cacheParts = ['.dart_tool', 'dart_dev']; | ||
|
||
String get config => _context.joinAll(_configParts); | ||
|
||
String get configForDart => p.url.joinAll(_configParts); | ||
|
||
final List<String> _configParts = ['tool', 'dart_dev', 'config.dart']; | ||
|
||
String get configFromRunScriptForDart => p.url.relative( | ||
p.url.absolute(configForDart), | ||
from: p.url.absolute(_cacheForDart), | ||
); | ||
|
||
String get legacyConfig => _context.join('tool', 'dev.dart'); | ||
|
||
String get runScript => cache('run.dart'); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
import 'package:dart_dev/src/utils/dart_dev_paths.dart'; | ||
import 'package:path/path.dart' as p; | ||
import 'package:test/test.dart'; | ||
|
||
void main() { | ||
group('DartDevPaths', () { | ||
group('posix', () { | ||
DartDevPaths paths; | ||
|
||
setUp(() { | ||
paths = DartDevPaths(context: p.posix); | ||
}); | ||
|
||
test('cache', () { | ||
expect(paths.cache(), '.dart_tool/dart_dev'); | ||
}); | ||
|
||
test('cache with subpath', () { | ||
expect(paths.cache('sub/path'), '.dart_tool/dart_dev/sub/path'); | ||
}); | ||
|
||
test('config', () { | ||
expect(paths.config, 'tool/dart_dev/config.dart'); | ||
}); | ||
|
||
test('configFromRunScriptForDart', () { | ||
expect(paths.configFromRunScriptForDart, | ||
'../../tool/dart_dev/config.dart'); | ||
}); | ||
|
||
test('legacyConfig', () { | ||
expect(paths.legacyConfig, 'tool/dev.dart'); | ||
}); | ||
|
||
test('runScript', () { | ||
expect(paths.runScript, '.dart_tool/dart_dev/run.dart'); | ||
}); | ||
}); | ||
|
||
group('windows', () { | ||
DartDevPaths paths; | ||
|
||
setUp(() { | ||
paths = DartDevPaths(context: p.windows); | ||
}); | ||
|
||
test('cache', () { | ||
expect(paths.cache(), r'.dart_tool\dart_dev'); | ||
}); | ||
|
||
test('cache with subpath', () { | ||
expect(paths.cache('sub/path'), r'.dart_tool\dart_dev\sub\path'); | ||
}); | ||
|
||
test('config', () { | ||
expect(paths.config, r'tool\dart_dev\config.dart'); | ||
}); | ||
|
||
test('configFromRunScriptForDart', () { | ||
expect(paths.configFromRunScriptForDart, | ||
r'../../tool/dart_dev/config.dart'); | ||
}); | ||
|
||
test('legacyConfig', () { | ||
expect(paths.legacyConfig, r'tool\dev.dart'); | ||
}); | ||
|
||
test('runScript', () { | ||
expect(paths.runScript, r'.dart_tool\dart_dev\run.dart'); | ||
}); | ||
}); | ||
}); | ||
} |