@baby-ui/cli 0.0.0-stage → 0.1.0

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 (44) hide show
  1. package/LICENSE +201 -0
  2. package/README.md +36 -2
  3. package/bin.mjs +20 -0
  4. package/dist/add-Dw_xdBjM.js +8472 -0
  5. package/dist/add-Dw_xdBjM.js.map +1 -0
  6. package/dist/auth-Cqd8NPiR.js +52 -0
  7. package/dist/auth-Cqd8NPiR.js.map +1 -0
  8. package/dist/auth-DLL_PGWB.js +41 -0
  9. package/dist/auth-DLL_PGWB.js.map +1 -0
  10. package/dist/banner-b_aKYU5F.js +23 -0
  11. package/dist/banner-b_aKYU5F.js.map +1 -0
  12. package/dist/core-Cd391zXy.js +142 -0
  13. package/dist/core-Cd391zXy.js.map +1 -0
  14. package/dist/dist-Bs-3vZ2T.js +2712 -0
  15. package/dist/dist-Bs-3vZ2T.js.map +1 -0
  16. package/dist/dist-CxDndWiZ.js +6661 -0
  17. package/dist/dist-CxDndWiZ.js.map +1 -0
  18. package/dist/errors-zXXytRXF.js +16 -0
  19. package/dist/errors-zXXytRXF.js.map +1 -0
  20. package/dist/history-l3B-mc6n.js +55 -0
  21. package/dist/history-l3B-mc6n.js.map +1 -0
  22. package/dist/index.js +3097 -0
  23. package/dist/index.js.map +1 -0
  24. package/dist/info-mS7KbPJ_.js +43 -0
  25. package/dist/info-mS7KbPJ_.js.map +1 -0
  26. package/dist/init-DO1txT-A.js +168 -0
  27. package/dist/init-DO1txT-A.js.map +1 -0
  28. package/dist/list-DnQNQUNr.js +48 -0
  29. package/dist/list-DnQNQUNr.js.map +1 -0
  30. package/dist/maintain-DeyqYm5K.js +183 -0
  31. package/dist/maintain-DeyqYm5K.js.map +1 -0
  32. package/dist/schemas-DwMX1h2B.js +5160 -0
  33. package/dist/schemas-DwMX1h2B.js.map +1 -0
  34. package/dist/shared-BJaaV-dl.js +96 -0
  35. package/dist/shared-BJaaV-dl.js.map +1 -0
  36. package/dist/state-CsT6LJsH.js +430 -0
  37. package/dist/state-CsT6LJsH.js.map +1 -0
  38. package/dist/targets-Bpv2h7C4.js +316 -0
  39. package/dist/targets-Bpv2h7C4.js.map +1 -0
  40. package/dist/tx-DBnjY8eR.js +226 -0
  41. package/dist/tx-DBnjY8eR.js.map +1 -0
  42. package/dist/ui-Cthxlfe6.js +206 -0
  43. package/dist/ui-Cthxlfe6.js.map +1 -0
  44. package/package.json +50 -3
