Skip to content

Commit

Permalink
feat: add GoogleServices file and update pbxproj file
Browse files Browse the repository at this point in the history
  • Loading branch information
russellwheatley committed May 12, 2022
1 parent 723f979 commit 1a3e945
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 1 deletion.
32 changes: 31 additions & 1 deletion packages/flutterfire_cli/lib/src/commands/config.dart
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
*/

import 'package:ansi_styles/ansi_styles.dart';
import 'package:path/path.dart' as path;
import 'dart:io';

import '../common/platform.dart';
import '../common/strings.dart';
Expand Down Expand Up @@ -199,7 +201,7 @@ class ConfigCommand extends FlutterFireCommand {
if (!done) {
return 'Creating new Firebase project ${AnsiStyles.cyan(newProjectId)}...';
}
return 'New Firebase project ${AnsiStyles.cyan(newProjectId)} created succesfully.';
return 'New Firebase project ${AnsiStyles.cyan(newProjectId)} created successfully.';
},
);
final newProject = await firebase.createProject(
Expand Down Expand Up @@ -395,6 +397,34 @@ class ConfigCommand extends FlutterFireCommand {
);
}

if (iosOptions != null) {
final googleServiceInfoFile = path.join(flutterApp!.iosDirectory.path, 'Runner',
iosOptions.optionsSourceFileName);

final file = File(googleServiceInfoFile);

await file.writeAsString(iosOptions.optionsSourceContent);
//check exists here. write if not.

final pathToScript = path.split(Platform.script.toFilePath());

final sourceDirIndex = pathToScript.indexOf('.dart_tool');

final listToPbxScriptDir = pathToScript.sublist(0, sourceDirIndex);

final pathToPbxScript = path.joinAll([...listToPbxScriptDir, 'scripts', 'set_ios_pbxproj_file.rb']);

final xcodeProjFilePath = path.join(flutterApp!.iosDirectory.path, 'Runner.xcodeproj');


//TODO -check if google file already exists in project.pbxproj (update if not) & check if google file exists (update if not).
if (Platform.isMacOS) {
final result = await Process.run('ruby', [ pathToPbxScript,'--googleFile=$googleServiceInfoFile','--xcodeFile=$xcodeProjFilePath']);
print('stdout: ${result.stdout}');
print('stderr: ${result.stderr}');
}
}

await Future.wait<void>(futures);

logger.stdout('');
Expand Down
28 changes: 28 additions & 0 deletions scripts/set_ios_pbxproj_file.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
require 'xcodeproj'
require 'optparse'


options = {}
OptionParser.new do |parser|
parser.banner = "Update project.pbxproj file for Xcode project."

parser.on("-x", "--xcodeFile=XCODEFILE", String, "File path of [PROJECT NAME].xcodeproj for adding file") do |xcodeFile|
options[:xcodeFile] = xcodeFile
end

parser.on("-g", "--googleFile=GOOGLEFILE", String, "File path for GoogleService-Info.plist to add to xcode project") do |googleFile|
options[:googleFile] = googleFile
end

end.parse!

# define the path to your .xcodeproj file
project_path = options[:xcodeFile]
# open the xcode project
project = Xcodeproj::Project.open(project_path)
# add GoogleService-Info.plist to your xcode project
file = project.new_file(options[:googleFile])
# save it
project.save

puts "Updated project.pbxproj file for Xcode project with GoogleService-Info.plist."

0 comments on commit 1a3e945

Please sign in to comment.