-
Notifications
You must be signed in to change notification settings - Fork 74
feat: make the cli compatible with jaspr projects #440
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -77,11 +77,10 @@ class Package { | |
|
|
||
| /// Returns whether this package is a Flutter app. | ||
| /// This is determined by ensuring all the following conditions are met: | ||
| /// a) the package depends on the Flutter SDK. | ||
| /// a) the package depends on the Flutter SDK or is a Flutter compatible package. | ||
| /// b) the package does not define itself as a Flutter plugin inside pubspec.yaml. | ||
| /// c) a lib/main.dart file exists in the package. | ||
| bool get isFlutterApp { | ||
| // Must directly depend on the Flutter SDK. | ||
| // Must directly depend on the Flutter SDK or be a Flutter compatible package. | ||
| if (!isFlutterPackage) return false; | ||
|
|
||
| // Must not have a Flutter plugin definition in it's pubspec.yaml. | ||
|
|
@@ -90,6 +89,24 @@ class Package { | |
| return true; | ||
| } | ||
|
|
||
| /// Returns whether this package is a runtime package. | ||
| /// | ||
| /// These are packages that are compatible with Flutter plugins, even | ||
| /// if they don't depend on the Flutter SDK directly. | ||
| /// | ||
| /// This is currently only true for packages that depend on Jaspr. | ||
| late final bool isRuntimePackage = dependencies.contains('jaspr'); | ||
|
Comment on lines
91
to
+98
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think we should support Jaspr, but this detection is hardcoded to match just that. Supporting a second non-Flutter host later means adding another hardcoded dependency check here plus another subclass in |
||
|
|
||
| bool get isRuntimeApp { | ||
| // Must not be a Flutter package. | ||
| if (isFlutterApp) return false; | ||
|
|
||
| // Must be a runtime package. | ||
| if (!isRuntimePackage) return false; | ||
|
|
||
| return true; | ||
| } | ||
|
|
||
| /// Returns whether this package is a Flutter plugin. | ||
| /// This is determined by whether the pubspec contains a flutter.plugin definition. | ||
| bool get isFlutterPlugin => pubSpec.flutter?.containsKey('plugin') ?? false; | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -22,7 +22,7 @@ import 'common/platform.dart'; | |
| import 'common/strings.dart'; | ||
| import 'common/utils.dart'; | ||
|
|
||
| class FlutterApp { | ||
| abstract class FlutterApp { | ||
| FlutterApp({ | ||
| required this.package, | ||
| }); | ||
|
|
@@ -37,20 +37,103 @@ class FlutterApp { | |
| throw FlutterAppRequiredException(); | ||
| } | ||
| final package = await Package.load(appDirectory); | ||
| if (!package.isFlutterApp) { | ||
| return null; | ||
| if (package.isFlutterApp) { | ||
| return FlutterProjectApp(package: package); | ||
| } | ||
| return FlutterApp( | ||
| package: package, | ||
| if (package.isRuntimeApp) { | ||
| return FlutterRuntimeApp(package: package); | ||
| } | ||
| return null; | ||
|
Comment on lines
39
to
+46
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Since we're introducing "runtime apps" as a first-class concept rather than a Jaspr-only special case, could this be a small registry of adapters instead, something like a list of |
||
| } | ||
|
|
||
| String? get iosBundleId; | ||
| String? get macosBundleId; | ||
| String? get androidApplicationId; | ||
|
|
||
| /// Returns whether the package depends on the given package. | ||
| bool dependsOnPackage(String packageName) { | ||
| return package.dependencies.contains(packageName) || | ||
| package.devDependencies.contains(packageName); | ||
| } | ||
|
|
||
| /// Returns whether this Flutter app can run on Android. | ||
| bool get android; | ||
|
|
||
| /// Returns the directory where the Android platform specific project exists. | ||
| Directory get androidDirectory { | ||
| return _platformDirectory(kAndroid); | ||
| } | ||
|
|
||
| /// Returns whether this Flutter app can run on Web. | ||
| bool get web; | ||
|
|
||
| /// Returns the directory where the Web platform specific project exists. | ||
| Directory get webDirectory { | ||
| return _platformDirectory(kWeb); | ||
| } | ||
|
|
||
| /// Returns whether this Flutter app can run on Windows. | ||
| bool get windows; | ||
|
|
||
| /// Returns the directory where the Windows platform specific project exists. | ||
| Directory get windowsDirectory { | ||
| return _platformDirectory(kWindows); | ||
| } | ||
|
|
||
| /// Returns whether this Flutter app can run on MacOS. | ||
| bool get macos; | ||
|
|
||
| /// Returns the directory where the macOS platform specific project exists. | ||
| Directory get macosDirectory { | ||
| return _platformDirectory(kMacos); | ||
| } | ||
|
|
||
| /// Returns whether this Flutter app can run on iOS. | ||
| bool get ios; | ||
|
|
||
| /// Returns the directory where the iOS platform specific project exists. | ||
| Directory get iosDirectory { | ||
| return _platformDirectory(kIos); | ||
| } | ||
|
|
||
| /// Returns whether this Flutter app can run on Linux. | ||
| bool get linux; | ||
|
|
||
| /// Returns the directory where the Linux platform specific project exists. | ||
| Directory get linuxDirectory { | ||
| return _platformDirectory(kLinux); | ||
| } | ||
|
|
||
| Directory _platformDirectory(String platform) { | ||
| assert( | ||
| platform == kIos || | ||
| platform == kAndroid || | ||
| platform == kWeb || | ||
| platform == kMacos || | ||
| platform == kWindows || | ||
| platform == kLinux, | ||
| ); | ||
| return Directory( | ||
| '${package.path}${currentPlatform.pathSeparator}$platform', | ||
| ); | ||
| } | ||
|
|
||
| String? get cleanBaseCommand; | ||
| String get pubBaseCommand; | ||
| } | ||
|
|
||
| class FlutterProjectApp extends FlutterApp { | ||
| FlutterProjectApp({ | ||
| required super.package, | ||
| }); | ||
|
|
||
| // Cached Android package name if available. | ||
| String? _androidApplicationId; | ||
|
|
||
| // Cached iOS bundle identifier if available. | ||
| String? _iosBundleId; | ||
|
|
||
| @override | ||
| String? get iosBundleId { | ||
| if (!ios) return null; | ||
| if (_iosBundleId != null) { | ||
|
|
@@ -62,6 +145,7 @@ class FlutterApp { | |
| // Cached macOS bundle identifier if available. | ||
| String? _macosBundleId; | ||
|
|
||
| @override | ||
| String? get macosBundleId { | ||
| if (!macos) return null; | ||
| if (_macosBundleId != null) { | ||
|
|
@@ -109,6 +193,7 @@ class FlutterApp { | |
| /// The Android Application (or Package Name) for this Flutter | ||
| /// application, or null if one could not be detected or the app | ||
| /// does not target Android as a supported platform. | ||
| @override | ||
| String? get androidApplicationId { | ||
| if (!android) return null; | ||
| if (_androidApplicationId != null) { | ||
|
|
@@ -175,93 +260,86 @@ class FlutterApp { | |
| return _androidApplicationId = applicationId; | ||
| } | ||
|
|
||
| /// Returns whether the package depends on the given package. | ||
| bool dependsOnPackage(String packageName) { | ||
| return package.dependencies.contains(packageName) || | ||
| package.devDependencies.contains(packageName); | ||
| } | ||
|
|
||
| /// Returns whether this Flutter app can run on Android. | ||
| @override | ||
| bool get android { | ||
| if (!package.isFlutterApp) return false; | ||
| return _supportsPlatform(kAndroid); | ||
| } | ||
|
|
||
| /// Returns the directory where the Android platform specific project exists. | ||
| Directory get androidDirectory { | ||
| return _platformDirectory(kAndroid); | ||
| } | ||
|
|
||
| /// Returns whether this Flutter app can run on Web. | ||
| @override | ||
| bool get web { | ||
| if (!package.isFlutterApp) return false; | ||
| return _supportsPlatform(kWeb); | ||
| } | ||
|
|
||
| /// Returns the directory where the Web platform specific project exists. | ||
| Directory get webDirectory { | ||
| return _platformDirectory(kWeb); | ||
| } | ||
|
|
||
| /// Returns whether this Flutter app can run on Windows. | ||
| @override | ||
| bool get windows { | ||
| if (!package.isFlutterApp) return false; | ||
| return _supportsPlatform(kWindows); | ||
| } | ||
|
|
||
| /// Returns the directory where the Windows platform specific project exists. | ||
| Directory get windowsDirectory { | ||
| return _platformDirectory(kWindows); | ||
| } | ||
|
|
||
| /// Returns whether this Flutter app can run on MacOS. | ||
| @override | ||
| bool get macos { | ||
| if (!package.isFlutterApp) return false; | ||
| return _supportsPlatform(kMacos); | ||
| } | ||
|
|
||
| /// Returns the directory where the macOS platform specific project exists. | ||
| Directory get macosDirectory { | ||
| return _platformDirectory(kMacos); | ||
| } | ||
|
|
||
| /// Returns whether this Flutter app can run on iOS. | ||
| @override | ||
| bool get ios { | ||
| if (!package.isFlutterApp) return false; | ||
| return _supportsPlatform(kIos); | ||
| } | ||
|
|
||
| /// Returns the directory where the iOS platform specific project exists. | ||
| Directory get iosDirectory { | ||
| return _platformDirectory(kIos); | ||
| } | ||
|
|
||
| /// Returns whether this Flutter app can run on Linux. | ||
| @override | ||
| bool get linux { | ||
| if (!package.isFlutterApp) return false; | ||
| return _supportsPlatform(kLinux); | ||
| } | ||
|
|
||
| /// Returns the directory where the Linux platform specific project exists. | ||
| Directory get linuxDirectory { | ||
| return _platformDirectory(kLinux); | ||
| } | ||
|
|
||
| Directory _platformDirectory(String platform) { | ||
| assert( | ||
| platform == kIos || | ||
| platform == kAndroid || | ||
| platform == kWeb || | ||
| platform == kMacos || | ||
| platform == kWindows || | ||
| platform == kLinux, | ||
| ); | ||
| return Directory( | ||
| '${package.path}${currentPlatform.pathSeparator}$platform', | ||
| ); | ||
| } | ||
|
|
||
| bool _supportsPlatform(String platform) { | ||
| return _platformDirectory(platform).existsSync(); | ||
| } | ||
|
|
||
| @override | ||
| String? get cleanBaseCommand => 'flutter'; | ||
|
|
||
| @override | ||
| String get pubBaseCommand => 'flutter'; | ||
| } | ||
|
|
||
| class FlutterRuntimeApp extends FlutterApp { | ||
| FlutterRuntimeApp({required super.package}); | ||
|
|
||
| @override | ||
| bool get android => false; | ||
|
|
||
| @override | ||
| String? get androidApplicationId => null; | ||
|
|
||
| @override | ||
| bool get ios => false; | ||
|
|
||
| @override | ||
| String? get iosBundleId => null; | ||
|
|
||
| @override | ||
| bool get linux => false; | ||
|
|
||
| @override | ||
| bool get macos => false; | ||
|
|
||
| @override | ||
| String? get macosBundleId => null; | ||
|
|
||
| @override | ||
| bool get web => true; | ||
|
|
||
| @override | ||
| bool get windows => false; | ||
|
|
||
| @override | ||
| String? get cleanBaseCommand => null; | ||
|
|
||
| @override | ||
| String get pubBaseCommand => 'dart'; | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nothing calls
commandRequiresFlutterApp(allowRuntimeApp: false)anywhere inconfig.dart/reconfigure.dart/update.dart/install.dart. If there's no command that should rejectFlutterRuntimeApp, maybe drop this parameter until there is one.