OLD | NEW |
1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file |
2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
4 | 4 |
5 import 'dart:io'; | 5 import 'dart:io'; |
6 | 6 |
7 import 'package:path/path.dart' as p; | 7 import 'package:path/path.dart' as p; |
8 import 'package:pub_semver/pub_semver.dart'; | 8 import 'package:pub_semver/pub_semver.dart'; |
9 | 9 |
10 import 'io.dart'; | 10 import 'io.dart'; |
11 | 11 |
12 /// Whether the Flutter SDK is available. | 12 /// Whether the Flutter SDK is available. |
13 final bool isAvailable = Platform.environment.containsKey("FLUTTER_ROOT"); | 13 final bool isAvailable = Platform.environment.containsKey("FLUTTER_ROOT"); |
14 | 14 |
15 /// The path to the root directory of the Flutter SDK. | 15 /// The path to the root directory of the Flutter SDK. |
16 final String rootDirectory = Platform.environment["FLUTTER_ROOT"]; | 16 final String rootDirectory = Platform.environment["FLUTTER_ROOT"]; |
17 | 17 |
18 /// The Flutter SDK's version number, or `null` if the Flutter SDK is | 18 /// The Flutter SDK's version number, or `null` if the Flutter SDK is |
19 /// unavailable. | 19 /// unavailable. |
20 final version = () { | 20 final version = () { |
21 if (!isAvailable) return null; | 21 if (!isAvailable) return null; |
22 | 22 |
23 return new Version.parse( | 23 return new Version.parse( |
24 readTextFile(p.join(rootDirectory, "version")).trim()); | 24 readTextFile(p.join(rootDirectory, "version")).trim()); |
25 }(); | 25 }(); |
| 26 |
| 27 /// Returns the path to the package [name] within Flutter. |
| 28 String packagePath(String name) { |
| 29 if (!isAvailable) throw new StateError("Flutter is not available."); |
| 30 |
| 31 return p.join(rootDirectory, 'packages', name); |
| 32 } |
OLD | NEW |