Skip to content

Commit

Permalink
Support generate for special module
Browse files Browse the repository at this point in the history
  • Loading branch information
tdao committed Jan 7, 2023
1 parent c63102b commit 8badc1e
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 17 deletions.
31 changes: 23 additions & 8 deletions lib/cli_commands.dart
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@ void createSplash({
}

final config = getConfig(configFile: path, flavor: flavor);
// It is important that the flavor setup occurs as soon as possible.
// So before we generate anything, we need to setup the flavor (even if it's the default one).
_flavorHelper = _FlavorHelper(config[_Parameter.appModule] ?? '', flavor);
createSplashByConfig(config);
}

Expand Down Expand Up @@ -148,7 +151,13 @@ void createSplashByConfig(Map<String, dynamic> config) {

if (!config.containsKey(_Parameter.android) ||
config[_Parameter.android] as bool) {
if (Directory('android').existsSync()) {
bool folderAndroidExist;
if (config.containsKey(_Parameter.appModule)) {
folderAndroidExist = Directory('../${config[_Parameter.appModule]}/android').existsSync();
} else {
folderAndroidExist = Directory('android').existsSync();
}
if (folderAndroidExist) {
_createAndroidSplash(
imagePath: imageAndroid ?? image,
darkImagePath: darkImageAndroid ?? darkImage,
Expand Down Expand Up @@ -179,7 +188,13 @@ void createSplashByConfig(Map<String, dynamic> config) {
}

if (!config.containsKey(_Parameter.ios) || config[_Parameter.ios] as bool) {
if (Directory('ios').existsSync()) {
bool folderIOSExist;
if (config.containsKey(_Parameter.appModule)) {
folderIOSExist = Directory('../${config[_Parameter.appModule]}/ios').existsSync();
} else {
folderIOSExist = Directory('ios').existsSync();
}
if (folderIOSExist) {
_createiOSSplash(
imagePath: imageIos ?? image,
darkImagePath: darkImageIos ?? darkImage,
Expand Down Expand Up @@ -245,7 +260,9 @@ void removeSplash({
}) {
print("Restoring Flutter's default native splash screen...");
final config = getConfig(configFile: path, flavor: flavor);

// It is important that the flavor setup occurs as soon as possible.
// So before we generate anything, we need to setup the flavor (even if it's the default one).
_flavorHelper = _FlavorHelper(config[_Parameter.appModule] ?? '', flavor);
final removeConfig = <String, dynamic>{
_Parameter.color: '#ffffff',
_Parameter.darkColor: '#000000'
Expand Down Expand Up @@ -334,9 +351,6 @@ Map<String, dynamic> getConfig({
required String? configFile,
required String? flavor,
}) {
// It is important that the flavor setup occurs as soon as possible.
// So before we generate anything, we need to setup the flavor (even if it's the default one).
_flavorHelper = _FlavorHelper(flavor);
// if `flutter_native_splash.yaml` exists use it as config file, otherwise use `pubspec.yaml`
String filePath;
if (configFile != null) {
Expand All @@ -346,8 +360,8 @@ Map<String, dynamic> getConfig({
print('The config file `$configFile` was not found.');
exit(1);
}
} else if (_flavorHelper.flavor != null) {
filePath = 'flutter_native_splash-${_flavorHelper.flavor}.yaml';
} else if (flavor != null) {
filePath = 'flutter_native_splash-$flavor.yaml';
} else if (File('flutter_native_splash.yaml').existsSync()) {
filePath = 'flutter_native_splash.yaml';
} else {
Expand Down Expand Up @@ -402,6 +416,7 @@ String? parseColor(dynamic color) {
}

class _Parameter {
static const appModule = 'app_module';
static const android = 'android';
static const android12Section = 'android_12';
static const androidScreenOrientation = 'android_screen_orientation';
Expand Down
26 changes: 17 additions & 9 deletions lib/flavor_helper.dart
Original file line number Diff line number Diff line change
@@ -1,20 +1,28 @@
part of flutter_native_splash_cli;

class _FlavorHelper {
_FlavorHelper(this._flavor) {
_FlavorHelper(this.appModule, this._flavor) {
if (_flavor != null) {
_androidResFolder = 'android/app/src/$_flavor/res/';
_androidResFolder = '${appModulePrefix}android/app/src/$_flavor/res/';
_iOSFlavorName = _flavor!.capitalize();
} else {
_androidResFolder = 'android/app/src/main/res/';
_androidResFolder = '${appModulePrefix}android/app/src/main/res/';
_iOSFlavorName = '';
}
}

final String appModule;
// Android related path values
final String? _flavor;
late String _androidResFolder;

String get appModulePrefix {
if (appModule.isEmpty) {
return '';
}
return '../$appModule/';
}

String? get flavor {
return _flavor;
}
Expand Down Expand Up @@ -72,7 +80,7 @@ class _FlavorHelper {
}

String get androidManifestFile {
return 'android/app/src/main/AndroidManifest.xml';
return '${appModulePrefix}android/app/src/main/AndroidManifest.xml';
}

// iOS related values
Expand All @@ -83,27 +91,27 @@ class _FlavorHelper {
}

String get iOSAssetsLaunchImageFolder {
return 'ios/Runner/Assets.xcassets/LaunchImage$_iOSFlavorName.imageset/';
return '${appModulePrefix}ios/Runner/Assets.xcassets/LaunchImage$_iOSFlavorName.imageset/';
}

String get iOSAssetsBrandingImageFolder {
return 'ios/Runner/Assets.xcassets/BrandingImage$_iOSFlavorName.imageset/';
return '${appModulePrefix}ios/Runner/Assets.xcassets/BrandingImage$_iOSFlavorName.imageset/';
}

String get iOSLaunchScreenStoryboardFile {
return 'ios/Runner/Base.lproj/$iOSLaunchScreenStoryboardName.storyboard';
return '${appModulePrefix}ios/Runner/Base.lproj/$iOSLaunchScreenStoryboardName.storyboard';
}

String get iOSLaunchScreenStoryboardName {
return 'LaunchScreen$_iOSFlavorName';
}

String get iOSInfoPlistFile {
return 'ios/Runner/Info.plist';
return '${appModulePrefix}ios/Runner/Info.plist';
}

String get iOSAssetsLaunchImageBackgroundFolder {
return 'ios/Runner/Assets.xcassets/LaunchBackground$_iOSFlavorName.imageset/';
return '${appModulePrefix}ios/Runner/Assets.xcassets/LaunchBackground$_iOSFlavorName.imageset/';
}

String get iOSLaunchScreenStoryBoardContent {
Expand Down

0 comments on commit 8badc1e

Please sign in to comment.