Skip to content

Commit

Permalink
feat: new command line args for service file output
Browse files Browse the repository at this point in the history
  • Loading branch information
russellwheatley committed Nov 18, 2022
1 parent 2e1a309 commit c335a26
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 3 deletions.
53 changes: 51 additions & 2 deletions packages/flutterfire_cli/lib/src/commands/config.dart
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,27 @@ class ConfigCommand extends FlutterFireCommand {
help:
'Whether to generate the firebase_app_id.json files used by native iOS and Android builds.',
);

argParser.addOption(
'ios-out',
valueHelp: 'pathForIosConfig',
help:
'Where would you like your `Google-Service-Info.plist` file to be written for iOS platform. Useful for different flavors',
);

argParser.addOption(
'macos-out',
valueHelp: 'pathForMacosConfig',
help:
'Where would you like your `Google-Service-Info.plist` file to be written for macOS platform. Useful for different flavors',
);

argParser.addOption(
'android-out',
valueHelp: 'pathForAndroidConfig',
help:
'Where would you like your `google-services.json` file to be written for android platform. Useful for different flavors',
);
}

@override
Expand Down Expand Up @@ -174,6 +195,18 @@ class ConfigCommand extends FlutterFireCommand {
return argResults!['app-id-json'] as bool;
}

String? get macosServiceFilePath {
return argResults!['macos-out'] as String?;
}

String? get iosServiceFilePath {
return argResults!['ios-out'] as String?;
}

String? get androidServiceFilePath {
return argResults!['android-out'] as String?;
}

String? get androidApplicationId {
final value = argResults!['android-package-name'] as String?;
final deprecatedValue = argResults!['android-app-id'] as String?;
Expand Down Expand Up @@ -507,6 +540,7 @@ class ConfigCommand extends FlutterFireCommand {
flutterApp!,
androidOptions,
logger,
androidServiceFilePath,
).apply(force: isCI || yes),
);
}
Expand All @@ -518,7 +552,14 @@ class ConfigCommand extends FlutterFireCommand {
iosOptions.optionsSourceFileName,
);

final file = File(googleServiceInfoFile);
final file;
if (iosServiceFilePath != null) {
String updatedPath =
'${flutterApp!.package.path}${iosServiceFilePath!}';
file = File(updatedPath);
} else {
file = File(googleServiceInfoFile);
}

if (!file.existsSync()) {
await file.writeAsString(iosOptions.optionsSourceContent);
Expand Down Expand Up @@ -548,7 +589,15 @@ class ConfigCommand extends FlutterFireCommand {
'Runner',
macosOptions.optionsSourceFileName,
);
final file = File(googleServiceInfoFile);

final file;
if (macosServiceFilePath != null) {
String updatedPath =
'${flutterApp!.package.path}${macosServiceFilePath!}';
file = File(updatedPath);
} else {
file = File(googleServiceInfoFile);
}

if (!file.existsSync()) {
await file.writeAsString(macosOptions.optionsSourceContent);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,19 +58,27 @@ class FirebaseAndroidGradlePlugins {
this.flutterApp,
this.firebaseOptions,
this.logger,
this.androidServiceFilePath,
);

final FlutterApp flutterApp;
final FirebaseOptions firebaseOptions;
final Logger logger;
final String? androidServiceFilePath;

File get androidGoogleServicesJsonFile => File(
File get androidGoogleServicesJsonFile {
if (androidServiceFilePath != null) {
return File('${flutterApp.package.path}${androidServiceFilePath!}');
} else {
return File(
path.join(
flutterApp.androidDirectory.path,
'app',
firebaseOptions.optionsSourceFileName,
),
);
}
}

File get androidBuildGradleFile =>
File(path.join(flutterApp.androidDirectory.path, 'build.gradle'));
Expand Down

0 comments on commit c335a26

Please sign in to comment.