Skip to content

Commit

Permalink
fix: error in generated grpc code
Browse files Browse the repository at this point in the history
  • Loading branch information
kincaidoneil committed Mar 5, 2019
1 parent b84a500 commit c0d9531
Showing 1 changed file with 23 additions and 12 deletions.
35 changes: 23 additions & 12 deletions generate.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,28 +16,39 @@ async function run() {
// Generate JS via grpc-tools
await shell(
`./node_modules/.bin/grpc_tools_node_protoc ` +
`--plugin="protoc-gen-grpc=./node_modules/.bin/grpc_tools_node_protoc_plugin" ` +
`--js_out="import_style=commonjs,binary:${outDir}" ` +
`--grpc_out="${outDir}" ` +
`--proto_path="./src/proto" ` +
`--proto_path="./node_modules/protobufjs" ` +
`./src/proto/*.proto`
`--plugin="protoc-gen-grpc=./node_modules/.bin/grpc_tools_node_protoc_plugin" ` +
`--js_out="import_style=commonjs,binary:${outDir}" ` +
`--grpc_out="${outDir}" ` +
`--proto_path="./src/proto" ` +
`--proto_path="./node_modules/protobufjs" ` +
`./src/proto/*.proto`
)

// Generate TypeScript declarations
await shell(
`./node_modules/grpc-tools/bin/protoc ` +
`--plugin="protoc-gen-ts=./node_modules/grpc_tools_node_protoc_ts/bin/protoc-gen-ts" ` +
`--ts_out="${outDir}" ` +
`--proto_path="./src/proto" ` +
`--proto_path="./node_modules/protobufjs" ` +
`./src/proto/*.proto`
`--plugin="protoc-gen-ts=./node_modules/grpc_tools_node_protoc_ts/bin/protoc-gen-ts" ` +
`--ts_out="${outDir}" ` +
`--proto_path="./src/proto" ` +
`--proto_path="./node_modules/protobufjs" ` +
`./src/proto/*.proto`
)

// Remove unused imports that cause errors
const removeReference = path =>
promisify(readFile)(path, 'utf8')
.then(data => data.replace(`var google_api_annotations_pb = require('./google/api/annotations_pb.js');`, ''))
.then(data =>
data.replace(
`var google_api_annotations_pb = require('./google/api/annotations_pb.js');`,
''
)
)
.then(data =>
data.replace(
`goog.object.extend(proto, google_api_annotations_pb);`,
''
)
)
.then(data => promisify(writeFile)(path, data))

await removeReference(resolve('./generated/rpc_grpc_pb.js'))
Expand Down

0 comments on commit c0d9531

Please sign in to comment.