handleGenerateConfigs function

Future<void> handleGenerateConfigs([
  1. Map<String, dynamic>? args
])

Generate Firebase configuration files.

When --hybrid-dynamic-prefix <p1,p2,...> is supplied the supplied prefixes overwrite HYBRID_DYNAMIC_PREFIXES in setup_config.env before regenerating firebase.json. This is the supported workflow for managing the per-mode rewrites delivered in T5.4 / T7.1 of the 2026-05-10 build/deploy/rendering-modes plan.

Implementation

Future<void> handleGenerateConfigs([Map<String, dynamic>? args]) async {
  final config = await ProjectConfigLoader.load();
  if (config == null) {
    ProjectConfigLoader.printMissingConfigHelp();
    return;
  }

  // Optionally override the hybrid dynamic prefixes the user wants Firebase
  // Hosting to rewrite to the Jaspr Cloud Run service. Accepts a single
  // comma-separated string ("/api,/auth,/admin") which is the most ergonomic
  // shape for the darted_cli single-value argument model.
  final String? raw = args == null
      ? null
      : args['hybrid-dynamic-prefix']?.toString();
  if (raw != null && raw.trim().isNotEmpty) {
    final List<String> requested = raw
        .split(RegExp('[,\\s]+'))
        .map((String s) => s.trim())
        .where((String s) => s.isNotEmpty)
        .map((String s) => s.startsWith('/') ? s : '/$s')
        .toList(growable: false);
    if (requested.isEmpty) {
      error('No valid prefixes parsed from --hybrid-dynamic-prefix.');
      return;
    }
    if (!config.template.isJasprApp ||
        config.jasprRenderMode != JasprRenderMode.hybrid) {
      info(
        '--hybrid-dynamic-prefix is only effective for Jaspr templates in '
        'hybrid render mode. The value will still be persisted to '
        'setup_config.env for future runs.',
      );
    }

    final SetupConfig updated = config.copyWith(
      hybridDynamicPrefixes: requested,
    );
    final String? configPath = _findExistingConfigPath();
    if (configPath == null) {
      error('Unable to locate setup_config.env on disk to persist update.');
      return;
    }
    await updated.saveToFile(configPath);
    info(
      'Updated HYBRID_DYNAMIC_PREFIXES in setup_config.env: '
      '${requested.join(', ')}',
    );

    final ConfigGenerator configGen = ConfigGenerator(updated);
    await configGen.generateAll();
    return;
  }

  final ConfigGenerator configGen = ConfigGenerator(config);
  await configGen.generateAll();
}