Skip to content

Commit

Permalink
refactor: big refactor to clean up code
Browse files Browse the repository at this point in the history
  • Loading branch information
russellwheatley committed Jan 11, 2023
1 parent 962eb2a commit f8c4264
Show file tree
Hide file tree
Showing 4 changed files with 134 additions and 250 deletions.
4 changes: 2 additions & 2 deletions packages/flutterfire_cli/lib/src/commands/config.dart
Original file line number Diff line number Diff line change
Expand Up @@ -614,7 +614,7 @@ class ConfigCommand extends FlutterFireCommand {
iosOptions,
flutterApp,
fulliOSServicePath,
fulliOSServicePath == null,
fulliOSServicePath != null,
logger,
iosGenerateDebugSymbolScript,
iosScheme,
Expand All @@ -628,7 +628,7 @@ class ConfigCommand extends FlutterFireCommand {
macosOptions,
flutterApp,
fullMacOSServicePath,
fullMacOSServicePath == null,
fullMacOSServicePath != null,
logger,
macosGenerateDebugSymbolScript,
macosScheme,
Expand Down
2 changes: 2 additions & 0 deletions packages/flutterfire_cli/lib/src/common/strings.dart
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@ const noPathVariableFound = r'There is no $PATH variable in your environment. '
"Please file an issue as your Crashlytic's upload debug "
'symbols script will not work without it';

const serviceFileAlreadyExists = 'Your GoogleService-Info.plist already exists, skipping write... ';

/// Prompts when Android Google Services JSON file already exists but contains
/// configuration values for a different Firebase project.
String logPromptReplaceGoogleServicesJson(
Expand Down
120 changes: 1 addition & 119 deletions packages/flutterfire_cli/lib/src/common/utils.dart
Original file line number Diff line number Diff line change
Expand Up @@ -342,7 +342,7 @@ Future<void> writeSchemeScriptToProject(
}
}

Future<void> writeToTargetProject(
Future<void> writeGoogleServiceFileToTargetProject(
String xcodeProjFilePath,
String serviceFilePath,
String target,
Expand All @@ -363,46 +363,6 @@ Future<void> writeToTargetProject(
}
}

Future<void> writeDebugSymbolScriptForScheme(
bool? generateDebugSymbolScript,
String xcodeProjFilePath,
String appId,
Logger logger,
String name,
String platform,
) async {
// ignore: use_if_null_to_convert_nulls_to_bools
if (generateDebugSymbolScript == true) {
await writeDebugScriptForScheme(
xcodeProjFilePath,
appId,
name,
logger,
);
} else if (generateDebugSymbolScript == false) {
// User has specifically requested no debug symbol script insert.
return;
} else {
// User hasn't specified anything, so we prompt
final addSymbolScript = promptBool(
"Do you want an 'upload Crashlytic's debug symbols script' adding to the build phases of your $platform project's '$name' scheme?",
);

if (addSymbolScript == true) {
await writeDebugScriptForScheme(
xcodeProjFilePath,
appId,
name,
logger,
);
} else {
logger.stdout(
logSkippingDebugSymbolScript,
);
}
}
}

Future<void> writeFirebaseJsonFile(
FlutterApp flutterApp,
) async {
Expand All @@ -427,84 +387,6 @@ Future<void> writeFirebaseJsonFile(
file.writeAsStringSync(mapJson);
}

Future<void> writeDebugSymbolScriptForTarget(
bool? generateDebugSymbolScript,
String xcodeProjFilePath,
String appId,
Logger logger,
String name,
String platform,
) async {
// ignore: use_if_null_to_convert_nulls_to_bools
if (generateDebugSymbolScript == true) {
await writeDebugScriptForTarget(
xcodeProjFilePath,
appId,
name,
logger,
);
} else if (generateDebugSymbolScript == false) {
// User has specifically requested no debug symbol script insert.
return;
} else {
// User hasn't specified anything, so we prompt
final addSymbolScript = promptBool(
"Do you want an 'upload Crashlytic's debug symbols script' adding to the build phases of your $platform project's '$name' target?",
);

if (addSymbolScript == true) {
await writeDebugScriptForTarget(
xcodeProjFilePath,
appId,
name,
logger,
);
} else {
logger.stdout(
logSkippingDebugSymbolScript,
);
}
}
}

String addServiceFileToRunnerScript(
String googleServiceInfoFile,
String xcodeProjFilePath,
) {
return '''
require 'xcodeproj'
googleFile='$googleServiceInfoFile'
xcodeFile='$xcodeProjFilePath'
# define the path to your .xcodeproj file
project_path = xcodeFile
# open the xcode project
project = Xcodeproj::Project.open(project_path)
# check if `GoogleService-Info.plist` config is set in `project.pbxproj` file.
googleConfigExists = false
project.files.each do |file|
if file.path == "Runner/GoogleService-Info.plist"
googleConfigExists = true
exit
end
end
# Write only if config doesn't exist
if googleConfigExists == false
file = project.new_file(googleFile)
main_target = project.targets.find { |target| target.name == 'Runner' }
if(main_target)
main_target.add_resources([file])
project.save
else
abort("Could not find target 'Runner' in your Xcode workspace. Please rename your target to 'Runner' and try again.")
end
end
''';
}

String findingSchemesScript(
String xcodeProjFilePath,
) {
Expand Down
Loading

0 comments on commit f8c4264

Please sign in to comment.