Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 15 additions & 6 deletions packages/flutterfire_cli/lib/src/commands/config.dart
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,12 @@ class ConfigCommand extends FlutterFireCommand {
'Where to write the `google-services.json` file to be written for android platform. Useful for different flavors',
);

argParser.addOption(
kFirebaseOutFlag,
valueHelp: 'filePath',
help: 'The output file path of the `firebase.json` file that will be generated or updated.',
);

argParser.addFlag(
kOverwriteFirebaseOptionsFlag,
abbr: 'f',
Expand Down Expand Up @@ -345,6 +351,12 @@ class ConfigCommand extends FlutterFireCommand {
return argResults!['out'] as String;
}

String get firebaseJsonPath {
final customPath = argResults![kFirebaseOutFlag] as String?;
if (customPath != null) return customPath;
return path.join(flutterApp!.package.path, 'firebase.json');
}
Comment thread
kevmoo marked this conversation as resolved.

bool get overwriteFirebaseOptions {
if (argResults!['overwrite-firebase-options'] == null) {
return false;
Expand Down Expand Up @@ -536,8 +548,6 @@ class ConfigCommand extends FlutterFireCommand {
}

Future<bool> checkIfUserRequiresReconfigure() async {
final firebaseJsonPath =
path.join(flutterApp!.package.path, 'firebase.json');
final file = File(firebaseJsonPath);

if (file.existsSync()) {
Expand All @@ -550,7 +560,7 @@ class ConfigCommand extends FlutterFireCommand {
);

if (reuseFirebaseJsonValues) {
final reconfigure = Reconfigure(flutterApp, token: testAccessToken);
final reconfigure = Reconfigure(flutterApp, token: testAccessToken, firebaseJsonPath: firebaseJsonPath);
reconfigure.logger = logger;
await reconfigure.run();
return true;
Expand Down Expand Up @@ -705,12 +715,11 @@ class ConfigCommand extends FlutterFireCommand {
firebaseJsonWrites.add(firebaseJsonWrite);
}

// 5. Writes for "firebase.json" file in root of project
// 5. Writes for "firebase.json" file
if (firebaseJsonWrites.isNotEmpty) {
await writeToFirebaseJson(
listOfWrites: firebaseJsonWrites,
firebaseJsonPath:
path.join(flutterApp!.package.path, 'firebase.json'),
firebaseJsonPath: firebaseJsonPath,
);
}

Expand Down
21 changes: 16 additions & 5 deletions packages/flutterfire_cli/lib/src/commands/reconfigure.dart
Original file line number Diff line number Diff line change
Expand Up @@ -56,18 +56,26 @@ class ConfigFileWrite {
}

class Reconfigure extends FlutterFireCommand {
Reconfigure(FlutterApp? flutterApp, {String? token}) : super(flutterApp) {
Reconfigure(FlutterApp? flutterApp, {String? token, String? firebaseJsonPath}) : super(flutterApp) {
setupDefaultFirebaseCliOptions();
_accessToken = token;
_firebaseJsonPath = firebaseJsonPath;
argParser.addOption(
'ci-access-token',
valueHelp: 'ciAccessToken',
hide: true,
help:
'Set the access token for making Firebase API requests. Required for CI environment.',
);
argParser.addOption(
kFirebaseOutFlag,
valueHelp: 'filePath',
help: 'The path to the `firebase.json` file.',
);
Comment thread
russellwheatley marked this conversation as resolved.
}

String? _firebaseJsonPath;

@override
final String description =
'Updates the configurations for all build variants included in the "firebase.json" added by running `flutterfire configure`.';
Expand Down Expand Up @@ -378,11 +386,14 @@ class Reconfigure extends FlutterFireCommand {
Future<void> run() async {
try {
commandRequiresFlutterApp();
final customPath = argResults != null ? argResults![kFirebaseOutFlag] as String? : null;
final firebaseJson = File(
path.join(
flutterApp!.package.path,
'firebase.json',
),
_firebaseJsonPath ??
customPath ??
path.join(
flutterApp!.package.path,
'firebase.json',
),
);
Comment thread
kevmoo marked this conversation as resolved.
Outdated

if (!firebaseJson.existsSync()) {
Expand Down
1 change: 1 addition & 0 deletions packages/flutterfire_cli/lib/src/common/utils.dart
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ const String kMacosTargetFlag = 'macos-target';
const String kIosOutFlag = 'ios-out';
const String kMacosOutFlag = 'macos-out';
const String kAndroidOutFlag = 'android-out';
const String kFirebaseOutFlag = 'firebase-out';
const String kOverwriteFirebaseOptionsFlag = 'overwrite-firebase-options';
const String kTestAccessTokenFlag = 'test-access-token';

Expand Down
48 changes: 48 additions & 0 deletions packages/flutterfire_cli/test/configure_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -1740,4 +1740,52 @@ void main() {
Duration(minutes: 3),
),
);

test('flutterfire configure: --firebase-out flag should dictate where firebase.json is written', () async {
// Install flutterfire_cli from local path
final installDevDependency = Process.runSync(
'flutter',
[
'pub',
'add',
'--dev',
'flutterfire_cli',
'--path=${Directory.current.path}',
],
workingDirectory: projectPath,
);

if (installDevDependency.exitCode != 0) {
fail(installDevDependency.stderr as String);
Comment on lines +1746 to +1759
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

don't need to install dev, it should be available already. See other tests.

}

const customFirebaseJsonPath = 'custom/firebase.json';
final result = Process.runSync(
'dart',
[
'run',
'flutterfire_cli:flutterfire',
'configure',
'--yes',
'--project=$firebaseProjectId',
'--platforms=android',
'--firebase-out=$customFirebaseJsonPath',
],
workingDirectory: projectPath,
runInShell: true,
);
Comment on lines +1763 to +1776
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

using dev dependency again, see other tests.


if (result.exitCode != 0) {
fail(result.stderr as String);
}

// check custom "firebase.json" was created and has correct content
final firebaseJsonFile = p.join(projectPath!, 'custom', 'firebase.json');
expect(File(firebaseJsonFile).existsSync(), true);

final firebaseJsonFileContent = await File(firebaseJsonFile).readAsString();
final decodedFirebaseJson = jsonDecode(firebaseJsonFileContent) as Map<String, dynamic>;

expect(decodedFirebaseJson[kFlutter], isNotNull);
});
}
Loading