launchWithTui static method

Future<void> launchWithTui(
  1. Client cloudApiClient,
  2. FileUploaderFactory fileUploaderFactory, {
  3. required CommandLogger logger,
  4. required ProjectLaunch projectSetup,
  5. required String consoleServer,
  6. required bool openBrowser,
  7. required int deployConcurrency,
  8. required bool deployDryRun,
  9. required bool deployShowFiles,
  10. String? deployOutputPath,
  11. bool deploySkipTailingStatus = false,
})

Implementation

static Future<void> launchWithTui(
  final Client cloudApiClient,
  final FileUploaderFactory fileUploaderFactory, {
  required final CommandLogger logger,
  required final ProjectLaunch projectSetup,
  required final String consoleServer,
  required final bool openBrowser,
  required final int deployConcurrency,
  required final bool deployDryRun,
  required final bool deployShowFiles,
  final String? deployOutputPath,
  final bool deploySkipTailingStatus = false,
}) async {
  final defaultProjectId = _getDefaultProjectId(projectSetup);

  final existingProjects = await _fetchExistingUndeployedProjects(
    cloudApiClient,
  );
  final existingProjectIds = existingProjects
      .map((final p) => p.cloudProjectId)
      .toList();

  final state = LaunchConfigState(
    projectSetup: projectSetup,
    defaultProjectId: defaultProjectId,
    existingProjectIds: existingProjectIds,
  );
  final holder = LaunchAppStateHolder(state);

  final tuiWriter = TuiLogWriter()..attach(holder);
  final tuiLogger = ServerpodCliLogger(tuiWriter);

  // Hook up the TUI logger for structured logs in the TUI.
  logger.initializeWith(tuiLogger);

  await runTuiApp(
    ScloudLaunchApp(
      holder: holder,
      onLaunch: () async {
        // Update UI to show logs from the launch
        state.markLaunchingProject();
        holder.markDirty();

        final stdoutController = StreamController<List<int>>();
        stdoutController.stream
            .transform(const Utf8Decoder(allowMalformed: true))
            .transform(const LineSplitter())
            .listen(logger.debug);
        final toDebugLog = IOSink(stdoutController);
        final stderrController = StreamController<List<int>>();
        stderrController.stream
            .transform(const Utf8Decoder(allowMalformed: true))
            .transform(const LineSplitter())
            .listen(logger.error);
        final toErrorLog = IOSink(stderrController);

        await performLaunch(
          cloudApiClient,
          fileUploaderFactory,
          logger,
          state.projectSetup,
          consoleServer: consoleServer,
          openBrowser: openBrowser,
          stdout: toDebugLog,
          stderr: toErrorLog,
          deployConcurrency: deployConcurrency,
          deployDryRun: deployDryRun,
          deployShowFiles: deployShowFiles,
          deployOutputPath: deployOutputPath,
          deploySkipTailingStatus: deploySkipTailingStatus,
        );
      },
      onQuit: () {
        /// Reset to the default logger for post-tui logs.
        logger.reset();
        shutdownTuiApp();
      },
    ),
  );
}