generateFiles method

List<CodeGeneratorResponse_File> generateFiles(
  1. OutputConfiguration config
)

Generates all the Dart files for this .proto file.

Implementation

List<CodeGeneratorResponse_File> generateFiles(OutputConfiguration config) {
  if (!_linked) throw StateError('not linked');

  CodeGeneratorResponse_File makeFile(String extension, String content) {
    final protoUrl = Uri.file(descriptor.name);
    final dartUrl = config.outputPathFor(protoUrl, extension);
    return CodeGeneratorResponse_File()
      ..name = dartUrl.path
      ..content = content;
  }

  final mainWriter = generateMainFile(config);
  final enumWriter = generateEnumFile(config);

  final files = [
    makeFile('.pb.dart', mainWriter.toString()),
    makeFile('.pbenum.dart', enumWriter.toString()),
    makeFile('.pbjson.dart', generateJsonFile(config)),
  ];

  if (options.generateMetadata) {
    files.addAll([
      makeFile('.pb.dart.meta',
          mainWriter.sourceLocationInfo.writeToJson().toString()),
      makeFile('.pbenum.dart.meta',
          enumWriter.sourceLocationInfo.writeToJson().toString())
    ]);
  }
  if (options.useGrpc) {
    if (grpcGenerators.isNotEmpty) {
      files.add(makeFile('.pbgrpc.dart', generateGrpcFile(config)));
    }
  } else {
    files.add(makeFile('.pbserver.dart', generateServerFile(config)));
  }
  return files;
}