buildAppRoutesFile function

String buildAppRoutesFile(
  1. List<FeatureRoute> routes
)

Builds the contents of app_routes.dart from the discovered routes. home is always present as /; every other route is '/<name>'.

Implementation

String buildAppRoutesFile(List<FeatureRoute> routes) {
  final buffer = StringBuffer()
    ..writeln('// GENERATED by `river_cli generate routes`. Re-run to refresh.')
    ..writeln('class AppRoutes {')
    ..writeln('  AppRoutes._();')
    ..writeln()
    ..writeln("  static const String home = '/';");

  for (final r in routes) {
    if (r.isHome) continue;
    buffer.writeln("  static const String ${r.routeName} = '/${r.routeName}';");
  }

  buffer.writeln('}');
  return buffer.toString();
}