useCaseBuilder function

Builder useCaseBuilder(
  1. BuilderOptions options
)

Builder for the UseCase annotation. Creates a .usecase.widgetbook.json file for each .dart file containing the UseCase annotation. The file contains a list of UseCaseMetadata json objects representing the annotated elements. These files are used later on by other builders to generate more code.

Implementation

Builder useCaseBuilder(BuilderOptions options) {
  final navPathModeConfig = options.config['nav_path_mode'] as String;
  final navPathMode = parseNavPathMode(navPathModeConfig);

  return JsonBuilder(
    UseCaseGenerator(navPathMode),
    generatedExtension: '.usecase.widgetbook.json',
    formatOutput: (input) {
      // [GeneratorForAnnotation] joins the JSON objects by two newlines,
      // we replace that by a comma, and we surround the whole thing with
      // square brackets to make it a valid JSON list.
      final joined = input.replaceAll('\n\n', ',\n');
      return '[$joined]';
    },
  );
}