defineSpryConfig function

void defineSpryConfig({
  1. String? host,
  2. int? port,
  3. BuildTarget? target,
  4. String? routesDir,
  5. String? middlewareDir,
  6. String? publicDir,
  7. String? outputDir,
  8. ReloadStrategy? reload,
  9. String? wranglerConfig,
})

Emits Spry build configuration as JSON for spry.config.dart.

Implementation

void defineSpryConfig({
  /// Overrides the host used by `spry serve`.
  String? host,

  /// Overrides the port used by `spry serve`.
  int? port,

  /// Selects the target runtime.
  BuildTarget? target,

  /// Overrides the routes directory.
  String? routesDir,

  /// Overrides the middleware directory.
  String? middlewareDir,

  /// Overrides the public asset directory.
  String? publicDir,

  /// Overrides the generated output directory.
  String? outputDir,

  /// Overrides the reload strategy used by `spry serve`.
  ReloadStrategy? reload,

  /// Overrides the Wrangler config path for Cloudflare targets.
  String? wranglerConfig,
}) {
  final config = <String, Object>{};
  if (host != null) {
    config['host'] = host;
  }
  if (port != null) {
    config['port'] = port;
  }
  if (target != null) {
    config['target'] = target.name;
  }
  if (routesDir != null) {
    config['routesDir'] = routesDir;
  }
  if (middlewareDir != null) {
    config['middlewareDir'] = middlewareDir;
  }
  if (publicDir != null) {
    config['publicDir'] = publicDir;
  }
  if (outputDir != null) {
    config['outputDir'] = outputDir;
  }
  if (reload != null) {
    config['reload'] = reload.name;
  }
  if (wranglerConfig != null) {
    config['wranglerConfig'] = wranglerConfig;
  }

  stdout.writeln(
    json.encode(config),
  );
}