@nulab/bee 1.1.2 → 1.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.
@@ -1,11 +1,10 @@
1
1
  import { y as getClient } from "./src-CTD9-bSB.mjs";
2
2
  import { t as outputResult } from "./output-DBvfyU1J.mjs";
3
3
  import { o as vFiniteNumber, u as UserError } from "./src-CP4YLIAh.mjs";
4
+ import { t as readFileOrStdin } from "./file-DwPTUKOI.mjs";
4
5
  import { n as ENV_AUTH, t as BeeCommand } from "./bee-command-v0qvZeth.mjs";
5
6
  import { S as space, a as collect } from "./common-options-BuYWxYdO.mjs";
6
- import { text } from "node:stream/consumers";
7
7
  import * as v from "valibot";
8
- import { readFile } from "node:fs/promises";
9
8
  //#region src/commands/api.ts
10
9
  const api = new BeeCommand("api").summary("Make an authenticated API request").description(`The endpoint is a Backlog API path (e.g. \`users/myself\`). A leading \`/api/v2/\` prefix is stripped automatically.
11
10
 
@@ -69,16 +68,8 @@ const normalizeEndpoint = (endpoint) => {
69
68
  * Number("\n") is 0.
70
69
  */
71
70
  const readFieldValue = async (ref) => {
72
- if (ref === "-") return text(process.stdin);
73
71
  if (ref === "") throw new UserError("Invalid file reference: \"@\". Provide a file path after @ or use @- for stdin.");
74
- try {
75
- return await readFile(ref, "utf8");
76
- } catch (error) {
77
- const { code } = error;
78
- if (code === "ENOENT") throw new UserError(`File not found: ${ref}`);
79
- if (code === "EISDIR") throw new UserError(`Expected a file but got a directory: ${ref}`);
80
- throw error;
81
- }
72
+ return readFileOrStdin(ref);
82
73
  };
83
74
  /**
84
75
  * Build params object from --field and --raw-field values.
@@ -87,7 +87,7 @@ const renderCompletionScript = (shell, program) => RENDERERS[shell](commandEntri
87
87
  * action defers the lookup until every module has finished evaluating.
88
88
  */
89
89
  const buildProgram = async () => {
90
- const { loadCommands } = await import("./registry-RATsKPUm.mjs");
90
+ const { loadCommands } = await import("./registry-D8DfbunX.mjs");
91
91
  const program = new BeeCommand("bee");
92
92
  await program.addCommands(loadCommands());
93
93
  return program;
@@ -7,6 +7,7 @@ await document.addCommands([
7
7
  import("./tree-CozBqPbN.mjs"),
8
8
  import("./attachments-CnL8t9tK.mjs"),
9
9
  import("./create-BHjwacOk.mjs"),
10
+ import("./edit-BfCZ2Abi.mjs"),
10
11
  import("./delete-BHNt5SWa.mjs")
11
12
  ]);
12
13
  //#endregion
@@ -0,0 +1,50 @@
1
+ import { y as getClient } from "./src-CTD9-bSB.mjs";
2
+ import { t as outputResult } from "./output-DBvfyU1J.mjs";
3
+ import { u as UserError } from "./src-CP4YLIAh.mjs";
4
+ import { t as readFileOrStdin } from "./file-DwPTUKOI.mjs";
5
+ import { n as ENV_AUTH, t as BeeCommand } from "./bee-command-v0qvZeth.mjs";
6
+ import { S as space, u as json } from "./common-options-BuYWxYdO.mjs";
7
+ import consola from "consola";
8
+ import { updateDocument, updateDocumentContent } from "backlog-js";
9
+ //#region src/commands/document/edit.ts
10
+ const edit = new BeeCommand("edit").summary("Edit a document").description(`Update the title or emoji, or replace the entire document body. Pass an empty value to clear a field. Use \`--body-file -\` to read the body from stdin.
11
+
12
+ The body is the Pandoc Markdown that \`bee document view --json plain\` returns, which keeps the document structure in attributes such as \`{#H-1}\`. Edit that Markdown and send it back, keeping the attributes you do not mean to change: a heading sent without its ID loses it, which breaks links to it. Backlog applies only the difference, so untouched parts and people editing in the browser are not disturbed.`).argument("<document>", "Document ID").option("-t, --title <text>", "New title of the document").option("--emoji <emoji>", "New emoji for the document").option("-b, --body <text>", "New Markdown body of the document").option("--body-file <path>", "Read the new Markdown body from a file or stdin").addOption(json()).addOption(space()).envVars([...ENV_AUTH]).examples([
13
+ {
14
+ description: "Update the title",
15
+ command: "bee document edit 12345 -t \"Meeting Notes\""
16
+ },
17
+ {
18
+ description: "Remove the emoji",
19
+ command: "bee document edit 12345 --emoji \"\""
20
+ },
21
+ {
22
+ description: "Save the body as Markdown to edit locally",
23
+ command: "bee document view 12345 --json plain | jq -r .plain > notes.md"
24
+ },
25
+ {
26
+ description: "Replace the body with the edited file",
27
+ command: "bee document edit 12345 --body-file notes.md"
28
+ }
29
+ ]).action(async (documentId, opts) => {
30
+ const { title, emoji, body, bodyFile } = opts;
31
+ const hasMetadata = title !== void 0 || emoji !== void 0;
32
+ const hasBody = body !== void 0 || bodyFile !== void 0;
33
+ if (body !== void 0 && bodyFile !== void 0) throw new UserError("Use either --body or --body-file.");
34
+ if (hasMetadata === hasBody) throw new UserError("Provide --title or --emoji for a metadata edit, or --body or --body-file for a body edit.");
35
+ const content = bodyFile === void 0 ? body : await readFileOrStdin(bodyFile);
36
+ const { client } = await getClient(opts.space);
37
+ const result = content === void 0 ? await updateDocument(client, documentId, {
38
+ title,
39
+ emoji
40
+ }) : await updateDocumentContent(client, documentId, content);
41
+ outputResult(result, opts, (data) => {
42
+ if ("code" in data && typeof data.code === "string") {
43
+ if (data.code === "NO_CHANGE") consola.info(`Document ${data.id} already has this content`);
44
+ else consola.warn(`Backlog left document ${data.id} unchanged (${data.code})`);
45
+ } else consola.success(`Updated document ${data.title} (ID: ${data.id})`);
46
+ if ("markdownIsFallback" in data && data.markdownIsFallback) consola.warn("Backlog returned fallback text. Open the document in Backlog before editing its body again.");
47
+ });
48
+ });
49
+ //#endregion
50
+ export { edit as default };
@@ -0,0 +1,17 @@
1
+ import { u as UserError } from "./src-CP4YLIAh.mjs";
2
+ import { text } from "node:stream/consumers";
3
+ import { readFile } from "node:fs/promises";
4
+ //#region ../../packages/cli-utils/src/file.ts
5
+ const readFileOrStdin = async (path) => {
6
+ if (path === "-") return text(process.stdin);
7
+ try {
8
+ return await readFile(path, "utf8");
9
+ } catch (error) {
10
+ const { code } = error;
11
+ if (code === "ENOENT") throw new UserError(`File not found: ${path}`);
12
+ if (code === "EISDIR") throw new UserError(`Expected a file but got a directory: ${path}`);
13
+ throw error;
14
+ }
15
+ };
16
+ //#endregion
17
+ export { readFileOrStdin as t };
package/dist/index.mjs CHANGED
@@ -1,6 +1,6 @@
1
1
  import { M as handleBacklogApiError, t as installHttpDispatcher } from "./src-CTD9-bSB.mjs";
