@@ -283,15 +283,13 @@ Future _runFix({
283283Future firebaseDeploy ({
284284 required String token,
285285 required String projectId,
286- required String destinationPath,
287286 String endpoint = kDefaultEndpoint,
288287}) async {
289288 final endpointUrl = Uri .parse (endpoint);
290289 final body = jsonEncode ({
291290 'project' : {
292291 'path' : 'projects/$projectId ' ,
293292 },
294- 'token' : token,
295293 });
296294 final result = await _callEndpoint (
297295 client: http.Client (),
@@ -304,47 +302,51 @@ Future firebaseDeploy({
304302 // Download actual code
305303 final projectZipBytes = base64Decode (result['firebase_zip' ]);
306304 final firebaseProjectId = result['firebase_project_id' ];
305+ final tmpFolder =
306+ Directory .systemTemp.createTempSync ('${projectId }_$firebaseProjectId ' );
307307 final projectFolder = ZipDecoder ().decodeBytes (projectZipBytes);
308- extractArchiveToCurrentDirectory (projectFolder, destinationPath);
309- final firebaseDir = '$destinationPath /firebase' ;
310-
311- // Install required modules for deployment.
312- await Process .run (
313- 'npm' ,
314- ['install' ],
315- workingDirectory: '$firebaseDir /functions' ,
316- runInShell: true ,
317- stdoutEncoding: utf8,
318- stderrEncoding: utf8,
319- );
320- final directoriesResult = await Process .run (
321- 'ls' ,
322- [],
323- workingDirectory: firebaseDir,
324- runInShell: true ,
325- stdoutEncoding: utf8,
326- stderrEncoding: utf8,
327- );
308+ extractArchiveToCurrentDirectory (projectFolder, tmpFolder.path);
309+ final firebaseDir = '${tmpFolder .path }/firebase' ;
328310
329- // This directory only exists if there were custom cloud functions.
330- if (directoriesResult.stdout. contains ( 'custom_cloud_functions' )) {
311+ try {
312+ // Install required modules for deployment.
331313 await Process .run (
332314 'npm' ,
333315 ['install' ],
334- workingDirectory: '$firebaseDir /custom_cloud_functions ' ,
316+ workingDirectory: '$firebaseDir /functions ' ,
335317 runInShell: true ,
336318 stdoutEncoding: utf8,
337319 stderrEncoding: utf8,
338320 );
339- }
321+ final directoriesResult = tmpFolder. listSync (recursive : true );
340322
341- final deployProcess = await Process .start (
342- 'firebase' ,
343- ['deploy' , '--project' , firebaseProjectId],
344- workingDirectory: firebaseDir,
345- runInShell: true ,
346- );
347- // There may be a need for the user to interactively provide inputs.
348- deployProcess.stdout.transform (utf8.decoder).forEach (print);
349- deployProcess.stdin.addStream (stdin);
323+ // This directory only exists if there were custom cloud functions.
324+ if (directoriesResult.map ((f) => f.path).any (
325+ (path) => path.startsWith ('$firebaseDir /custom_cloud_functions' ))) {
326+ await Process .run (
327+ 'npm' ,
328+ ['install' ],
329+ workingDirectory: '$firebaseDir /custom_cloud_functions' ,
330+ runInShell: true ,
331+ stdoutEncoding: utf8,
332+ stderrEncoding: utf8,
333+ );
334+ }
335+
336+ final deployProcess = await Process .start (
337+ 'firebase' ,
338+ ['deploy' , '--project' , firebaseProjectId],
339+ workingDirectory: firebaseDir,
340+ runInShell: true ,
341+ );
342+ // There may be a need for the user to interactively provide inputs.
343+ deployProcess.stdout.transform (utf8.decoder).forEach (print);
344+ deployProcess.stdin.addStream (stdin);
345+ final exitCode = await deployProcess.exitCode;
346+ if (exitCode != 0 ) {
347+ stderr.write ('Failed to deploy to Firebase.\n ' );
348+ }
349+ } finally {
350+ tmpFolder.deleteSync (recursive: true );
351+ }
350352}
0 commit comments