@@ -0,0 +1,16 @@
1
+ //#region src/errors.ts
2
+ /** An expected failure: printed without a stack trace, exits with `code`. */
3
+ var CliError = class extends Error {
4
+ code;
5
+ hint;
6
+ constructor(message, options = {}) {
7
+ super(message);
8
+ this.name = "CliError";
9
+ this.hint = options.hint;
10
+ this.code = options.code ?? 1;
11
+ }
12
+ };
13
+ //#endregion
14
+ export { CliError as t };
15
+
16
+ //# sourceMappingURL=errors-zXXytRXF.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"errors-zXXytRXF.js","names":[],"sources":["../src/errors.ts"],"sourcesContent":["/** An expected failure: printed without a stack trace, exits with `code`. */\nexport class CliError extends Error {\n\treadonly code: number;\n\treadonly hint: string | undefined;\n\n\tconstructor(message: string, options: { hint?: string; code?: number } = {}) {\n\t\tsuper(message);\n\t\tthis.name = \"CliError\";\n\t\tthis.hint = options.hint;\n\t\tthis.code = options.code ?? 1;\n\t}\n}\n"],"mappings":";;AACA,IAAa,WAAb,cAA8B,MAAM;CACnC;CACA;CAEA,YAAY,SAAiB,UAA4C,CAAC,GAAG;EAC5E,MAAM,OAAO;EACb,KAAK,OAAO;EACZ,KAAK,OAAO,QAAQ;EACpB,KAAK,OAAO,QAAQ,QAAQ;CAC7B;AACD"}
@@ -0,0 +1,55 @@
1
+ import { t as CliError } from "./errors-zXXytRXF.js";
2
+ import { r as isInteractive, u as c } from "./core-Cd391zXy.js";
3
+ import { a as note, n as intro, o as outro, r as message, t as confirm } from "./ui-Cthxlfe6.js";
4
+ import { t as configuredTargets } from "./shared-BJaaV-dl.js";
5
+ import { a as readJournal, i as listJournals, o as revert, r as conflicts } from "./tx-DBnjY8eR.js";
6
+ //#region src/commands/history.ts
7
+ function describe(j) {
8
+ const files = j.ops.map((op) => op.path).filter((p) => !p.startsWith(".baby-ui/"));
9
+ const state = j.revertedBy ? c.dim(` reverted by ${j.revertedBy}`) : "";
10
+ return `${c.bold(j.id)} ${j.command}${state}\n${c.dim(files.join(", ") || "no files")}`;
11
+ }
12
+ async function history(options) {
13
+ const targets = await configuredTargets(options);
14
+ intro("baby-ui history");
15
+ for (const target of targets) {
16
+ const journals = await listJournals(target.root);
17
+ note(journals.length ? journals.map(describe).join("\n") : c.dim("nothing yet"), target.path);
18
+ }
19
+ outro("Revert one with `baby-ui revert <id>`");
20
+ }
21
+ async function pick(root, id) {
22
+ if (id) {
23
+ const journal = await readJournal(root, id);
24
+ if (!journal) throw new CliError(`No transaction ${id}.`, { hint: "See `baby-ui history`." });
25
+ return journal;
26
+ }
27
+ const latest = (await listJournals(root)).find((j) => !j.revertedBy && !j.revertOf);
28
+ if (!latest) throw new CliError("Nothing to undo.");
29
+ return latest;
30
+ }
31
+ async function revertCommand(options) {
32
+ const targets = await configuredTargets(options);
33
+ intro(options.id ? `baby-ui revert ${options.id}` : "baby-ui undo");
34
+ for (const target of targets) {
35
+ const journal = await pick(target.root, options.id);
36
+ if (journal.revertedBy && !options.force) throw new CliError(`${journal.id} was already reverted by ${journal.revertedBy}.`, { hint: `Revert ${journal.revertedBy} to redo it.` });
37
+ const edited = await conflicts(target.root, journal);
38
+ if (edited.length && !options.force) {
39
+ const list = edited.map((e) => `${e.path} (${e.reason})`).join("\n");
40
+ note(list, "Changed since then");
41
+ if (!(isInteractive() && await confirm({
42
+ message: "Discard those changes too?",
43
+ initialValue: false
44
+ }))) throw new CliError("Revert cancelled.", { hint: "Pass --force to discard them." });
45
+ }
46
+ const result = await revert(target.root, journal);
47
+ message(`${c.green("reverted")} ${journal.id} (${journal.command})`);
48
+ message(c.dim(`Redo with \`baby-ui revert ${result.id}\``));
49
+ }
50
+ outro("Done");
51
+ }
52
+ //#endregion
53
+ export { history, revertCommand };
54
+
55
+ //# sourceMappingURL=history-l3B-mc6n.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"history-l3B-mc6n.js","names":[],"sources":["../src/commands/history.ts"],"sourcesContent":["import { CliError } from \"../errors.ts\";\nimport { c } from \"../logger.ts\";\nimport { confirm, intro, isInteractive, message, note, outro } from \"../ui/index.ts\";\nimport {\n\tconflicts,\n\ttype Journal,\n\tlistJournals,\n\treadJournal,\n\trevert,\n} from \"../write/tx.ts\";\nimport { type CommonOptions, configuredTargets } from \"./shared.ts\";\n\nexport interface RevertOptions extends CommonOptions {\n\treadonly id?: string;\n\treadonly force?: boolean;\n}\n\nfunction describe(j: Journal): string {\n\tconst files = j.ops.map((op) => op.path).filter((p) => !p.startsWith(\".baby-ui/\"));\n\tconst state = j.revertedBy ? c.dim(` reverted by ${j.revertedBy}`) : \"\";\n\treturn `${c.bold(j.id)} ${j.command}${state}\\n${c.dim(files.join(\", \") || \"no files\")}`;\n}\n\nexport async function history(options: CommonOptions): Promise<void> {\n\tconst targets = await configuredTargets(options);\n\tintro(\"baby-ui history\");\n\tfor (const target of targets) {\n\t\tconst journals = await listJournals(target.root);\n\t\tnote(\n\t\t\tjournals.length ? journals.map(describe).join(\"\\n\") : c.dim(\"nothing yet\"),\n\t\t\ttarget.path,\n\t\t);\n\t}\n\toutro(\"Revert one with `baby-ui revert <id>`\");\n}\n\nasync function pick(root: string, id: string | undefined): Promise<Journal> {\n\tif (id) {\n\t\tconst journal = await readJournal(root, id);\n\t\tif (!journal)\n\t\t\tthrow new CliError(`No transaction ${id}.`, { hint: \"See `baby-ui history`.\" });\n\t\treturn journal;\n\t}\n\t// Undo skips transactions already reverted and the reverts themselves, like an editor's undo.\n\tconst latest = (await listJournals(root)).find((j) => !j.revertedBy && !j.revertOf);\n\tif (!latest) throw new CliError(\"Nothing to undo.\");\n\treturn latest;\n}\n\nexport async function revertCommand(options: RevertOptions): Promise<void> {\n\tconst targets = await configuredTargets(options);\n\tintro(options.id ? `baby-ui revert ${options.id}` : \"baby-ui undo\");\n\tfor (const target of targets) {\n\t\tconst journal = await pick(target.root, options.id);\n\t\tif (journal.revertedBy && !options.force) {\n\t\t\tthrow new CliError(`${journal.id} was already reverted by ${journal.revertedBy}.`, {\n\t\t\t\thint: `Revert ${journal.revertedBy} to redo it.`,\n\t\t\t});\n\t\t}\n\t\tconst edited = await conflicts(target.root, journal);\n\t\tif (edited.length && !options.force) {\n\t\t\tconst list = edited.map((e) => `${e.path} (${e.reason})`).join(\"\\n\");\n\t\t\tnote(list, \"Changed since then\");\n\t\t\tconst go =\n\t\t\t\tisInteractive() &&\n\t\t\t\t(await confirm({ message: \"Discard those changes too?\", initialValue: false }));\n\t\t\tif (!go)\n\t\t\t\tthrow new CliError(\"Revert cancelled.\", {\n\t\t\t\t\thint: \"Pass --force to discard them.\",\n\t\t\t\t});\n\t\t}\n\t\tconst result = await revert(target.root, journal);\n\t\tmessage(`${c.green(\"reverted\")} ${journal.id} (${journal.command})`);\n\t\tmessage(c.dim(`Redo with \\`baby-ui revert ${result.id}\\``));\n\t}\n\toutro(\"Done\");\n}\n"],"mappings":";;;;;;AAiBA,SAAS,SAAS,GAAoB;CACrC,MAAM,QAAQ,EAAE,IAAI,KAAK,OAAO,GAAG,IAAI,CAAC,CAAC,QAAQ,MAAM,CAAC,EAAE,WAAW,WAAW,CAAC;CACjF,MAAM,QAAQ,EAAE,aAAa,EAAE,IAAI,gBAAgB,EAAE,YAAY,IAAI;CACrE,OAAO,GAAG,EAAE,KAAK,EAAE,EAAE,EAAE,IAAI,EAAE,UAAU,MAAM,IAAI,EAAE,IAAI,MAAM,KAAK,IAAI,KAAK,UAAU;AACtF;AAEA,eAAsB,QAAQ,SAAuC;CACpE,MAAM,UAAU,MAAM,kBAAkB,OAAO;CAC/C,MAAM,iBAAiB;CACvB,KAAK,MAA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