Add create app and plugin templates for Swift Package Manager (#147082)
When Swift Package Manager feature is enabled, create app and create plugin will have Swift Package Manager integration already added and will not need to undergo a migration. Fixes https://github.com/flutter/flutter/issues/146371. ``` flutter config --enable-swift-package-manager flutter create --ios-language swift --platforms ios,macos swift_app_name flutter create --ios-language objc --platforms ios objc_app_name flutter create --template=plugin --ios-language swift --platforms ios,macos swift_plugin_name flutter create --template=plugin --ios-language objc --platforms ios objc_plugin_name ```
This commit is contained in:
committed by
GitHub
parent
d85571b46b
commit
5a63b1df95
@@ -21,6 +21,8 @@ import '../flutter_manifest.dart';
|
||||
import '../flutter_project_metadata.dart';
|
||||
import '../globals.dart' as globals;
|
||||
import '../ios/code_signing.dart';
|
||||
import '../macos/swift_package_manager.dart';
|
||||
import '../macos/swift_packages.dart';
|
||||
import '../project.dart';
|
||||
import '../reporting/reporting.dart';
|
||||
import '../runner/flutter_command.dart';
|
||||
@@ -324,6 +326,7 @@ class CreateCommand extends CreateBase {
|
||||
projectDescription: stringArg('description'),
|
||||
flutterRoot: flutterRoot,
|
||||
withPlatformChannelPluginHook: generateMethodChannelsPlugin,
|
||||
withSwiftPackageManager: featureFlags.isSwiftPackageManagerEnabled,
|
||||
withFfiPluginHook: generateFfiPlugin,
|
||||
withFfiPackage: generateFfiPackage,
|
||||
withEmptyMain: emptyArgument,
|
||||
@@ -603,8 +606,21 @@ Your $application code is in $relativeAppMain.
|
||||
? stringArg('description')
|
||||
: 'A new Flutter plugin project.';
|
||||
templateContext['description'] = description;
|
||||
|
||||
final String? projectName = templateContext['projectName'] as String?;
|
||||
final List<String> templates = <String>['plugin', 'plugin_shared'];
|
||||
if ((templateContext['ios'] == true || templateContext['macos'] == true) && featureFlags.isSwiftPackageManagerEnabled) {
|
||||
templates.add('plugin_swift_package_manager');
|
||||
templateContext['swiftLibraryName'] = projectName?.replaceAll('_', '-');
|
||||
templateContext['swiftToolsVersion'] = minimumSwiftToolchainVersion;
|
||||
templateContext['iosSupportedPlatform'] = SwiftPackageManager.iosSwiftPackageSupportedPlatform.format();
|
||||
templateContext['macosSupportedPlatform'] = SwiftPackageManager.macosSwiftPackageSupportedPlatform.format();
|
||||
} else {
|
||||
templates.add('plugin_cocoapods');
|
||||
}
|
||||
|
||||
generatedCount += await renderMerged(
|
||||
<String>['plugin', 'plugin_shared'],
|
||||
templates,
|
||||
directory,
|
||||
templateContext,
|
||||
overwrite: overwrite,
|
||||
@@ -618,7 +634,6 @@ Your $application code is in $relativeAppMain.
|
||||
project: project, requireAndroidSdk: false);
|
||||
}
|
||||
|
||||
final String? projectName = templateContext['projectName'] as String?;
|
||||
final String organization = templateContext['organization']! as String; // Required to make the context.
|
||||
final String? androidPluginIdentifier = templateContext['androidIdentifier'] as String?;
|
||||
final String exampleProjectName = '${projectName}_example';
|
||||
|
||||
@@ -351,6 +351,7 @@ abstract class CreateBase extends FlutterCommand {
|
||||
String? kotlinVersion,
|
||||
String? gradleVersion,
|
||||
bool withPlatformChannelPluginHook = false,
|
||||
bool withSwiftPackageManager = false,
|
||||
bool withFfiPluginHook = false,
|
||||
bool withFfiPackage = false,
|
||||
bool withEmptyMain = false,
|
||||
@@ -404,6 +405,7 @@ abstract class CreateBase extends FlutterCommand {
|
||||
'withFfiPackage': withFfiPackage,
|
||||
'withFfiPluginHook': withFfiPluginHook,
|
||||
'withPlatformChannelPluginHook': withPlatformChannelPluginHook,
|
||||
'withSwiftPackageManager': withSwiftPackageManager,
|
||||
'withPluginHook': withFfiPluginHook || withFfiPackage || withPlatformChannelPluginHook,
|
||||
'withEmptyMain': withEmptyMain,
|
||||
'androidLanguage': androidLanguage,
|
||||
|
||||
@@ -30,12 +30,12 @@ class SwiftPackageManager {
|
||||
|
||||
static const String _defaultFlutterPluginsSwiftPackageName = 'FlutterGeneratedPluginSwiftPackage';
|
||||
|
||||
static final SwiftPackageSupportedPlatform _iosSwiftPackageSupportedPlatform = SwiftPackageSupportedPlatform(
|
||||
static final SwiftPackageSupportedPlatform iosSwiftPackageSupportedPlatform = SwiftPackageSupportedPlatform(
|
||||
platform: SwiftPackagePlatform.ios,
|
||||
version: Version(12, 0, null),
|
||||
);
|
||||
|
||||
static final SwiftPackageSupportedPlatform _macosSwiftPackageSupportedPlatform = SwiftPackageSupportedPlatform(
|
||||
static final SwiftPackageSupportedPlatform macosSwiftPackageSupportedPlatform = SwiftPackageSupportedPlatform(
|
||||
platform: SwiftPackagePlatform.macos,
|
||||
version: Version(10, 14, null),
|
||||
);
|
||||
@@ -66,9 +66,9 @@ class SwiftPackageManager {
|
||||
|
||||
final SwiftPackageSupportedPlatform swiftSupportedPlatform;
|
||||
if (platform == SupportedPlatform.ios) {
|
||||
swiftSupportedPlatform = _iosSwiftPackageSupportedPlatform;
|
||||
swiftSupportedPlatform = iosSwiftPackageSupportedPlatform;
|
||||
} else {
|
||||
swiftSupportedPlatform = _macosSwiftPackageSupportedPlatform;
|
||||
swiftSupportedPlatform = macosSwiftPackageSupportedPlatform;
|
||||
}
|
||||
|
||||
// FlutterGeneratedPluginSwiftPackage must be statically linked to ensure
|
||||
@@ -169,10 +169,10 @@ class SwiftPackageManager {
|
||||
final SwiftPackageSupportedPlatform defaultPlatform;
|
||||
final SwiftPackagePlatform packagePlatform;
|
||||
if (platform == SupportedPlatform.ios) {
|
||||
defaultPlatform = _iosSwiftPackageSupportedPlatform;
|
||||
defaultPlatform = iosSwiftPackageSupportedPlatform;
|
||||
packagePlatform = SwiftPackagePlatform.ios;
|
||||
} else {
|
||||
defaultPlatform = _macosSwiftPackageSupportedPlatform;
|
||||
defaultPlatform = macosSwiftPackageSupportedPlatform;
|
||||
packagePlatform = SwiftPackagePlatform.macos;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user