-
Notifications
You must be signed in to change notification settings - Fork 217
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
CLI Command that generates all flavors with single flag (#752)
* - added support to generate all flavors with a single command * - added more helpers and tests * - updated the readme and changelog
- Loading branch information
Showing
10 changed files
with
396 additions
and
23 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,16 +1,39 @@ | ||
import 'package:args/args.dart'; | ||
import 'package:flutter_native_splash/cli_commands.dart'; | ||
import 'package:flutter_native_splash/enums.dart'; | ||
|
||
void main(List<String> args) { | ||
final parser = ArgParser(); | ||
|
||
parser.addOption('path'); | ||
parser.addOption('flavor'); | ||
parser | ||
..addFlag( | ||
ArgEnums.help.name, | ||
abbr: ArgEnums.help.abbr, | ||
help: 'Show help', | ||
) | ||
..addOption( | ||
ArgEnums.path.name, | ||
abbr: ArgEnums.path.abbr, | ||
help: | ||
'Path to the flutter project, if the project is not in it\'s default location.', | ||
) | ||
..addOption( | ||
ArgEnums.flavor.name, | ||
abbr: ArgEnums.flavor.abbr, | ||
help: 'Flavor to remove the splash for.', | ||
); | ||
|
||
final parsedArgs = parser.parse(args); | ||
|
||
final helpArg = parsedArgs[ArgEnums.help.name]; | ||
|
||
if (helpArg != null) { | ||
print(parser.usage); | ||
return; | ||
} | ||
|
||
removeSplash( | ||
path: parsedArgs['path']?.toString(), | ||
flavor: parsedArgs['flavor']?.toString(), | ||
path: parsedArgs[ArgEnums.path.name]?.toString(), | ||
flavor: parsedArgs[ArgEnums.flavor.name]?.toString(), | ||
); | ||
} |
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 +1,2 @@ | ||
#include? "Pods/Target Support Files/Pods-Runner/Pods-Runner.debug.xcconfig" | ||
#include "Generated.xcconfig" |
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 +1,2 @@ | ||
#include? "Pods/Target Support Files/Pods-Runner/Pods-Runner.release.xcconfig" | ||
#include "Generated.xcconfig" |
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,44 @@ | ||
# Uncomment this line to define a global platform for your project | ||
# platform :ios, '12.0' | ||
|
||
# CocoaPods analytics sends network stats synchronously affecting flutter build latency. | ||
ENV['COCOAPODS_DISABLE_STATS'] = 'true' | ||
|
||
project 'Runner', { | ||
'Debug' => :debug, | ||
'Profile' => :release, | ||
'Release' => :release, | ||
} | ||
|
||
def flutter_root | ||
generated_xcode_build_settings_path = File.expand_path(File.join('..', 'Flutter', 'Generated.xcconfig'), __FILE__) | ||
unless File.exist?(generated_xcode_build_settings_path) | ||
raise "#{generated_xcode_build_settings_path} must exist. If you're running pod install manually, make sure flutter pub get is executed first" | ||
end | ||
|
||
File.foreach(generated_xcode_build_settings_path) do |line| | ||
matches = line.match(/FLUTTER_ROOT\=(.*)/) | ||
return matches[1].strip if matches | ||
end | ||
raise "FLUTTER_ROOT not found in #{generated_xcode_build_settings_path}. Try deleting Generated.xcconfig, then run flutter pub get" | ||
end | ||
|
||
require File.expand_path(File.join('packages', 'flutter_tools', 'bin', 'podhelper'), flutter_root) | ||
|
||
flutter_ios_podfile_setup | ||
|
||
target 'Runner' do | ||
use_frameworks! | ||
use_modular_headers! | ||
|
||
flutter_install_all_ios_pods File.dirname(File.realpath(__FILE__)) | ||
target 'RunnerTests' do | ||
inherit! :search_paths | ||
end | ||
end | ||
|
||
post_install do |installer| | ||
installer.pods_project.targets.each do |target| | ||
flutter_additional_ios_build_settings(target) | ||
end | ||
end |
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,12 @@ | ||
enum ArgEnums { | ||
help(name: 'help', abbr: 'h'), | ||
path(name: 'path', abbr: 'p'), | ||
flavor(name: 'flavor', abbr: 'f'), | ||
flavors(name: 'flavors', abbr: 'F'), | ||
allFlavors(name: 'all-flavors', abbr: 'A'); | ||
|
||
final String name; | ||
final String abbr; | ||
|
||
const ArgEnums({required this.name, required this.abbr}); | ||
} |
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,46 @@ | ||
import 'package:flutter_native_splash/enums.dart'; | ||
|
||
class HelperUtils { | ||
const HelperUtils._(); | ||
|
||
/// Checks if a given filename matches the flutter native splash flavor config pattern | ||
/// The pattern is: flutter_native_splash-*.yaml where * is the flavor name | ||
/// | ||
/// Returns true if the filename matches the pattern, false otherwise | ||
static bool isValidFlavorConfigFileName(String fileName) { | ||
return RegExp(r'^flutter_native_splash-[^-]+\.yaml$').hasMatch(fileName); | ||
} | ||
|
||
/// Extracts the flavor name from a valid flavor config filename | ||
/// | ||
/// Throws an exception if the filename is not a valid flavor config filename | ||
static String getFlavorNameFromFileName(String fileName) { | ||
final flavorMatch = | ||
RegExp(r'^flutter_native_splash-(.+)\.yaml$').firstMatch(fileName); | ||
|
||
final flavorName = flavorMatch?.group(1); | ||
|
||
if (flavorName == null) { | ||
throw Exception('Invalid flavor config filename: $fileName'); | ||
} | ||
|
||
return flavorName; | ||
} | ||
|
||
/// Validate the flavor arguments | ||
/// | ||
/// Throws an exception if the arguments are invalid. | ||
static void validateFlavorArgs({ | ||
required String? flavorArg, | ||
required String? flavorsArg, | ||
required bool? allFlavorsArg, | ||
}) { | ||
if ((flavorArg != null && flavorsArg != null) || | ||
(flavorArg != null && allFlavorsArg == true) || | ||
(flavorsArg != null && allFlavorsArg == true)) { | ||
throw Exception( | ||
'Cannot use multiple flavor options together. Please use only one of: --${ArgEnums.flavor.name}, --${ArgEnums.flavors.name}, or --${ArgEnums.allFlavors.name}.', | ||
); | ||
} | ||
} | ||
} |
Oops, something went wrong.