@yunuseon/kayra 0.17.0 → 0.17.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (101) hide show
  1. package/ansible/roles/platform/tasks/main.yml +31 -0
  2. package/cli/dist/browser/assets/index-hcyM6f6T.js +7 -0
  3. package/cli/dist/browser/index.html +1 -1
  4. package/cli/dist/clients/api/api.js +138 -218
  5. package/cli/dist/clients/api/auth.js +8 -7
  6. package/cli/dist/clients/api/commands.js +50 -14
  7. package/cli/dist/clients/api/contract.js +8 -6
  8. package/cli/dist/clients/api/discovery.js +7 -2
  9. package/cli/dist/clients/api/live.js +40 -0
  10. package/cli/dist/clients/api/protocol.js +17 -10
  11. package/cli/dist/clients/api/queries.js +3 -3
  12. package/cli/dist/clients/api/runs.js +10 -9
  13. package/cli/dist/clients/api/start.js +97 -0
  14. package/cli/dist/clients/api/status.js +29 -0
  15. package/cli/dist/clients/api/validate.js +13 -0
  16. package/cli/dist/clients/cli/explain.js +12 -10
  17. package/cli/dist/clients/cli/framed.js +12 -9
  18. package/cli/dist/clients/cli/invocation.js +4 -3
  19. package/cli/dist/clients/cli/paint.js +1 -1
  20. package/cli/dist/clients/cli/parser.js +8 -8
  21. package/cli/dist/clients/cli/questions.js +11 -10
  22. package/cli/dist/clients/cli/status.js +75 -0
  23. package/cli/dist/clients/cli/terminal.js +4 -2
  24. package/cli/dist/{core/present → clients/cli}/text.js +15 -24
  25. package/cli/dist/clients/cli/validate.js +32 -0
  26. package/cli/dist/clients/cli/values.js +19 -0
  27. package/cli/dist/{core/present → clients/cli}/views.js +28 -60
  28. package/cli/dist/core/adapters/fs.js +18 -0
  29. package/cli/dist/core/{net.js → adapters/network.js} +20 -5
  30. package/cli/dist/core/adapters/opentofu.js +24 -0
  31. package/cli/dist/core/ctl/answers.js +32 -0
  32. package/cli/dist/core/fleet/brand.js +45 -0
  33. package/cli/dist/core/{schemas.js → fleet/docs.js} +4 -3
  34. package/cli/dist/core/fleet/load.js +44 -0
  35. package/cli/dist/core/fleet/model.js +1 -0
  36. package/cli/dist/core/{fleet.js → fleet/parse.js} +61 -41
  37. package/cli/dist/core/{settings.js → fleet/settings.js} +10 -3
  38. package/cli/dist/core/{validate.js → fleet/shape.js} +6 -5
  39. package/cli/dist/core/{present/progress.js → interpreter/events.js} +27 -31
  40. package/cli/dist/core/interpreter/io.js +18 -0
  41. package/cli/dist/core/interpreter/loop.js +101 -0
  42. package/cli/dist/core/interpreter/needs.js +47 -0
  43. package/cli/dist/core/interpreter/process.js +107 -0
  44. package/cli/dist/core/interpreter/progress.js +15 -0
  45. package/cli/dist/core/interpreter/pty.js +8 -0
  46. package/cli/dist/core/operations/catalog.js +35 -18
  47. package/cli/dist/core/operations/{run.js → dispatch.js} +49 -46
  48. package/cli/dist/core/{plan.js → plan/describe.js} +4 -14
  49. package/cli/dist/core/plan/model.js +14 -0
  50. package/cli/dist/core/{commands → recipes}/app-check.js +11 -16
  51. package/cli/dist/core/recipes/apps.js +63 -0
  52. package/cli/dist/core/recipes/backup.js +34 -0
  53. package/cli/dist/core/recipes/certs.js +4 -0
  54. package/cli/dist/core/{commands → recipes}/doctor.js +20 -35
  55. package/cli/dist/core/recipes/host.js +104 -0
  56. package/cli/dist/core/recipes/ssh.js +20 -0
  57. package/cli/dist/core/recipes/steps.js +82 -0
  58. package/cli/dist/core/status/look.js +55 -0
  59. package/cli/dist/core/status/model.js +6 -0
  60. package/cli/dist/core/status/ports.js +1 -0
  61. package/cli/dist/core/text/plural.js +2 -0
  62. package/cli/dist/core/text/spans.js +22 -0
  63. package/cli/dist/core/text/time.js +12 -0
  64. package/cli/dist/core/validation/facts.js +49 -0
  65. package/cli/dist/core/{commands/validate.js → validation/findings.js} +31 -66
  66. package/cli/dist/deployer/app.js +2 -1
  67. package/cli/dist/deployer/{builder.js → build/builder.js} +14 -13
  68. package/cli/dist/deployer/{bundle.js → build/bundle.js} +8 -7
  69. package/cli/dist/deployer/{compose.js → build/compose.js} +8 -7
  70. package/cli/dist/deployer/cron.js +2 -2
  71. package/cli/dist/deployer/{answers.js → ctl/answers.js} +5 -4
  72. package/cli/dist/deployer/{ctl.js → ctl/ctl.js} +3 -3
  73. package/cli/dist/deployer/deployer.js +23 -22
  74. package/cli/dist/deployer/{forge.js → forges/forge.js} +2 -1
  75. package/cli/dist/deployer/{forgejo.js → forges/forgejo.js} +2 -2
  76. package/cli/dist/deployer/{github.js → forges/github.js} +2 -2
  77. package/cli/dist/deployer/{gitlab.js → forges/gitlab.js} +2 -2
  78. package/cli/dist/deployer/{github-issues.js → forges/issues.js} +5 -4
  79. package/cli/dist/deployer/{notify.js → forges/notify.js} +9 -8
  80. package/cli/dist/deployer/{http.js → http/http.js} +1 -0
  81. package/cli/dist/deployer/{page.js → http/page.js} +1 -1
  82. package/cli/dist/deployer/{webhook.js → http/webhook.js} +2 -1
  83. package/cli/dist/deployer/main.js +2 -2
  84. package/cli/dist/deployer/{queue.js → runs/queue.js} +4 -3
  85. package/cli/dist/deployer/{records.js → runs/records.js} +9 -8
  86. package/cli/dist/deployer/{run.js → runs/run.js} +10 -9
  87. package/cli/dist/deployer/{store.js → runs/store.js} +9 -8
  88. package/cli/dist/main.js +89 -89
  89. package/cli/dist/result.js +11 -1
  90. package/cli/dist/serve.js +2 -2
  91. package/cli/dist/typed.js +2 -0
  92. package/package.json +3 -2
  93. package/cli/dist/browser/assets/index-9a-SE2rU.js +0 -7
  94. package/cli/dist/core/brand.js +0 -39
  95. package/cli/dist/core/commands/server.js +0 -298
  96. package/cli/dist/core/commands/status.js +0 -194
  97. package/cli/dist/core/gather.js +0 -61
  98. package/cli/dist/core/interpret.js +0 -276
  99. package/cli/dist/core/load.js +0 -64
  100. package/cli/dist/core/present/line.js +0 -17
  101. /package/cli/dist/core/{updates.js → status/updates.js} +0 -0