2
2
  import { t as handleValidationError, u as UserError } from "./src-CP4YLIAh.mjs";
3
- import { t as loadCommands } from "./registry-B0ZQfBD5.mjs";
3
+ import { t as loadCommands } from "./registry-PlBmfTR4.mjs";
4
4
  import { t as BeeCommand } from "./bee-command-v0qvZeth.mjs";
5
5
  import consola, { LogLevels } from "consola";
6
6
  import { CommanderError } from "commander";
@@ -18,7 +18,7 @@ const handleError = (error) => {
18
18
  };
19
19
  //#endregion
20
20
  //#region package.json
21
- var version = "1.1.2";
21
+ var version = "1.2.0";
22
22
  var description = "Bring Backlog to your command line";
23
23
  //#endregion
24
24
  //#region src/index.ts
@@ -0,0 +1,2 @@
1
+ import { t as loadCommands } from "./registry-PlBmfTR4.mjs";
2
+ export { loadCommands };
@@ -11,7 +11,7 @@ const commandModules = [
11
11
  () => import("./auth-5TJGBPxi.mjs"),
12
12
  () => import("./project-Dilo1T5e.mjs"),
13
13
  () => import("./issue-BRzJy3k1.mjs"),
14
- () => import("./document-CiIzSyoS.mjs"),
14
+ () => import("./document-vTiqLew9.mjs"),
15
15
  () => import("./notification-CsOuC8Uk.mjs"),
16
16
  () => import("./pr-BBe07JUp.mjs"),
17
17
  () => import("./repo-B2K8y0mD.mjs"),
@@ -27,8 +27,8 @@ const commandModules = [
27
27
  () => import("./watching-D22YYxOT.mjs"),
28
28
  () => import("./dashboard-CYYU5Yii.mjs"),
29
29
  () => import("./browse-vgF6nz7X.mjs"),
30
- () => import("./api-kJR0fRPw.mjs"),
31
- () => import("./completion-yfcnEl7k.mjs")
30
+ () => import("./api-DhA8avDD.mjs"),
31
+ () => import("./completion-yX2VOQSl.mjs")
32
32
  ];
33
33
  const loadCommands = () => commandModules.map((load) => load());
34
34
  //#endregion
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nulab/bee",
3
- "version": "1.1.2",
3
+ "version": "1.2.0",
4
4
  "description": "Bring Backlog to your command line",
5
5
  "keywords": [
6
6
  "backlog",
@@ -31,7 +31,7 @@
31
31
  "access": "public"
32
32
  },
33
33
  "dependencies": {
34
- "backlog-js": "^1.1.0",
34
+ "backlog-js": "^1.2.0",
35
35
  "commander": "^14.0.3",
36
36
  "consola": "^3.4.2",
37
37
  "is-unicode-supported": "^2.1.0",
@@ -40,10 +40,10 @@
40
40
  },
41
41
  "devDependencies": {
42
42
  "tsx": "^4.23.12",
43
- "@repo/backlog-utils": "0.0.0",
44
- "@repo/cli-utils": "0.0.0",
45
43
  "@repo/config": "0.0.0",
46
44
  "@repo/test-utils": "0.0.0",
45
+ "@repo/cli-utils": "0.0.0",
46
+ "@repo/backlog-utils": "0.0.0",
47
47
  "@repo/tsconfigs": "0.0.0"
48
48
  },
49
49
  "devEngines": {
@@ -1,2 +0,0 @@
1
- import { t as loadCommands } from "./registry-B0ZQfBD5.mjs";
2
- export { loadCommands };