-
Notifications
You must be signed in to change notification settings - Fork 11
/
dev
executable file
·183 lines (145 loc) · 5.7 KB
/
dev
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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
#!/usr/bin/env python3
# This script is an entrypoint for all developer activities in this project.
import argparse
import os
import subprocess
import sys
def cmd(cmds: argparse._SubParsersAction, name: str, help: str):
"""Decorator that registers subcommands as functions to be executed."""
def wrapper(func):
p = cmds.add_parser(name, help=help)
p.set_defaults(func=func)
return wrapper
def run(cmd: str, args: list = None, capture_output=False, env: dict = None):
"""Helper to run cmd in a shell."""
if args:
if args[0] == "--":
args = args[1:]
cmd += " -- " + " ".join(args)
return subprocess.run(
cmd, check=True, shell=True, capture_output=capture_output, env=env
)
def main():
if not os.getenv("DIRENV_DIR"):
print("Direnv is not enabled. Fix it first! See README.md for instructions.")
sys.exit(1)
cli = argparse.ArgumentParser(
usage="./dev COMMAND [FLAGS...]",
description="CLI for developing Mintter. Provides commands for most common developer tasks in this project.",
)
cmds = cli.add_subparsers(
title="commands",
# This is ugly, but otherwise argparse prints the redundant list of subcommands.
# And if we just use an empty string it messes up help message alignment for some subcommands.
metavar=" ",
)
@cmd(
cmds,
"gen",
"Check all the generated code is up to date. Otherwise run the code generation process to fix it.",
)
def gen(args):
targets_to_check = (
run(
f"plz query filter -i 'generated:check' {str.join(' ', args)}",
capture_output=True,
)
.stdout.decode("utf-8")
.split("\n")
)
out = run(f"plz run parallel {' '.join(targets_to_check)}", capture_output=True)
targets_to_gen = []
for line in out.stdout.decode("utf-8").split("\n"):
idx = line.find("plz run")
if idx == -1:
continue
targets_to_gen.append(line[idx + 7 : -1]) # 7 is length of 'plz run'
if len(targets_to_gen) == 0:
return
return run("plz run parallel " + " ".join(targets_to_gen))
@cmd(cmds, "run-desktop", "Run frontend desktop app for development.")
def run_desktop(args):
run("./scripts/cleanup-desktop.sh")
run("yarn install")
run("yarn workspace @mintter/ui generate")
run("plz build //backend:mintterd //:yarn")
testnet_var = "MINTTER_P2P_TESTNET_NAME"
if testnet_var not in os.environ:
os.environ[testnet_var] = "dev"
return run("VITE_DESKTOP_APPDATA=Mintter.dev yarn desktop", args=args)
@cmd(cmds, "build-desktop", "Builds the desktop app for the current platform.")
def build_desktop(args):
run("./scripts/cleanup-frontend.sh")
run("./scripts/cleanup-desktop.sh")
run("yarn install")
run("plz build //backend:mintterd //:yarn")
testnet_var = "MINTTER_P2P_TESTNET_NAME"
if testnet_var not in os.environ:
os.environ[testnet_var] = "dev"
run("VITE_DESKTOP_APPDATA=Mintter.local yarn desktop:make")
@cmd(cmds, "test-desktop", "Run frontend desktop tests.")
def test_desktop(args):
run("yarn workspace @mintter/ui generate")
run("plz build //backend:mintterd //:yarn")
testnet_var = "MINTTER_P2P_TESTNET_NAME"
if testnet_var not in os.environ:
os.environ[testnet_var] = "dev"
return run("yarn desktop:test", args=args)
@cmd(cmds, "run-site", "Run sites app for development.")
def run_site(args):
run("./scripts/cleanup-site.sh")
run("yarn install")
run("plz build //:yarn")
return run(
"yarn site",
args=args,
env={**os.environ, "HM_BASE_URL": "http://localhost:3000"},
)
@cmd(cmds, "build-site", "Build site app for production.")
def build_site(args):
run("./scripts/cleanup-frontend.sh")
run("./scripts/cleanup-site.sh")
run("yarn install")
run("plz build //:yarn")
return run(
"yarn site:prod",
args=args,
# env={**os.environ, "HM_BASE_URL": "http://localhost:3000"},
)
@cmd(cmds, "frontend-validate", "Formats, Validates")
def frontend_validate(args):
run("yarn validate")
@cmd(cmds, "run-backend", "Build and run mintterd binary for the current platform.")
def run_backend(args):
return run("plz run //backend:mintterd", args=args)
@cmd(cmds, "build-backend", "Build mintterd binary for the current platform.")
def build_backend(args):
return run("plz build //backend:mintterd")
@cmd(cmds, "run-gw-backend", "Build and run backend for mintter web gateway.")
def run_gateway(args):
return run("plz run //backend:minttergw", args=args)
@cmd(cmds, "ping-p2p", "Execute ping utility to check visibility.")
def ping_p2p(args):
return run("plz run //backend:pingp2p", args=args)
@cmd(
cmds,
"release",
"Create a new Release. this will create a new tag and push it to the remote repository",
)
def release(args):
# run("yarn validate")
# run("yarn test")
run("node scripts/tag.mjs")
if len(sys.argv) == 1:
cli.print_help()
return
namespace, args = cli.parse_known_args()
try:
namespace.func(args)
except ValueError as err:
print(str(err))
sys.exit(1)
except (subprocess.CalledProcessError, KeyboardInterrupt):
return
if __name__ == "__main__":
main()