@@ -1,276 +0,0 @@
1
- import { spawn } from "node:child_process";
2
- import { chmodSync, mkdtempSync, rmSync, writeFileSync } from "node:fs";
3
- import { tmpdir } from "node:os";
4
- import { join } from "node:path";
5
- import { text } from "node:stream/consumers";
6
- import { all, err, flatMap, ok } from "../result.js";
7
- import { active, bad, muted, ok as fine, strong } from "./present/line.js";
8
- import { position, silent } from "./present/progress.js";
9
- import { draw } from "./present/views.js";
10
- const terminal = {};
11
- const isStopped = (signal) => signal?.aborted === true;
12
- /** A program that ignores SIGINT this long gets SIGTERM. */
13
- const patience = 10_000;
14
- const spawned = async (argv, streams, env = {}, plumbing = terminal) => {
15
- const [program, ...args] = argv;
16
- const { output, signal } = plumbing;
17
- if (isStopped(signal))
18
- return { code: 130, stdout: "", stderr: "", started: false };
19
- const shown = (stream) => stream === "show" ? (output === undefined ? "inherit" : "pipe") : stream === "capture" ? "pipe" : "ignore";
20
- const stdin = streams.stdin ?? (output === undefined ? { kind: "inherit" } : { kind: "none" });
21
- const child = spawn(program, args, {
22
- env: { ...process.env, ...env },
23
- detached: output !== undefined,
24
- stdio: [stdin.kind === "inherit" ? "inherit" : stdin.kind === "none" ? "ignore" : "pipe", shown(streams.stdout), shown(streams.stderr)],
25
- });
26
- const forward = (from, sink) => {
27
- child[from]?.setEncoding("utf8").on("data", (chunk) => {
28
- sink(chunk, from);
29
- });
30
- };
31
- if (output !== undefined && streams.stdout === "show")
32
- forward("stdout", output);
33
- if (output !== undefined && streams.stderr === "show")
34
- forward("stderr", output);
35
- // A program that exits before reading all it was given must not take kayra down with EPIPE.
36
- child.stdin?.on("error", () => undefined);
37
- if (stdin.kind === "given")
38
- child.stdin?.end(stdin.text);
39
- const unsubscribe = stdin.kind === "typed"
40
- ? stdin.input((chunk) => {
41
- child.stdin?.write(chunk);
42
- })
43
- : () => undefined;
44
- const read = (from, stream) => {
45
- const piped = child[from];
46
- return piped === null || stream !== "capture" ? Promise.resolve("") : text(piped);
47
- };
48
- const stdout = read("stdout", streams.stdout);
49
- const stderr = read("stderr", streams.stderr);
50
- const kill = (withSignal) => {
51
- if (child.pid === undefined)
52
- return;
53
- try {
54
- if (output === undefined)
55
- child.kill(withSignal);
56
- else
57
- process.kill(-child.pid, withSignal);
58
- }
59
- catch (error) {
60
- if (!(error instanceof Error && "code" in error && error.code === "ESRCH"))
61
- throw error;
62
- }
63
- };
64
- // eslint-disable-next-line functional/prefer-immutable-types -- the escalation belongs to this child, cleared when it exits
65
- const stopping = {};
66
- const stop = () => {
67
- if (stopping.timer !== undefined)
68
- return;
69
- if (stdin.kind === "typed")
70
- child.stdin?.write("\u0003");
71
- kill("SIGINT");
72
- // eslint-disable-next-line functional/immutable-data -- see above
73
- stopping.timer = setTimeout(() => { kill("SIGTERM"); }, patience);
74
- stopping.timer.unref();
75
- };
76
- // The process group exists only once Node confirms the child has spawned.
77
- child.once("spawn", () => {
78
- signal?.addEventListener("abort", stop, { once: true });
79
- if (isStopped(signal))
80
- stop();
81
- });
82
- const exit = await new Promise((resolve) => {
83
- child.on("error", resolve);
84
- child.on("close", (code) => {
85
- resolve(code ?? 1);
86
- });
87
- });
88
- signal?.removeEventListener("abort", stop);
89
- clearTimeout(stopping.timer);
90
- unsubscribe();
91
- return exit instanceof Error
92
- ? { code: 127, stdout: "", stderr: exit.message, started: false }
93
- : { code: exit, stdout: await stdout, stderr: await stderr, started: true };
94
- };
95
- /** A command's stdout, for kayra to read; its stderr reaches the operator unless captured too. */
96
- export const capture = (argv, stderr = "show", env = {}, plumbing = terminal) => spawned(argv, { stdout: "capture", stderr }, env, plumbing);
97
- const answer = (probe, plumbing) => spawned(probe.kind === "on-path" ? ["sh", "-c", 'command -v "$1"', "sh", probe.program] : probe.argv, { stdout: "discard", stderr: "capture", stdin: { kind: "none" } }, probe.kind === "exits-zero" ? probe.env : {}, plumbing);
98
- /** Each query's answer in place of it, as `$(…)` would: one word, or split into many. */
99
- const resolve = async (argv, plumbing) => {
100
- const words = await Promise.all(argv.map(async (value) => {
101
- if (typeof value === "string")
102
- return ok([value]);
103
- const exit = await capture(value.argv, "show", value.env, plumbing);
104
- if (exit.code !== 0)
105
- return err(`$(${value.argv.join(" ")}) failed: exit ${String(exit.code)}`);
106
- const output = exit.stdout.replace(/\n+$/, "");
107
- return ok(value.words === "one" ? [output] : output.split(/\s+/).filter((word) => word !== ""));
108
- }));
109
- return flatMap(all(words), (lists) => {
110
- const [program, ...rest] = lists.flat();
111
- return program === undefined ? err("the command is empty") : ok([program, ...rest]);
112
- });
113
- };
114
- const lines = (text) => text
115
- .trimEnd()
116
- .split("\n")
117
- .filter((line) => line !== "");
118
- /** Under the step's own line. */
119
- const detail = (line) => [" ", line];
120
- const aside = (line) => [" ", muted(line)];
121
- const hint = (text) => (text === undefined ? [] : [[" ", active("→"), " ", text]]);
122
- const goOn = { failed: false, stopped: false, out: [], err: [] };
123
- const check = async (step, plumbing) => {
124
- const exit = await answer(step.probe, plumbing);
125
- const said = [...lines(exit.stderr).map(detail), ...hint(step.hint)];
126
- if (step.onFailure === "stop")
127
- return exit.code === 0 ? goOn : { failed: true, stopped: true, out: [], err: said };
128
- return exit.code === 0
129
- ? { ...goOn, out: [[fine("✓"), " ", step.label]] }
130
- : { failed: true, stopped: false, out: [[bad("✗"), " ", step.label], ...said], err: [] };
131
- };
132
- const keyOf = (need) => (need.kind === "vault" ? `vault:${need.server}` : "sudo");
133
- const questionOf = (need) => need.kind === "vault"
134
- ? { kind: "secret", text: [" ", active("?"), " ", strong(`${need.server}'s vault password`), muted(" (asked once, kept for this run): ")] }
135
- : { kind: "secret", text: [" ", active("?"), " ", strong("sudo's password"), muted(" (for this step only): ")] };
136
- /** Whether sudo would run without a password: a cached one, or none needed. */
137
- const sudoReady = async (plumbing) => (await spawned(["sudo", "-n", "true"], { stdout: "discard", stderr: "capture", stdin: { kind: "none" } }, {}, plumbing)).code === 0;
138
- const scratch = () => {
139
- // eslint-disable-next-line functional/prefer-immutable-types -- made on first need, removed when the run ends
140
- const made = {};
141
- const dir = () => {
142
- // eslint-disable-next-line functional/immutable-data -- see above
143
- made.dir ??= mkdtempSync(join(tmpdir(), "kayra-"));
144
- return made.dir;
145
- };
146
- return {
147
- vaultScript: () => {
148
- const script = join(dir(), "vault-password");
149
- writeFileSync(script, '#!/bin/sh\nprintf \'%s\\n\' "$KAYRA_VAULT_PASSWORD"\n', { mode: 0o700 });
150
- chmodSync(script, 0o700);
151
- return script;
152
- },
153
- clean: () => {
154
- if (made.dir !== undefined)
155
- rmSync(made.dir, { recursive: true, force: true });
156
- },
157
- };
158
- };
159
- /** Asks what a step needs and has not been given yet in this run; undefined if the operator gave nothing. */
160
- const meet = async (needs, asked, io, made) => needs.reduce(async (previous, need) => {
161
- const so = await previous;
162
- if (so === undefined)
163
- return undefined;
164
- if (need.kind === "sudo" && (await sudoReady(io)))
165
- return so;
166
- const key = keyOf(need);
167
- const given = so.asked[key] ?? (await ask(io, questionOf(need)));
168
- if (given === "")
169
- return undefined;
170
- const now = need.kind === "vault" ? { ...so.asked, [key]: given } : so.asked;
171
- return need.kind === "vault"
172
- ? { asked: now, met: { ...so.met, env: { ...so.met.env, ANSIBLE_VAULT_PASSWORD_FILE: made.vaultScript(), KAYRA_VAULT_PASSWORD: given } } }
173
- : { asked: now, met: { env: { ...so.met.env, KAYRA_SUDO_STDIN: "1" }, stdin: { kind: "given", text: `${given}\n` } } };
174
- }, Promise.resolve({ met: { env: {} }, asked }));
175
- /** A step that talks with a person, given a pty: macOS's script, util-linux's elsewhere. */
176
- const inPty = (argv, size) => {
177
- const { columns, rows } = size ?? { columns: 120, rows: 32 };
178
- const sized = ["sh", "-c", `stty rows ${String(rows)} cols ${String(columns)} 2>/dev/null; exec "$@"`, "sh", ...argv];
179
- return process.platform === "darwin"
180
- // BSD script accepts a pipe, but rejects Node's socket-backed stdin with ENOTSUP.
181
- ? ["bash", "-c", '"$@" < <(cat); code=$?; kill "$!" 2>/dev/null || :; exit "$code"', "bash", "script", "-q", "/dev/null", ...sized]
182
- : ["script", "-q", "-e", "-c", sized.map((word) => `'${word.replaceAll("'", `'\\''`)}'`).join(" "), "/dev/null"];
183
- };
184
- const runStep = async (step, io, met) => {
185
- const argv = await resolve(step.argv, io);
186
- if (!argv.ok)
187
- return { failed: true, stopped: true, why: "a query failed", out: [], err: [detail(argv.error)] };
188
- const { stdout } = step;
189
- const talks = step.kind === "session" && io.output !== undefined;
190
- if (talks && io.input === undefined)
191
- return { failed: true, stopped: true, why: "no terminal", out: [], err: [detail("it talks with a person, and this client gives it no keys")] };
192
- // A quiet step's stderr waits until it is done, so it cannot tear through a spinner.
193
- const quiet = stdout === "discard";
194
- const exit = await spawned(talks ? inPty(argv.value, io.size) : argv.value, {
195
- stdout: typeof stdout === "string" ? stdout : "capture",
196
- stderr: quiet ? "capture" : "show",
197
- ...(talks && io.input !== undefined ? { stdin: { kind: "typed", input: io.input } } : met.stdin === undefined ? {} : { stdin: met.stdin }),
198
- }, { ...step.env, ...met.env }, io);
199
- if (!exit.started)
200
- return { failed: true, stopped: true, why: "not started", out: [], err: [detail(`${argv.value[0]}: ${exit.stderr}`)] };
201
- // Whatever it answered is shown, even when it failed: it may say why.
202
- const out = typeof stdout === "string" ? [] : draw(stdout, exit.stdout, Date.now());
203
- if (exit.code === 0)
204
- return { ...goOn, out, err: lines(exit.stderr).map(aside) };
205
- return { failed: true, stopped: true, why: `exit ${String(exit.code)}`, out, err: lines(exit.stderr).map(detail) };
206
- };
207
- const perform = async (step, io, met) => {
208
- switch (step.kind) {
209
- case "session":
210
- case "run":
211
- return runStep(step, io, met);
212
- case "check":
213
- return check(step, io);
214
- case "confirm": {
215
- io.err("");
216
- io.err([" ", bad("▲"), " ", strong(step.warning)]);
217
- const typed = await ask(io, { kind: "confirm", text: [" Type ", strong(step.expect), " to confirm: "], expect: step.expect });
218
- return typed === step.expect ? goOn : { failed: false, stopped: true, out: ["Aborted."], err: [] };
219
- }
220
- case "note":
221
- return { ...goOn, out: [step.text] };
222
- }
223
- };
224
- /** Cancellation also ends a question; a late answer cannot restart the plan. */
225
- const ask = async (io, question) => {
226
- if (isStopped(io.signal))
227
- return "";
228
- return new Promise((resolve, reject) => {
229
- const done = (answer) => {
230
- io.signal?.removeEventListener("abort", stopped);
231
- resolve(answer);
232
- };
233
- const stopped = () => { done(""); };
234
- io.signal?.addEventListener("abort", stopped, { once: true });
235
- void io.ask(question).then(done, (error) => {
236
- io.signal?.removeEventListener("abort", stopped);
237
- reject(error instanceof Error ? error : new Error(String(error)));
238
- });
239
- });
240
- };
241
- /**
242
- * Runs a plan step by step, until it ends or a step stops it, shown by `progress`.
243
- * True if nothing failed and the operator did not interrupt it.
244
- */
245
- export const interpret = async (plan, io, progress = silent, interrupted = () => false) => {
246
- const made = scratch();
247
- try {
248
- const ended = await progress.plan(plan, () => plan.reduce(async (previous, step, index) => {
249
- const so = await previous;
250
- if (so.stop !== undefined)
251
- return so;
252
- if (interrupted() || isStopped(io.signal))
253
- return { ...so, stop: { index, step, why: "interrupted" } };
254
- // What a step needs is asked before its frame opens: a prompt, then the step.
255
- const met = (step.kind === "run" || step.kind === "session") && step.needs !== undefined ? await meet(step.needs, so.asked, io, made) : { met: { env: {} }, asked: so.asked };
256
- if (met === undefined) {
257
- io.err([" ", muted("Nothing given: stopped before it ran.")]);
258
- return { ...so, stop: { index, step, why: isStopped(io.signal) ? "interrupted" : "declined" } };
259
- }
260
- const done = await progress.step(step, position(plan, index), () => perform(step, io, met.met));
261
- // Ctrl-C reached the step's program too: how it ended says nothing about the server.
262
- if (interrupted() || isStopped(io.signal))
263
- return { failures: so.failures, asked: met.asked, stop: { index, step, why: "interrupted" } };
264
- done.out.forEach(io.out);
265
- done.err.forEach(io.err);
266
- const failures = so.failures + (done.failed ? 1 : 0);
267
- if (done.stopped)
268
- return { failures, asked: met.asked, stop: { index, step, why: done.failed ? "failed" : "declined" } };
269
- return { failures, asked: met.asked };
270
- }, Promise.resolve({ failures: 0, asked: {} })));
271
- return ended.failures === 0 && ended.stop?.why !== "interrupted";
272
- }
273
- finally {
274
- made.clean();
275
- }
276
- };
@@ -1,64 +0,0 @@
1
- import { existsSync, readdirSync, readFileSync } from "node:fs";
2
- import { join } from "node:path";
3
- import { fleetRoot, serverDir, serverName, within } from "./brand.js";
4
- import { parseServer, yamlOf } from "./fleet.js";
5
- import { all, err, flatMap, map, ok } from "../result.js";
6
- import { defaultsSchema } from "./settings.js";
7
- import { checkSettings, knownSettings } from "./validate.js";
8
- /** The fleet is the nearest directory, from `from` upwards, with a servers/defaults.yml. */
9
- export const findFleetRoot = (from) => {
10
- if (existsSync(join(from, "servers", "defaults.yml")))
11
- return ok(fleetRoot(from));
12
- const parent = within(from, "..");
13
- return parent === from
14
- ? err("no fleet here: no servers/defaults.yml in this directory or above it")
15
- : findFleetRoot(parent);
16
- };
17
- const text = (path) => (existsSync(path) ? readFileSync(path, "utf8") : undefined);
18
- const stacks = (dir) => existsSync(join(dir, "stacks"))
19
- ? readdirSync(join(dir, "stacks"))
20
- .toSorted()
21
- .flatMap((stack) => text(join(dir, "stacks", stack, "compose.yaml")) ?? [])
22
- : [];
23
- const appValues = (dir) => existsSync(join(dir, "apps"))
24
- ? readdirSync(join(dir, "apps"))
25
- .filter((file) => file.endsWith(".yml"))
26
- .toSorted()
27
- .map((file) => ({ file, text: readFileSync(join(dir, "apps", file), "utf8") }))
28
- : [];
29
- const readServer = (root, entry) => {
30
- const name = serverName(entry);
31
- if (!name.ok)
32
- return err(`servers/${entry}: ${name.error}`);
33
- const dir = serverDir(root, name.value);
34
- const server = parseServer({
35
- name: name.value,
36
- dir,
37
- descriptor: readFileSync(join(dir, "server.yml"), "utf8"),
38
- vars: text(join(dir, "vars.yml")),
39
- secrets: text(join(dir, "secrets.yml")),
40
- inventory: text(join(dir, "inventory.ini")),
41
- terraform: existsSync(join(dir, "terraform")),
42
- stacks: stacks(dir),
43
- appValues: appValues(dir),
44
- });
45
- return server.ok ? server : err(`servers/${entry}/server.yml: ${server.error}`);
46
- };
47
- /** servers/defaults.yml: settings shared by every server, any kind's. */
48
- const checkDefaults = (root) => {
49
- const parsed = yamlOf(readFileSync(join(root, "servers", "defaults.yml"), "utf8"));
50
- if (!parsed.ok)
51
- return err(`servers/defaults.yml ${parsed.error}`);
52
- const values = parsed.value;
53
- if (values === null || values === undefined)
54
- return ok(true);
55
- if (typeof values !== "object" || Array.isArray(values))
56
- return err("servers/defaults.yml is not a YAML mapping");
57
- return map(checkSettings("servers/defaults.yml", Object.fromEntries(Object.entries(values)), defaultsSchema, knownSettings(undefined)), () => true);
58
- };
59
- export const loadFleet = (root) => flatMap(checkDefaults(root), () => fleetOf(root));
60
- const fleetOf = (root) => map(all(readdirSync(join(root, "servers"), { withFileTypes: true })
61
- .filter((entry) => entry.isDirectory() && existsSync(join(root, "servers", entry.name, "server.yml")))
62
- .map((entry) => entry.name)
63
- .toSorted()
64
- .map((entry) => readServer(root, entry))), (servers) => ({ root, servers }));
@@ -1,17 +0,0 @@
1
- const toned = (tone) => (text) => ({ tone, text });
2
- export const ok = toned("ok");
3
- export const bad = toned("bad");
4
- export const warn = toned("warn");
5
- export const active = toned("active");
6
- export const muted = toned("muted");
7
- export const strong = toned("strong");
8
- export const accent = toned("accent");
9
- export const link = (text, href, tone) => ({ text, href, ...(tone === undefined ? {} : { tone }) });
10
- export const spans = (text) => (typeof text === "string" ? [text] : text);
11
- export const textOf = (span) => (typeof span === "string" ? span : span.text);
12
- export const flat = (text) => spans(text).map(textOf).join("");
13
- const graphemes = new Intl.Segmenter();
14
- /** A string's characters as a reader counts them. */
15
- export const characters = (text) => Array.from(graphemes.segment(text), (each) => each.segment);
16
- /** Columns it takes: one per character, which holds for everything kayra writes itself. */
17
- export const width = (text) => characters(flat(text)).length;
File without changes