-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
184 additions
and
29 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
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 |
---|---|---|
@@ -1,5 +1,23 @@ | ||
class PackageContext { | ||
final bool isFlutter; | ||
import "package:uni/src/tooling.dart"; | ||
|
||
const PackageContext({this.isFlutter}); | ||
abstract class Context { | ||
final String name; | ||
|
||
const Context({this.name}); | ||
|
||
Future<bool> isSupported(); | ||
} | ||
|
||
class FlutterContext extends Context { | ||
const FlutterContext() : super(name: "flutter"); | ||
|
||
@override | ||
Future<bool> isSupported() => const FlutterTooling().isSupported(); | ||
} | ||
|
||
class DartContext extends Context { | ||
const DartContext() : super(name: "dart"); | ||
|
||
@override | ||
Future<bool> isSupported() => const AdaptiveTooling().isSupported(); | ||
} |
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,100 @@ | ||
import "package:pub_semver/pub_semver.dart"; | ||
import "package:uni/src/tools/dart_tool.dart"; | ||
import "package:uni/src/tools/dartanalyzer_tool.dart"; | ||
import "package:uni/src/tools/dartdoc_tool.dart"; | ||
import "package:uni/src/tools/dartfmt_tool.dart"; | ||
import "package:uni/src/tools/flutter_tool.dart"; | ||
import "package:uni/src/tools/pub_tool.dart"; | ||
|
||
abstract class Tooling { | ||
final String name; | ||
final String description; | ||
|
||
const Tooling({ | ||
this.name, | ||
this.description, | ||
}); | ||
|
||
factory Tooling.fromName(String name) { | ||
if (const AdaptiveTooling().name == name) { | ||
return const AdaptiveTooling(); | ||
} | ||
|
||
if (const DartTooling().name == name) { | ||
return const DartTooling(); | ||
} | ||
|
||
if (const FlutterTooling().name == name) { | ||
return const FlutterTooling(); | ||
} | ||
|
||
if (const LegacyTooling().name == name) { | ||
return const LegacyTooling(); | ||
} | ||
|
||
return null; | ||
} | ||
|
||
Future<bool> isSupported(); | ||
} | ||
|
||
class AdaptiveTooling extends Tooling { | ||
const AdaptiveTooling() | ||
: super( | ||
name: "adaptive", | ||
description: "Selects tooling based on package.", | ||
); | ||
|
||
@override | ||
Future<bool> isSupported() async => Stream.fromFutures([ | ||
const DartTooling().isSupported(), | ||
const FlutterTooling().isSupported(), | ||
const LegacyTooling().isSupported(), | ||
]).any( | ||
(supported) => supported, | ||
); | ||
} | ||
|
||
class DartTooling extends Tooling { | ||
const DartTooling() | ||
: super( | ||
name: "dart", | ||
description: "Only use `dart` tool.", | ||
); | ||
|
||
@override | ||
Future<bool> isSupported() async => | ||
const DartTool().isAvailable() && | ||
VersionConstraint.parse("^2.10.0").allows( | ||
await const DartTool().getVersion(), | ||
); | ||
} | ||
|
||
class FlutterTooling extends Tooling { | ||
const FlutterTooling() | ||
: super( | ||
name: "flutter", | ||
description: "Only use `flutter` tool.", | ||
); | ||
|
||
@override | ||
Future<bool> isSupported() async => const FlutterTool().isAvailable(); | ||
} | ||
|
||
class LegacyTooling extends Tooling { | ||
const LegacyTooling() | ||
: super( | ||
name: "legacy", | ||
description: "Only use legacy tooling.", | ||
); | ||
|
||
@override | ||
Future<bool> isSupported() async => const [ | ||
PubTool(), | ||
DartAnalyzerTool(), | ||
DartFmtTool(), | ||
DartDocTool(), | ||
].every( | ||
(tool) => tool.isAvailable(), | ||
); | ||
} |