routeFileMaker function

PartFile routeFileMaker(
  1. ServerParentRoute route,
  2. String format(
    1. Spec
    )
)

Implementation

PartFile routeFileMaker(
  ServerParentRoute route,
  String Function(Spec) format,
) {
  final closure = Method(
    (p) => p
      ..name = route.handlerName
      ..returns = refer((Route).name)
      ..requiredParameters.addAll([
        Parameter(
          (b) => b
            ..name = route.className.toCamelCase()
            ..type = refer(route.className),
        ),
        Parameter(
          (b) => b
            ..name = 'di'
            ..type = refer((DI).name),
        ),
      ])
      ..body = Block.of([
        refer((Route).name)
            .newInstance([
              literalString(route.routePath),
            ], {
              ...createRouteArgs(
                route: route,
                classVarName: route.classVarName,
              ),
              if (route.routes.isNotEmpty)
                'routes': literalList([
                  for (final child in route.routes)
                    createChildRoute(child, route),
                ]),
            })
            .returned
            .statement,
      ]),
  );

  return PartFile(
    path: ['routes', '__${route.fileName}'],
    content: format(closure),
  );
}