launchWithTui static method

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

Implementation

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

  final existingProjects = await _fetchExistingUndeployedProjects(
    cloudApiClient,
  );
  final existingProjectIds = existingProjects
      .map((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,
          baseCommand,
          state.projectSetup,
          consoleServer: consoleServer,
          openBrowser: openBrowser,
          stdout: toDebugLog,
          stderr: toErrorLog,
          deployConcurrency: deployConcurrency,
          wetRun: wetRun,
          deployShowFiles: deployShowFiles,
          deployOutputPath: deployOutputPath,
          deploySkipTailingStatus: deploySkipTailingStatus,
        );
      },
      onQuit: () {
        /// Reset to the default logger for post-tui logs.
        logger.reset();
        shutdownTuiApp();
      },
    ),
  );
}