Skip to content

Commit

Permalink
refactor: cleaned up code
Browse files Browse the repository at this point in the history
  • Loading branch information
russellwheatley committed Jan 11, 2023
1 parent 6f16b97 commit 99a92de
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 38 deletions.
6 changes: 3 additions & 3 deletions packages/flutterfire_cli/lib/src/commands/config.dart
Expand Up @@ -274,7 +274,7 @@ class ConfigCommand extends FlutterFireCommand {
if (relativeiOSServiceFilePath == null) {
return null;
}
return '${flutterApp!.package.path}${relativeiOSServiceFilePath!}';
return '${flutterApp!.package.path}/${relativeiOSServiceFilePath!}';
}

String? get androidServiceFilePath {
Expand Down Expand Up @@ -614,7 +614,7 @@ class ConfigCommand extends FlutterFireCommand {
iosOptions,
flutterApp,
fulliOSServicePath,
relativeiOSServiceFilePath,
fulliOSServicePath == null,
logger,
iosGenerateDebugSymbolScript,
iosScheme,
Expand All @@ -628,7 +628,7 @@ class ConfigCommand extends FlutterFireCommand {
macosOptions,
flutterApp,
fullMacOSServicePath,
macosServiceFilePath,
fullMacOSServicePath == null,
logger,
macosGenerateDebugSymbolScript,
macosScheme,
Expand Down
5 changes: 2 additions & 3 deletions packages/flutterfire_cli/lib/src/common/utils.dart
Expand Up @@ -324,7 +324,7 @@ Future<void> writeSchemeScriptToProject(
xcodeProjFilePath,
scheme,
runScriptName,
removeForwardSlash(serviceFilePath),
serviceFilePath,
);

// Add script to Build Phases in Xcode project
Expand Down Expand Up @@ -602,8 +602,7 @@ bashScript = %q(
PLIST_DESTINATION=\${BUILT_PRODUCTS_DIR}/\${PRODUCT_NAME}.app
# Remove the "ios" segment from the SOURCE_ROOT environment variable as it could already be on "googleServiceFilePath"
GOOGLESERVICE_INFO_PATH=\${SOURCE_ROOT%/*}
GOOGLESERVICE_INFO_PATH=\${GOOGLESERVICE_INFO_PATH}/$googleServiceFilePath
GOOGLESERVICE_INFO_PATH=$googleServiceFilePath
# Copy GoogleService-Info.plist for appropriate scheme. Each scheme has multiple configurations (i.e. Debug-development, Debug-staging, etc).
# This is why we use *"scheme"*
Expand Down
57 changes: 25 additions & 32 deletions packages/flutterfire_cli/lib/src/firebase/firebase_apple_setup.dart
Expand Up @@ -16,7 +16,7 @@ class FirebaseAppleSetup {
this.platformOptions,
this.flutterApp,
this.fullPathToServiceFile,
this.relativePathToServiceFile,
this.isDefaultSetup,
this.logger,
this.generateDebugSymbolScript,
this.scheme,
Expand All @@ -28,7 +28,7 @@ class FirebaseAppleSetup {
final FlutterApp? flutterApp;
final FirebaseOptions platformOptions;
String? fullPathToServiceFile;
String? relativePathToServiceFile;
bool isDefaultSetup;
final Logger logger;
final bool? generateDebugSymbolScript;
// This allows us to update to the required "GoogleService-Info.plist" file name for iOS target or scheme writes.
Expand Down Expand Up @@ -116,6 +116,14 @@ end
final uploadDebugSymbolsName = 'uploadDebugSymbols';
final pathToServiceFileOutput = 'serviceFileOutput';

String get googleServiceInfoFile {
return path.join(
flutterApp!.iosDirectory.path,
'Runner',
platformOptions.optionsSourceFileName,
);
}

Future<void> _updateFirebaseJsonFileScheme(
FlutterApp flutterApp,
String appId,
Expand Down Expand Up @@ -268,15 +276,15 @@ end
}
}

Future<void> apply() async {
final googleServiceInfoFile = path.join(
flutterApp!.iosDirectory.path,
'Runner',
platformOptions.optionsSourceFileName,
);
Future<File> _createFileToSpecifiedPath(
String pathToServiceFile,
) async {
await Directory(path.dirname(pathToServiceFile)).create(recursive: true);

File file;
return File(fullPathToServiceFile!);
}

Future<void> apply() async {
if (scheme != null && fullPathToServiceFile == null) {
// if the user has selected a scheme but no "[ios-macos]-out" argument, they need to specify the location of "GoogleService-Info.plist" so it can be used at build time.
// No need to do the same for target as it is included with bundle resources and included in Runner directory
Expand All @@ -295,16 +303,9 @@ end
fullPathToServiceFile =
'${flutterApp!.package.path}/$pathToServiceFile/${platformOptions.optionsSourceFileName}';

relativePathToServiceFile =
'$pathToServiceFile/${platformOptions.optionsSourceFileName}';

await Directory(path.dirname(fullPathToServiceFile!))
.create(recursive: true);

file = File(fullPathToServiceFile!);
// If "fullPathToServiceFile" exists, we use a different configuration from Runner/GoogleService-Info.plist setup
} else if (fullPathToServiceFile != null) {
final googleServiceFileName = path.basename(relativePathToServiceFile!);
final googleServiceFileName = path.basename(fullPathToServiceFile!);

if (googleServiceFileName != platformOptions.optionsSourceFileName) {
final response = promptBool(
Expand All @@ -313,30 +314,22 @@ end

// Change filename to "GoogleService-Info.plist" if user wants to, it is required for target or scheme setup
if (response == true) {
relativePathToServiceFile = path.join(
path.dirname(relativePathToServiceFile!),
platformOptions.optionsSourceFileName,
);

fullPathToServiceFile =
'${flutterApp!.package.path}${relativePathToServiceFile!}';
'${path.dirname(fullPathToServiceFile!)}/${platformOptions.optionsSourceFileName}';
}
}
// Create new directory for file output if it doesn't currently exist
await Directory(path.dirname(fullPathToServiceFile!))
.create(recursive: true);

file = File(fullPathToServiceFile!);
} else {
file = File(googleServiceInfoFile);
fullPathToServiceFile = googleServiceInfoFile;
}

final file = await _createFileToSpecifiedPath(fullPathToServiceFile!);

if (!file.existsSync()) {
await file.writeAsString(platformOptions.optionsSourceContent);
}

if (Platform.isMacOS) {
if (fullPathToServiceFile != null) {
if (!isDefaultSetup) {
if (scheme != null) {
final schemes = await findSchemesAvailable(xcodeProjFilePath);

Expand All @@ -345,7 +338,7 @@ end
if (schemeExists) {
await writeSchemeScriptToProject(
xcodeProjFilePath,
relativePathToServiceFile!,
fullPathToServiceFile!,
scheme!,
logger,
);
Expand Down Expand Up @@ -407,7 +400,7 @@ end
);
await writeSchemeScriptToProject(
xcodeProjFilePath,
relativePathToServiceFile!,
fullPathToServiceFile!,
schemes[response],
logger,
);
Expand Down

0 comments on commit 99a92de

Please sign in to comment.