Skip to content

Commit 250bb6b

Browse files
initialize firebase and support appending rules
1 parent 98117dd commit 250bb6b

File tree

2 files changed

+32
-4
lines changed

2 files changed

+32
-4
lines changed

bin/flutterflow_cli.dart

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ void main(List<String> args) async {
6262
await firebaseDeploy(
6363
token: token,
6464
projectId: project,
65+
appendRules: parsedArguments.command!['append-rules'],
6566
endpoint: endpoint,
6667
);
6768
break;
@@ -111,7 +112,13 @@ ArgResults _parseArgs(List<String> args) {
111112
);
112113

113114
final firebaseDeployCommandParser = ArgParser()
114-
..addOption('project', abbr: 'p', help: 'Project id');
115+
..addOption('project', abbr: 'p', help: 'Project id')
116+
..addFlag(
117+
'append-rules',
118+
abbr: 'a',
119+
help: 'Append to rules, instead of overwriting them.',
120+
defaultsTo: false,
121+
);
115122

116123
final parser = ArgParser()
117124
..addOption('endpoint', abbr: 'e', help: 'Endpoint', hide: true)

lib/src/flutterflow_api_client.dart

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -283,13 +283,13 @@ Future _runFix({
283283
Future firebaseDeploy({
284284
required String token,
285285
required String projectId,
286+
bool appendRules = false,
286287
String endpoint = kDefaultEndpoint,
287288
}) async {
288289
final endpointUrl = Uri.parse(endpoint);
289290
final body = jsonEncode({
290-
'project': {
291-
'path': 'projects/$projectId',
292-
},
291+
'project': {'path': 'projects/$projectId'},
292+
'append_rules': appendRules,
293293
});
294294
final result = await _callEndpoint(
295295
client: http.Client(),
@@ -333,6 +333,27 @@ Future firebaseDeploy({
333333
);
334334
}
335335

336+
stdout.write('Initializing firebase...\n');
337+
await Process.run(
338+
'firebase',
339+
['use', firebaseProjectId],
340+
workingDirectory: firebaseDir,
341+
runInShell: true,
342+
);
343+
final initHostingProcess = await Process.start(
344+
'firebase',
345+
['init', 'hosting'],
346+
workingDirectory: firebaseDir,
347+
runInShell: true,
348+
);
349+
final initHostingInputStream = Stream.periodic(
350+
Duration(milliseconds: 100),
351+
(count) => utf8.encode('\n'),
352+
);
353+
initHostingProcess.stdin.addStream(initHostingInputStream);
354+
// Make sure hosting is initialized before deploying.
355+
await initHostingProcess.exitCode;
356+
336357
final deployProcess = await Process.start(
337358
'firebase',
338359
['deploy', '--project', firebaseProjectId],

0 commit comments

Comments
 (0)