@devdogsuga/backstage 0.1.5 → 0.1.6

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.
@@ -4,292 +4,6 @@ import { dirname, join } from "node:path";
4
4
  import { confirm, log, spinner } from "@clack/prompts";
5
5
  import { execFile, spawn } from "node:child_process";
6
6
  import { promisify } from "node:util";
7
- //#region ../cli-core/src/env/document.ts
8
- /**
9
- * An editable `.env` that survives being edited.
10
- *
11
- * The root `.env` is not a data file. It is 150 lines of hard-won commentary
12
- * about which value breaks the Supabase CLI when empty, which one must stay
13
- * commented out, and why. A writer that parses to a Map and serializes back
14
- * destroys all of it on the first save.
15
- *
16
- * So this keeps the file as **lines** and edits in place. An untouched line is
17
- * returned byte-for-byte, including its spacing, quoting style and trailing
18
- * comment. Only the lines actually being changed are rewritten.
19
- *
20
- * Nothing is ever deleted. Removing a key comments it out, so the value stays
21
- * recoverable from the file itself, and re-adding it later uncomments that line
22
- * rather than appending a duplicate.
23
- */
24
- /**
25
- * `KEY=value`, active. Groups: indent, `export ` prefix, key, value.
26
- *
27
- * The prefix is CAPTURED rather than skipped so an update can put it back.
28
- * Dropping it turns `export FOO=` into `FOO=`, which still parses here and
29
- * stops being exported to child processes. That shows up as a missing variable
30
- * three tools downstream.
31
- */
32
- const ACTIVE = /^(\s*)((?:export\s+)?)([A-Za-z_][A-Za-z0-9_]*)\s*=(.*)$/;
33
- /** `# KEY=value`, the commented form this tool writes and reads back. */
34
- const COMMENTED = /^(\s*)#\s?((?:export\s+)?)([A-Za-z_][A-Za-z0-9_]*)\s*=(.*)$/;
35
- /**
36
- * Reads the value half of an assignment.
37
- *
38
- * Deliberately NOT a general dotenv parser: it does not expand `$VAR`, because
39
- * a stored value that means one thing in the file and another in the process
40
- * cannot be rotated with confidence.
41
- */
42
- function parseValue(rest) {
43
- const text = rest.trim();
44
- if (text.startsWith("\"")) {
45
- const end = findClosing(text, "\"");
46
- if (end === -1) return unescape(text.slice(1));
47
- return unescape(text.slice(1, end));
48
- }
49
- if (text.startsWith("'")) {
50
- const end = findClosing(text, "'");
51
- if (end === -1) return text.slice(1);
52
- return text.slice(1, end);
53
- }
54
- const hash = text.search(/\s#/);
55
- return (hash === -1 ? text : text.slice(0, hash)).trim();
56
- }
57
- function findClosing(text, quote) {
58
- for (let i = 1; i < text.length; i += 1) {
59
- if (text[i] === "\\") {
60
- i += 1;
61
- continue;
62
- }
63
- if (text[i] === quote) return i;
64
- }
65
- return -1;
66
- }
67
- function unescape(text) {
68
- return text.replace(/\\([nrt\\"'])/g, (_, c) => c === "n" ? "\n" : c === "r" ? "\r" : c === "t" ? " " : c);
69
- }
70
- /**
71
- * Splits everything after `=` into its value and its trailing comment.
72
- *
73
- * Quote-aware, because the naive "cut at the first `#`" truncates a generated
74
- * password into something that still looks like one. A `#` inside quotes is
75
- * part of the value; outside them it starts a comment only when whitespace
76
- * precedes it.
77
- */
78
- function splitComment(rest) {
79
- const text = rest.trimStart();
80
- let after;
81
- if (text.startsWith("\"") || text.startsWith("'")) {
82
- const end = findClosing(text, text[0]);
83
- after = end === -1 ? text.length : end + 1;
84
- } else {
85
- const hash = text.search(/\s#/);
86
- after = hash === -1 ? text.length : hash;
87
- }
88
- const tail = text.slice(after);
89
- const hash = tail.indexOf("#");
90
- return { comment: hash === -1 ? "" : tail.slice(hash).trimEnd() };
91
- }
92
- /**
93
- * Recognises a stamp this tool wrote, so it is replaced rather than duplicated.
94
- *
95
- * Deliberately narrow: it matches the exact bracketed shape below and nothing
96
- * else, because the cost of a false positive is deleting somebody's own note.
97
- */
98
- const STAMP = /\s*#\s*\[[a-z][a-z0-9-]* (?:pushed|pulled) \d{4}-\d{2}-\d{2}\]\s*$/;
99
- function stampText(stamp) {
100
- return `# [${stamp.environment} ${stamp.action} ${stamp.date}]`;
101
- }
102
- function isStamp(comment) {
103
- return STAMP.test(comment);
104
- }
105
- /** Always double-quoted, so a multi-line value round-trips through one line. */
106
- function quote(value) {
107
- return `"${value.replace(/\\/g, "\\\\").replace(/"/g, "\\\"").replace(/\n/g, "\\n").replace(/\r/g, "\\r").replace(/\t/g, "\\t")}"`;
108
- }
109
- var EnvDocument = class EnvDocument {
110
- lines;
111
- /** Whether this session has already appended, so it separates only once. */
112
- appended = false;
113
- constructor(lines) {
114
- this.lines = lines;
115
- }
116
- static parse(text) {
117
- const lines = text.split("\n").map((raw) => {
118
- const active = ACTIVE.exec(raw);
119
- if (active) return {
120
- raw,
121
- key: active[3],
122
- value: parseValue(active[4])
123
- };
124
- const commented = COMMENTED.exec(raw);
125
- if (commented) return {
126
- raw,
127
- key: commented[3],
128
- value: parseValue(commented[4]),
129
- commented: true
130
- };
131
- return { raw };
132
- });
133
- return new EnvDocument(lines);
134
- }
135
- static empty() {
136
- return new EnvDocument([]);
137
- }
138
- find(key, commented) {
139
- return this.lines.findIndex((l) => l.key === key && Boolean(l.commented) === commented);
140
- }
141
- /** The active value, or undefined when absent or commented out. */
142
- get(key) {
143
- const i = this.find(key, false);
144
- return i === -1 ? void 0 : this.lines[i].value;
145
- }
146
- /** Present and active. */
147
- has(key) {
148
- return this.find(key, false) !== -1;
149
- }
150
- /** Present, but commented out. */
151
- isCommented(key) {
152
- return this.find(key, false) === -1 && this.find(key, true) !== -1;
153
- }
154
- /** Every active assignment, in file order. */
155
- entries() {
156
- return this.lines.filter((l) => l.key !== void 0 && !l.commented).map((l) => [l.key, l.value]);
157
- }
158
- keys() {
159
- return this.entries().map(([k]) => k);
160
- }
161
- /**
162
- * Sets a value, preferring to revive a commented line over appending.
163
- *
164
- * Appending when a commented form already exists is how a file ends up with
165
- * the same key twice: one stale, both plausible, and which one looks
166
- * authoritative depends on where the reader scrolled to.
167
- */
168
- set(key, value, stamp) {
169
- const active = this.find(key, false);
170
- if (active !== -1) {
171
- const line = this.lines[active];
172
- const match = ACTIVE.exec(line.raw);
173
- const existing = splitComment(match[4]).comment;
174
- if (stamp && existing !== "" && !isStamp(existing)) this.lines.splice(this.first(key), 0, { raw: existing });
175
- const trailing = stamp ? ` ${stampText(stamp)}` : existing === "" ? "" : ` ${existing}`;
176
- const at = this.find(key, false);
177
- const target = this.lines[at];
178
- target.raw = `${match[1]}${match[2]}${key}=${quote(value)}${trailing}`;
179
- target.value = value;
180
- return;
181
- }
182
- const commented = this.find(key, true);
183
- if (commented !== -1) {
184
- const line = this.lines[commented];
185
- line.raw = `${key}=${quote(value)}${stamp ? ` ${stampText(stamp)}` : ""}`;
186
- line.value = value;
187
- line.commented = false;
188
- return;
189
- }
190
- if (!this.appended && this.lines.length > 0 && this.lines.at(-1).raw !== "") this.lines.push({ raw: "" });
191
- this.appended = true;
192
- this.lines.push({
193
- raw: `${key}=${quote(value)}${stamp ? ` ${stampText(stamp)}` : ""}`,
194
- key,
195
- value
196
- });
197
- }
198
- /** Index of the first line mentioning a key, active or commented. */
199
- first(key) {
200
- return this.lines.findIndex((l) => l.key === key);
201
- }
202
- /**
203
- * Moves every line for a key next to that key's first appearance.
204
- *
205
- * Files drift: a key gets commented out near the bottom, re-added at the top
206
- * six weeks later, and now two lines claim the same name a hundred lines
207
- * apart. Whichever one a reader scrolls to first looks authoritative.
208
- *
209
- * The FIRST occurrence keeps its position, so the standalone comment block
210
- * documenting a key stays attached to it. Everything else moves up to join
211
- * it, in the order it already had.
212
- */
213
- group() {
214
- const out = [];
215
- const taken = /* @__PURE__ */ new Set();
216
- let moved = false;
217
- for (let i = 0; i < this.lines.length; i += 1) {
218
- if (taken.has(i)) continue;
219
- const line = this.lines[i];
220
- out.push(line);
221
- taken.add(i);
222
- if (line.key === void 0) continue;
223
- for (let j = i + 1; j < this.lines.length; j += 1) {
224
- if (taken.has(j) || this.lines[j].key !== line.key) continue;
225
- if (j !== i + 1 || taken.has(i + 1)) moved = true;
226
- out.push(this.lines[j]);
227
- taken.add(j);
228
- }
229
- }
230
- this.lines = out;
231
- return moved;
232
- }
233
- /**
234
- * Blanks every active value without losing one.
235
- *
236
- * Each becomes a commented line holding what it was, plus an empty active
237
- * line under it. The file still declares every key it needs, which is what
238
- * makes it a usable checklist, while holding nothing.
239
- *
240
- * Already-empty keys are skipped. Commenting out `FOO=""` to write `FOO=""`
241
- * underneath is churn that makes the next diff harder to read.
242
- */
243
- reset() {
244
- const out = [];
245
- const cleared = [];
246
- for (const line of this.lines) {
247
- if (line.key === void 0 || line.commented || line.value === "") {
248
- out.push(line);
249
- continue;
250
- }
251
- const exported = ACTIVE.exec(line.raw)?.[2] ?? "";
252
- line.raw = `# ${line.raw.trimStart()}`;
253
- line.commented = true;
254
- out.push(line);
255
- out.push({
256
- raw: `${exported}${line.key}=""`,
257
- key: line.key,
258
- value: ""
259
- });
260
- cleared.push(line.key);
261
- }
262
- this.lines = out;
263
- return cleared;
264
- }
265
- /**
266
- * Comments a key out rather than deleting it.
267
- *
268
- * A no-op when it is already commented or absent, so running a sync twice
269
- * cannot produce `## KEY=`.
270
- */
271
- comment(key) {
272
- const i = this.find(key, false);
273
- if (i === -1) return false;
274
- const line = this.lines[i];
275
- line.raw = `# ${line.raw.trimStart()}`;
276
- line.commented = true;
277
- return true;
278
- }
279
- /** Restores a commented assignment. Returns its value, or undefined. */
280
- uncomment(key) {
281
- const i = this.find(key, true);
282
- if (i === -1) return void 0;
283
- const line = this.lines[i];
284
- line.raw = line.raw.replace(/^(\s*)#\s?/, "$1");
285
- line.commented = false;
286
- return line.value;
287
- }
288
- toString() {
289
- return this.lines.map((l) => l.raw).join("\n");
290
- }
291
- };
292
- //#endregion
293
7
  //#region src/bws/bw.ts
294
8
  /**
295
9
  * Where the bundled Bitwarden CLI (`bw`) is, for the vault code that signs in
@@ -560,4 +274,4 @@ function explainVault(status, envVar = "BWS_ACCESS_TOKEN") {
560
274
  if (status === "unauthenticated") return `You are not signed in to Bitwarden, and with no terminal there is nobody to sign in. Set ${envVar} instead.`;
561
275
  }
562
276
  //#endregion
563
- export { readTokenFromVault as a, EnvDocument as c, readPasswordFromVault as i, bwArgs as n, saveTokenToVault as o, openVault as r, bwCommand as s, VAULT_ITEM_NAME as t };
277
+ export { readTokenFromVault as a, readPasswordFromVault as i, bwArgs as n, saveTokenToVault as o, openVault as r, bwCommand as s, VAULT_ITEM_NAME as t };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@devdogsuga/backstage",
3
- "version": "0.1.5",
3
+ "version": "0.1.6",
4
4
  "private": false,
5
5
  "type": "module",
6
6
  "description": "Officer and production CLI for DevDogsUGA: deploys, env sync with Bitwarden and GitHub, the migration planner role, club graphics and QR codes, GitHub rulesets and settings, and the newsletter. Ships built JS; run it anywhere with `pnpm dlx @devdogsuga/backstage` (no checkout needed to start; commands that read a checkout say so).",
@@ -40,10 +40,10 @@
40
40
  "tsx": "^4.23.12",
41
41
  "typescript": "^6.0.3",
42
42
  "zod": "4.4.3",
43
- "@devdogsuga/events": "0.1.5",
44
- "@devdogsuga/newsletter": "0.1.10",
45
43
  "@devdogsuga/brand": "0.1.5",
46
- "@devdogsuga/telemetry": "0.1.3"
44
+ "@devdogsuga/newsletter": "0.1.10",
45
+ "@devdogsuga/telemetry": "0.1.3",
46
+ "@devdogsuga/events": "0.1.5"
47
47
  },
48
48
  "peerDependencies": {
49
49
  "@devdogsuga/db": "*",
@@ -64,10 +64,10 @@
64
64
  "eslint": "^9.39.5",
65
65
  "tsdown": "^0.23.0",
66
66
  "vitest": "^4.1.11",
67
- "@devdogsuga/cli-core": "0.0.0",
68
67
  "@devdogsuga/config": "0.1.2",
69
68
  "@devdogsuga/db": "0.1.3",
70
- "@devdogsuga/env": "0.1.5"
69
+ "@devdogsuga/env": "0.1.5",
70
+ "@devdogsuga/cli-core": "0.0.0"
71
71
  },
72
72
  "scripts": {
73
73
  "build": "tsdown && node scripts/write-build-info.mjs && node ../../scripts/check-bundle-imports.mjs",
@@ -1,2 +0,0 @@
1
- import { a as listSecrets, o as projectIdFor } from "./client-B7HhuTaA.js";
2
- export { listSecrets, projectIdFor };