UNPKG

2.88 kBJavaScriptView Raw
1"use strict";
2Object.defineProperty(exports, "__esModule", { value: true });
3var fileDescriptorTSD_1 = require("./ts/fileDescriptorTSD");
4var ExportMap_1 = require("./ExportMap");
5var util_1 = require("./util");
6var plugin_pb_1 = require("google-protobuf/google/protobuf/compiler/plugin_pb");
7var grpcweb_1 = require("./service/grpcweb");
8var grpcnode_1 = require("./service/grpcnode");
9var parameters_1 = require("./parameters");
10util_1.withAllStdIn(function (inputBuff) {
11 try {
12 var typedInputBuff = new Uint8Array(inputBuff.length);
13 typedInputBuff.set(inputBuff);
14 var codeGenRequest = plugin_pb_1.CodeGeneratorRequest.deserializeBinary(typedInputBuff);
15 var codeGenResponse_1 = new plugin_pb_1.CodeGeneratorResponse();
16 codeGenResponse_1.setSupportedFeatures(plugin_pb_1.CodeGeneratorResponse.Feature.FEATURE_PROTO3_OPTIONAL);
17 var exportMap_1 = new ExportMap_1.ExportMap();
18 var fileNameToDescriptor_1 = {};
19 var parameter = codeGenRequest.getParameter();
20 var _a = util_1.getParameterEnums(parameter || ""), service = _a.service, mode_1 = _a.mode;
21 var generateGrpcWebServices_1 = service === parameters_1.ServiceParameter.GrpcWeb;
22 var generateGrpcNodeServices_1 = service === parameters_1.ServiceParameter.GrpcNode;
23 codeGenRequest.getProtoFileList().forEach(function (protoFileDescriptor) {
24 var fileDescriptorName = protoFileDescriptor.getName() || util_1.throwError("Missing file descriptor name");
25 fileNameToDescriptor_1[fileDescriptorName] = protoFileDescriptor;
26 exportMap_1.addFileDescriptor(protoFileDescriptor);
27 });
28 codeGenRequest.getFileToGenerateList().forEach(function (fileName) {
29 var outputFileName = util_1.replaceProtoSuffix(fileName);
30 var thisFile = new plugin_pb_1.CodeGeneratorResponse.File();
31 thisFile.setName(outputFileName + ".d.ts");
32 thisFile.setContent(fileDescriptorTSD_1.printFileDescriptorTSD(fileNameToDescriptor_1[fileName], exportMap_1));
33 codeGenResponse_1.addFile(thisFile);
34 if (generateGrpcWebServices_1) {
35 grpcweb_1.generateGrpcWebService(outputFileName, fileNameToDescriptor_1[fileName], exportMap_1)
36 .forEach(function (file) { return codeGenResponse_1.addFile(file); });
37 }
38 else if (generateGrpcNodeServices_1) {
39 var file = grpcnode_1.generateGrpcNodeService(outputFileName, fileNameToDescriptor_1[fileName], exportMap_1, mode_1);
40 codeGenResponse_1.addFile(file);
41 }
42 });
43 process.stdout.write(Buffer.from(codeGenResponse_1.serializeBinary().buffer));
44 }
45 catch (err) {
46 console.error("protoc-gen-ts error: " + err.stack + "\n");
47 process.exit(1);
48 }
49});
50//# sourceMappingURL=index.js.map
\No newline at end of file