-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathdev
More file actions
executable file
·262 lines (205 loc) · 8.35 KB
/
dev
File metadata and controls
executable file
·262 lines (205 loc) · 8.35 KB
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
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
#!/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, add_help=False)
p.set_defaults(func=func)
return p
return wrapper
def run(cmd: str, args: list = [], capture_output=False, env: os._Environ = os.environ):
"""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 Seed Hyper Media. 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 the generated code is up to date and 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("node scripts/cleanup-desktop.js")
run("plz build //:pnpm")
if "SEED_NO_DAEMON_SPAWN" not in os.environ:
run("plz build //backend:seed-daemon")
return run("pnpm desktop", args=args)
@cmd(cmds, "run-desktop-mainnet", "Run frontend desktop app for dev, on mainnet.")
def run_desktop_mainnet(args):
run("node scripts/cleanup-desktop.js")
run("plz build //:pnpm")
if "SEED_NO_DAEMON_SPAWN" not in os.environ:
run("plz build //backend:seed-daemon")
del os.environ["SEED_P2P_TESTNET_NAME"]
return run("pnpm desktop", args=args)
@cmd(cmds, "run-desktop-profiler", "Run desktop app with memory profiler window.")
def run_desktop_profiler(args):
run("node scripts/cleanup-desktop.js")
run("plz build //:pnpm")
if "SEED_NO_DAEMON_SPAWN" not in os.environ:
run("plz build //backend:seed-daemon")
os.environ["MEMORY_PROFILER"] = "1"
return run("pnpm desktop", args=args)
@cmd(cmds, "run-desktop-fixture", "Run desktop app against test fixture data.")
def run_desktop_fixture(args):
run("plz build //:pnpm")
if "SEED_NO_DAEMON_SPAWN" not in os.environ:
run("plz build //backend:seed-daemon")
# Point entire desktop userData to fixture directory
fixture_dir = os.path.abspath("test-fixtures/desktop")
os.environ["SEED_FIXTURE_DATA_DIR"] = fixture_dir
os.environ["SEED_P2P_TESTNET_NAME"] = "fixture"
return run("pnpm desktop", args=args)
@cmd(cmds, "build-desktop", "Builds the desktop app for the current platform. Use --profiler to enable React Profiler.")
def build_desktop(args):
# run("node scripts/cleanup-desktop.js")
# run("./scripts/cleanup-frontend.sh")
run("pnpm install")
run("plz build //backend:seed-daemon //:pnpm")
# build-desktop always targets mainnet, regardless of the ambient SEED_P2P_TESTNET_NAME.
os.environ["SEED_P2P_TESTNET_NAME"] = ""
os.environ["VITE_LIGHTNING_API_URL"] = "https://ln.seed.hyper.media"
host_url = "https://host.seed.hyper.media"
gateway_url = "https://hyper.media"
# Enable React Profiler if --profiler flag is passed
if "--profiler" in args:
os.environ["REACT_PROFILER"] = "1"
args = [a for a in args if a != "--profiler"]
env_prefix = f"VITE_DESKTOP_APPDATA=Seed-local SHOW_OB_RESET_BTN=0 VITE_SEED_HOST_URL={host_url} VITE_GATEWAY_URL={gateway_url}"
if os.environ.get("REACT_PROFILER"):
env_prefix = f"REACT_PROFILER=1 {env_prefix}"
run(f"{env_prefix} pnpm desktop:make")
@cmd(cmds, "test-desktop", "Run frontend desktop tests.")
def test_desktop(args):
run("node scripts/cleanup-desktop.js")
run("plz build //backend:seed-daemon //:pnpm")
testnet_var = "SEED_P2P_TESTNET_NAME"
if testnet_var not in os.environ:
os.environ[testnet_var] = "dev"
return run("pnpm desktop:test", args=args)
@cmd(cmds, "run-web", "Run Web app for development.")
def run_web(args):
run("./scripts/cleanup-web.sh")
run("pnpm install")
run("plz build //:pnpm")
return run(
"pnpm web",
args=args,
)
@cmd(cmds, "build-web", "Build web app for production.")
def build_web(args):
run("./scripts/cleanup-frontend.sh")
run("./scripts/cleanup-web.sh")
run("pnpm install")
run("plz build //:pnpm")
return run(
"pnpm web:prod",
args=args,
)
@cmd(cmds, "frontend-validate", "Formats, Validates")
def frontend_validate(args):
run("node scripts/cleanup-desktop.js")
run("pnpm validate")
@cmd(
cmds,
"run-backend",
"Build and run seed-daemon binary for the current platform.",
)
def run_backend(args):
env = os.environ.copy()
env["LLAMA_LOG"] = "error"
return run("plz run //backend:seed-daemon", args=args, env=env)
@cmd(cmds, "build-backend", "Build seed-daemon binary for the current platform.")
def build_backend(args):
return run("plz build //backend:seed-daemon")
@cmd(cmds, "run-gw-backend", "Build and run backend for seed web gateway.")
def run_gateway(args):
return run("plz run //backend:seed-gateway", 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,
"install-cli",
"Build and install the seed-cli command into ~/.local/bin.",
)
def install_cli(args):
import pathlib
run("pnpm install")
run("pnpm --filter @seed-hypermedia/cli build")
cli_dist = pathlib.Path(__file__).resolve().parent / "frontend" / "apps" / "cli" / "dist" / "index.js"
if not cli_dist.exists():
print(f"Error: build output not found at {cli_dist}")
sys.exit(1)
bin_dir = pathlib.Path.home() / ".local" / "bin"
bin_dir.mkdir(parents=True, exist_ok=True)
link = bin_dir / "seed-cli"
if link.exists() or link.is_symlink():
link.unlink()
link.symlink_to(cli_dist)
print(f"Installed: {link} -> {cli_dist}")
@cmd(
cmds,
"release",
"Create a new Release. this will create a new tag and push it to the remote repository",
)
def release(args):
# run("pnpm validate")
# run("pnpm 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:
sys.exit(1)
except KeyboardInterrupt:
return
if __name__ == "__main__":
main()