@addorimprove/prompt 0.1.1 → 0.2.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 +13 -12
  2. package/package.json +1 -1
package/dist/prompt.js CHANGED
@@ -350,7 +350,7 @@ async function login(baseUrlFlag) {
350
350
  saveCredential({ user: me });
351
351
  console.log(`Logged in as ${me.name} <${me.email}>.`);
352
352
  }
353
- async function whoami(baseUrlFlag) {
353
+ async function whoami(baseUrlFlag, json = false) {
354
354
  const apiKey = resolveApiKey();
355
355
  if (!apiKey) {
356
356
  console.error("Not logged in. Run 'prompt login'.");
@@ -359,9 +359,9 @@ async function whoami(baseUrlFlag) {
359
359
  }
360
360
  const client = new ApiClient({ baseUrl: resolveBaseUrl(baseUrlFlag), apiKey });
361
361
  const me = await client.getMe();
362
- console.log(`${me.name} <${me.email}> (id: ${me.id})`);
362
+ console.log(json ? JSON.stringify(me, null, 2) : `${me.name} <${me.email}> (id: ${me.id})`);
363
363
  }
364
- async function logout(baseUrlFlag) {
364
+ async function logout(baseUrlFlag, json = false) {
365
365
  const apiKey = resolveApiKey();
366
366
  if (apiKey) {
367
367
  try {
@@ -370,7 +370,7 @@ async function logout(baseUrlFlag) {
370
370
  } catch {}
371
371
  }
372
372
  clearCredential();
373
- console.log("Logged out.");
373
+ console.log(json ? JSON.stringify({ loggedOut: true }, null, 2) : "Logged out.");
374
374
  }
375
375
 
376
376
  // src/commands.ts
@@ -399,9 +399,9 @@ async function run(args) {
399
399
  case "login":
400
400
  return login(baseFlag);
401
401
  case "logout":
402
- return logout(baseFlag);
402
+ return logout(baseFlag, json);
403
403
  case "whoami":
404
- return whoami(baseFlag);
404
+ return whoami(baseFlag, json);
405
405
  case "ls": {
406
406
  const client = requireClient(args.flags);
407
407
  if (!client)
@@ -456,14 +456,14 @@ ${doc.latest?.content ?? "(no versions)"}`);
456
456
  process.exitCode = 1;
457
457
  return;
458
458
  }
459
- const format = flagStr(args.flags, "format") ?? "mdx";
459
+ const format = flagStr(args.flags, "format");
460
460
  const content = await readContent(args.flags, `# ${name}
461
461
  `);
462
462
  if (!flags(args, "yes") && !flags(args, "y") && !await confirm(`Create document "${name}"?`)) {
463
463
  console.log("Aborted.");
464
464
  return;
465
465
  }
466
- const r = await client.createDoc({ name, content, format });
466
+ const r = await client.createDoc({ name, content, ...format ? { format } : {} });
467
467
  return out(json, r, `Created #${r.id} (${r.label}).`);
468
468
  }
469
469
  case "iterate": {
@@ -486,13 +486,13 @@ ${doc.latest?.content ?? "(no versions)"}`);
486
486
  process.exitCode = 1;
487
487
  return;
488
488
  }
489
- const format = flagStr(args.flags, "format") ?? "mdx";
489
+ const format = flagStr(args.flags, "format");
490
490
  const content = await readContent(args.flags, "");
491
491
  if (!flags(args, "yes") && !flags(args, "y") && !await confirm(`Add iterate version off ${parent} on #${id}?`)) {
492
492
  console.log("Aborted.");
493
493
  return;
494
494
  }
495
- const r = await client.addVersion(id, { intent: "iterate", parentLabel: parent, content, format });
495
+ const r = await client.addVersion(id, { intent: "iterate", parentLabel: parent, content, ...format ? { format } : {} });
496
496
  return out(json, r, `Added ${r.label}.`);
497
497
  }
498
498
  case "branch": {
@@ -506,13 +506,13 @@ ${doc.latest?.content ?? "(no versions)"}`);
506
506
  process.exitCode = 1;
507
507
  return;
508
508
  }
509
- const format = flagStr(args.flags, "format") ?? "mdx";
509
+ const format = flagStr(args.flags, "format");
510
510
  const content = await readContent(args.flags, "");
511
511
  if (!flags(args, "yes") && !flags(args, "y") && !await confirm(`Branch off ${parent} on #${id}?`)) {
512
512
  console.log("Aborted.");
513
513
  return;
514
514
  }
515
- const r = await client.addVersion(id, { intent: "branch", parentLabel: parent, content, format });
515
+ const r = await client.addVersion(id, { intent: "branch", parentLabel: parent, content, ...format ? { format } : {} });
516
516
  return out(json, r, `Branched → ${r.label}.`);
517
517
  }
518
518
  case "help":
@@ -538,6 +538,7 @@ Usage: prompt <command> [args] [flags] (or: npx @addorimprove/prompt <command>
538
538
  new --name <n> [-f file] [--format mdx|html] Create a document
539
539
  iterate <id> [--parent label] [-f file] Add a version on the same line
540
540
  branch <id> <parentLabel> [-f file] Fork a new line from a version
541
+ (omit --format to auto-detect mdx/html from content)
541
542
 
542
543
  Global flags: --base-url <url>, --json, -y/--yes
543
544
  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.1",
3
+ "version": "0.2.0",
4
4
  "type": "module",
5
5
  "bin": { "prompt": "dist/prompt.js" },
6
6
  "files": ["dist"],