@addorimprove/prompt 0.2.0 → 0.3.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 (2) hide show
  1. package/dist/prompt.js +24 -0
  2. package/package.json +1 -1
package/dist/prompt.js CHANGED
@@ -108,6 +108,9 @@ class ApiClient {
108
108
  addVersion(id, body) {
109
109
  return this.request("POST", `/docs/${id}/versions`, body);
110
110
  }
111
+ setVisibility(id, label, isPublic) {
112
+ return this.request("PATCH", `/docs/${id}/versions/${encodeURIComponent(label)}`, { isPublic });
113
+ }
111
114
  deleteCurrentKey() {
112
115
  return this.request("DELETE", "/keys/current");
113
116
  }
@@ -515,6 +518,26 @@ ${doc.latest?.content ?? "(no versions)"}`);
515
518
  const r = await client.addVersion(id, { intent: "branch", parentLabel: parent, content, ...format ? { format } : {} });
516
519
  return out(json, r, `Branched → ${r.label}.`);
517
520
  }
521
+ case "visibility": {
522
+ const client = requireClient(args.flags);
523
+ if (!client)
524
+ return;
525
+ const id = Number(args.positionals[0]);
526
+ const label = args.positionals[1];
527
+ const state = args.positionals[2];
528
+ if (!Number.isInteger(id) || !label || state !== "public" && state !== "private") {
529
+ console.error("usage: prompt visibility <id> <label> public|private");
530
+ process.exitCode = 1;
531
+ return;
532
+ }
533
+ const isPublic = state === "public";
534
+ if (!flags(args, "yes") && !flags(args, "y") && !await confirm(`Set ${id} ${label} → ${state}?`)) {
535
+ console.log("Aborted.");
536
+ return;
537
+ }
538
+ const r = await client.setVisibility(id, label, isPublic);
539
+ return out(json, r, `${id} ${label} → ${r.isPublic ? "public" : "private"}.`);
540
+ }
518
541
  case "help":
519
542
  default:
520
543
  console.log(HELP);
@@ -538,6 +561,7 @@ Usage: prompt <command> [args] [flags] (or: npx @addorimprove/prompt <command>
538
561
  new --name <n> [-f file] [--format mdx|html] Create a document
539
562
  iterate <id> [--parent label] [-f file] Add a version on the same line
540
563
  branch <id> <parentLabel> [-f file] Fork a new line from a version
564
+ visibility <id> <label> public|private Publish/unpublish a version
541
565
  (omit --format to auto-detect mdx/html from content)
542
566
 
543
567
  Global flags: --base-url <url>, --json, -y/--yes
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@addorimprove/prompt",
3
- "version": "0.2.0",
3
+ "version": "0.3.0",
4
4
  "type": "module",
5
5
  "bin": { "prompt": "dist/prompt.js" },
6
6
  "files": ["dist"],