handleHostingInit function

Future<void> handleHostingInit()

Create the <project>-beta site and apply hosting targets (T6).

Implementation

Future<void> handleHostingInit() async {
  final SetupConfig? config = await requireFirebaseProjectConfig();
  if (config == null) return;
  if (!SetupGuidance.supportsWebHosting(config)) {
    error('This project does not produce a web build; nothing to host.');
    return;
  }

  final HostingSiteManager hosting = HostingSiteManager(
    config.firebaseProjectId!,
    workingDirectory: config.outputDir,
  );

  info('Verifying release hosting site `${config.firebaseProjectId}`...');
  final SiteEnsureResult release = await hosting.ensureReleaseSite();
  _printSiteResult(release, role: 'release');

  info('Ensuring beta hosting site `${hosting.betaSiteId}`...');
  final SiteEnsureResult beta = await hosting.ensureBetaSite();
  _printSiteResult(beta, role: 'beta');

  info('Applying hosting targets...');
  final ApplyTargetsResult apply = await hosting.applyTargets();
  if (apply.success) {
    success('Hosting targets applied (release + beta).');
  } else {
    error('Failed to apply hosting targets: ${apply.message}');
  }

  print('');
  if (release.success && beta.success && apply.success) {
    success('Hosting init complete. You can now run:');
    UserPrompt.printList(<String>[
      '  oracular deploy hosting',
      '  oracular deploy hosting-beta',
      'Live URLs once deployed:',
      '  ${release.webAppUrl}',
      '  ${beta.webAppUrl}',
    ]);
  }
}