generator function
Prisma generator
Implementation
Future<void> generator(Handler handler) async {
final input = stdin.transform(utf8.decoder).transform(const LineSplitter());
final controller = StreamController<String>();
// Listen the output stream, write to stderr
controller.stream.listen((event) => stderr.writeln(event));
final channel = StreamChannel<String>(input, controller.sink);
final server = Server(channel);
// Register the manifest method
server.registerMethod('getManifest', (Parameters params) async {
final config = GeneratorConfig.fromJson(params.asMap.cast());
final manifest = await handler.onManifest(config);
return {
'manifest': manifest.toJson(),
};
});
// Register the generate method
server.registerMethod('generate', (Parameters params) async {
final options = GeneratorOptions.fromJson(params.asMap.cast());
await handler.onGenerate(options);
});
// Listen for requests
await server.listen();
}