forked from woogles-io/liwords
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtasks.py
65 lines (60 loc) · 2.3 KB
/
tasks.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
import os
from invoke import task
code_dir = os.getenv("CODE_DIR", "/Users/cesar/code")
@task
def build_protobuf(c):
# Build the JS for the macondo proto.
c.run(
"protoc "
'--plugin="protoc-gen-ts=liwords-ui/node_modules/.bin/protoc-gen-ts" '
"--ts_out=liwords-ui/src/gen "
"--js_out=import_style=commonjs,binary:liwords-ui/src/gen "
f"--proto_path={code_dir} macondo/api/proto/macondo/macondo.proto"
)
# Build the liwords proto files.
twirp_apis = ["user_service", "game_service"]
for tapi in twirp_apis:
c.run(
"protoc "
f"--twirp_out=rpc --go_out=rpc "
f"--proto_path={code_dir}/ --proto_path={code_dir}/liwords "
"--go_opt=paths=source_relative "
"--twirp_opt=paths=source_relative "
f"api/proto/{tapi}/{tapi}.proto"
)
# create a game_service typescript proto file.
c.run(
"protoc "
'--plugin="protoc-gen-ts=liwords-ui/node_modules/.bin/protoc-gen-ts" '
"--js_out=import_style=commonjs,binary:liwords-ui/src/gen "
f"--ts_out=liwords-ui/src/gen --proto_path={code_dir}/ "
f"--proto_path={code_dir}/liwords "
"api/proto/game_service/game_service.proto"
)
c.run(
"protoc "
f"--go_out=rpc "
f"--proto_path={code_dir}/liwords "
"--go_opt=paths=source_relative "
"api/proto/realtime/ipc.proto"
)
c.run(
"protoc "
'--plugin="protoc-gen-ts=liwords-ui/node_modules/.bin/protoc-gen-ts" '
f"--go_out=rpc "
"--js_out=import_style=commonjs,binary:liwords-ui/src/gen "
f"--ts_out=liwords-ui/src/gen --proto_path={code_dir}/ "
f"--proto_path={code_dir}/liwords "
"--go_opt=paths=source_relative "
"api/proto/realtime/realtime.proto"
)
# Prepend line to disable eslint to generated files. It doesn't work
# if I put them in the .eslintignore file for some reason.
for gen_filename in (
"liwords-ui/src/gen/macondo/api/proto/macondo/macondo_pb.js",
"liwords-ui/src/gen/api/proto/realtime/realtime_pb.js",
):
tmp = c.run("mktemp").stdout.strip()
c.run(r'printf "/* eslint-disable */\n" > ' + tmp)
c.run(f"cat {gen_filename} >> " + tmp)
c.run(f"mv {tmp} {gen_filename}")