garaje 0.1.3 → 0.1.4

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 (2) hide show
  1. package/dist/host/sync.js +34 -12
  2. package/package.json +1 -1
package/dist/host/sync.js CHANGED
@@ -5,17 +5,34 @@ import { readManifest } from "../manifest.js";
5
5
  function git(args) {
6
6
  return spawnSync("git", args, { stdio: "inherit" }).status ?? 1;
7
7
  }
8
- /** Cross the manifest with what is actually checked out under bays/. */
9
- export function bayStatuses(root) {
10
- return readManifest(root).map((bay) => {
11
- const dest = join(root, "bays", bay.name);
12
- if (!existsSync(join(dest, ".git")))
13
- return { ...bay, synced: false };
14
- const rev = spawnSync("git", ["-C", dest, "rev-parse", "--short", "HEAD"], {
15
- encoding: "utf8",
16
- });
17
- return { ...bay, synced: true, head: rev.status === 0 ? rev.stdout.trim() : "?" };
8
+ /** Read the manifest, reporting a bad one as an error rather than a stack
9
+ * trace. A `bays: []` line followed by list items is the common way to get
10
+ * here — it looks like an append but is not valid YAML. */
11
+ function readOrReport(root) {
12
+ try {
13
+ return readManifest(root);
14
+ }
15
+ catch (e) {
16
+ const first = e.message.split("\n")[0];
17
+ process.stderr.write(`error: garaje.yaml: ${first}\n`);
18
+ process.stderr.write("hint: bays must be a YAML list; an empty `bays: []` cannot be followed by `- name:` items\n");
19
+ return undefined;
20
+ }
21
+ }
22
+ /** Whether one manifest bay is materialized, and at which commit. */
23
+ function bayStatus(root, bay) {
24
+ const dest = join(root, "bays", bay.name);
25
+ if (!existsSync(join(dest, ".git")))
26
+ return { ...bay, synced: false };
27
+ const rev = spawnSync("git", ["-C", dest, "rev-parse", "--short", "HEAD"], {
28
+ encoding: "utf8",
18
29
  });
30
+ return { ...bay, synced: true, head: rev.status === 0 ? rev.stdout.trim() : "?" };
31
+ }
32
+ /** Cross the manifest with what is actually checked out under bays/. Throws on
33
+ * a bad manifest; doctor reports that as a failed check. */
34
+ export function bayStatuses(root) {
35
+ return readManifest(root).map((bay) => bayStatus(root, bay));
19
36
  }
20
37
  /** One human-readable line per bay. Pure — doctor reuses this. */
21
38
  export function statusLine(b) {
@@ -34,7 +51,10 @@ export function renderList(rows) {
34
51
  }
35
52
  /** `garaje list` — show the manifest and which bays are materialized. */
36
53
  export function runList(root) {
37
- process.stdout.write(renderList(bayStatuses(root)));
54
+ const entries = readOrReport(root);
55
+ if (!entries)
56
+ return 1;
57
+ process.stdout.write(renderList(entries.map((b) => bayStatus(root, b))));
38
58
  return 0;
39
59
  }
40
60
  /** `garaje sync [name...]` — clone/update the manifest's bays into bays/. */
@@ -43,7 +63,9 @@ export function runSync(root, names) {
43
63
  process.stderr.write("error: git not found in PATH\n");
44
64
  return 1;
45
65
  }
46
- const entries = readManifest(root);
66
+ const entries = readOrReport(root);
67
+ if (!entries)
68
+ return 1;
47
69
  const unknown = names.filter((n) => !entries.some((b) => b.name === n));
48
70
  if (unknown.length) {
49
71
  process.stderr.write(`error: not in garaje.yaml: ${unknown.join(", ")} (declare the bay in the manifest first)\n`);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "garaje",
3
- "version": "0.1.3",
3
+ "version": "0.1.4",
4
4
  "license": "MIT",
5
5
  "repository": {
6
6
  "type": "git",