@addorimprove/prompt 0.1.2 → 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 +31 -6
  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
  }
@@ -456,14 +459,14 @@ ${doc.latest?.content ?? "(no versions)"}`);
456
459
  process.exitCode = 1;
457
460
  return;
458
461
  }
459
- const format = flagStr(args.flags, "format") ?? "mdx";
462
+ const format = flagStr(args.flags, "format");
460
463
  const content = await readContent(args.flags, `# ${name}
461
464
  `);
462
465
  if (!flags(args, "yes") && !flags(args, "y") && !await confirm(`Create document "${name}"?`)) {
463
466
  console.log("Aborted.");
464
467
  return;
465
468
  }
466
- const r = await client.createDoc({ name, content, format });
469
+ const r = await client.createDoc({ name, content, ...format ? { format } : {} });
467
470
  return out(json, r, `Created #${r.id} (${r.label}).`);
468
471
  }
469
472
  case "iterate": {
@@ -486,13 +489,13 @@ ${doc.latest?.content ?? "(no versions)"}`);
486
489
  process.exitCode = 1;
487
490
  return;
488
491
  }
489
- const format = flagStr(args.flags, "format") ?? "mdx";
492
+ const format = flagStr(args.flags, "format");
490
493
  const content = await readContent(args.flags, "");
491
494
  if (!flags(args, "yes") && !flags(args, "y") && !await confirm(`Add iterate version off ${parent} on #${id}?`)) {
492
495
  console.log("Aborted.");
493
496
  return;
494
497
  }
495
- const r = await client.addVersion(id, { intent: "iterate", parentLabel: parent, content, format });
498
+ const r = await client.addVersion(id, { intent: "iterate", parentLabel: parent, content, ...format ? { format } : {} });
496
499
  return out(json, r, `Added ${r.label}.`);
497
500
  }
498
501
  case "branch": {
@@ -506,15 +509,35 @@ ${doc.latest?.content ?? "(no versions)"}`);
506
509
  process.exitCode = 1;
507
510
  return;
508
511
  }
509
- const format = flagStr(args.flags, "format") ?? "mdx";
512
+ const format = flagStr(args.flags, "format");
510
513
  const content = await readContent(args.flags, "");
511
514
  if (!flags(args, "yes") && !flags(args, "y") && !await confirm(`Branch off ${parent} on #${id}?`)) {
512
515
  console.log("Aborted.");
513
516
  return;
514
517
  }
515
- const r = await client.addVersion(id, { intent: "branch", parentLabel: parent, content, format });
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,8 @@ 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
565
+ (omit --format to auto-detect mdx/html from content)
541
566
 
542
567
  Global flags: --base-url <url>, --json, -y/--yes
543
568
  Env: MD_PROMPT_API_KEY, MD_PROMPT_BASE_URL (shared with the 'prompt' skill)`;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@addorimprove/prompt",
3
- "version": "0.1.2",
3
+ "version": "0.3.0",
4
4
  "type": "module",
5
5
  "bin": { "prompt": "dist/prompt.js" },
6
6
  "files": ["dist"],