From 4f990d586329b882f558a2622e09f201ece99e31 Mon Sep 17 00:00:00 2001 From: Dillon Nys Date: Thu, 4 Aug 2022 16:18:54 -0700 Subject: [PATCH] chore: Inherit stdio Inherits stdio in `amplify init` and `amplify push` so that those commands' logs are streamed to the gen process. --- hooks/post_gen.dart | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/hooks/post_gen.dart b/hooks/post_gen.dart index 3d2464b..7e9b957 100644 --- a/hooks/post_gen.dart +++ b/hooks/post_gen.dart @@ -55,16 +55,18 @@ Future _runAmplifyInit(HookContext context) async { 'amplify', ['init', '--yes'], workingDirectory: '{{project_name}}', + mode: ProcessStartMode.inheritStdio, ); + // Complete progress so it doesn't interfere with stdout of `amplify` + amplifyInitProgress.complete(); + final exitCode = await result.exitCode; if (exitCode == 0) { - amplifyInitProgress.complete('Project is initialized.'); + context.logger.success('Project is initialized.'); } else { - final errorBytes = await result.stderr.first; - final error = systemEncoding.decode(errorBytes); - amplifyInitProgress.complete('Project initialization failed. $error'); + context.logger.err('Project initialization failed.'); exit(exitCode); } } @@ -166,20 +168,21 @@ Future _runAmplifyPush(HookContext context, String input) async { 'running "amplify push"', ); - final result = Process.runSync( + final result = await Process.start( 'amplify', ['push', '--yes'], workingDirectory: '{{project_name}}', + mode: ProcessStartMode.inheritStdio, ); + amplifyPushProgress.complete(); + final exitCode = await result.exitCode; if (exitCode == 0) { - amplifyPushProgress.complete('Backend is pushed'); + context.logger.success('Backend is pushed'); } else { - final errorBytes = await result.stderr.first; - final error = systemEncoding.decode(errorBytes); - amplifyPushProgress.complete('Backend push is failed. $error'); + context.logger.err('Backend push failed.'); exit(exitCode); } } else {