innernote 0.1.0 → 0.1.1

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/index.js +26 -15
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -48,6 +48,14 @@ async function clearToken() {
48
48
  }
49
49
  var configPath = CONFIG_FILE;
50
50
 
51
+ // src/invocation.ts
52
+ var CMD = /[/\\]_npx[/\\]/.test(process.argv[1] ?? "") ? "npx innernote" : "innernote";
53
+ function retarget(text, cmd = CMD) {
54
+ if (cmd === "innernote")
55
+ return text;
56
+ return text.replace(/(^|\| |\$\(|&& )innernote(?= )/g, `$1${cmd}`);
57
+ }
58
+
51
59
  // src/client.ts
52
60
  function isNotLoggedIn(err) {
53
61
  return err instanceof Error && err.name === "NotLoggedIn";
@@ -56,6 +64,9 @@ function isApiError(err) {
56
64
  return err instanceof Error && err.name === "ApiError";
57
65
  }
58
66
 
67
+ // src/invocation.ts
68
+ var CMD2 = /[/\\]_npx[/\\]/.test(process.argv[1] ?? "") ? "npx innernote" : "innernote";
69
+
59
70
  // src/commands/auth.ts
60
71
  import { hostname } from "node:os";
61
72
 
@@ -130,7 +141,7 @@ async function requestWith(config, path, options = {}) {
130
141
  const payload = parsed ?? {};
131
142
  if (!response.ok) {
132
143
  if (response.status === 401) {
133
- throw new ApiError("That token is not valid any more. Run `innernote login` to reconnect.", 401, payload);
144
+ throw new ApiError(`That token is not valid any more. Run \`${CMD} login\` to reconnect.`, 401, payload);
134
145
  }
135
146
  const message = typeof payload.message === "string" && payload.message || typeof payload.error === "string" && payload.error || `Request failed (${response.status}).`;
136
147
  throw new ApiError(message, response.status, payload);
@@ -336,7 +347,7 @@ async function login(args) {
336
347
  out();
337
348
  if (!process.stdin.isTTY) {
338
349
  fail("No pairing code given, and there is no terminal to ask on.");
339
- note(dim2("Pass it directly: innernote login ABCD-2345"));
350
+ note(dim2(`Pass it directly: ${CMD} login ABCD-2345`));
340
351
  return 1;
341
352
  }
342
353
  code = (prompt("Pairing code:") ?? "").trim();
@@ -898,7 +909,7 @@ async function queue(args) {
898
909
  const id = rest[0];
899
910
  if (!id) {
900
911
  fail("Which post?");
901
- note(dim2("innernote queue <post-id> (ids come from `innernote drafts --json`)"));
912
+ note(dim2(`${CMD} queue <post-id> (ids come from \`${CMD} drafts --json\`)`));
902
913
  return 1;
903
914
  }
904
915
  const result = await request(`/api/posts/${encodeURIComponent(id)}/queue`, { method: "POST", timeoutMs: 60000 });
@@ -1312,7 +1323,7 @@ function commandHelp(name) {
1312
1323
  const c = COMMANDS[name];
1313
1324
  if (!c)
1314
1325
  return null;
1315
- const lines = ["", ` ${bold2(c.usage)}`, ` ${dim2(c.summary)}`];
1326
+ const lines = ["", ` ${bold2(retarget(c.usage))}`, ` ${dim2(c.summary)}`];
1316
1327
  if (c.detail)
1317
1328
  lines.push("", wrap3(c.detail, 74, " "));
1318
1329
  if (c.options?.length) {
@@ -1324,7 +1335,7 @@ function commandHelp(name) {
1324
1335
  if (c.examples?.length) {
1325
1336
  lines.push("");
1326
1337
  for (const ex of c.examples)
1327
- lines.push(` ${dim2("$")} ${ex}`);
1338
+ lines.push(` ${dim2("$")} ${retarget(ex)}`);
1328
1339
  }
1329
1340
  lines.push("");
1330
1341
  return lines.join(`
@@ -1395,27 +1406,27 @@ function landingDisconnected(apiUrl, version) {
1395
1406
  "",
1396
1407
  dim2("Write LinkedIn posts in your voice, without leaving here."),
1397
1408
  "",
1398
- `${caramel("innernote login")}${pad("", 5)}${dim2("connect this machine")}`,
1409
+ `${caramel(`${CMD} login`)}${pad("", Math.max(3, 20 - width(`${CMD} login`)))}${dim2("connect this machine")}`,
1399
1410
  dim2(`Get a code at ${apiUrl.replace(/^https?:\/\//, "")}/dashboard/settings`),
1400
1411
  ""
1401
1412
  ]);
1402
1413
  }
1403
1414
  function suggest(state) {
1404
1415
  if (state.scheduled === 0 && state.ideas > 0) {
1405
- return { command: "innernote ideas", why: "nothing scheduled, and you have things saved" };
1416
+ return { command: `${CMD} ideas`, why: "nothing scheduled, and you have things saved" };
1406
1417
  }
1407
1418
  if (state.scheduled === 0) {
1408
- return { command: "innernote write", why: "the week is empty" };
1419
+ return { command: `${CMD} write`, why: "the week is empty" };
1409
1420
  }
1410
1421
  if (state.ideas >= 5) {
1411
- return { command: "innernote ideas", why: "your inbox is filling up" };
1422
+ return { command: `${CMD} ideas`, why: "your inbox is filling up" };
1412
1423
  }
1413
- return { command: "innernote write", why: "start something" };
1424
+ return { command: `${CMD} write`, why: "start something" };
1414
1425
  }
1415
1426
  // package.json
1416
1427
  var package_default = {
1417
1428
  name: "innernote",
1418
- version: "0.1.0",
1429
+ version: "0.1.1",
1419
1430
  description: "Write LinkedIn posts in your voice, from the terminal.",
1420
1431
  type: "module",
1421
1432
  bin: {
@@ -1620,7 +1631,7 @@ function commandHelp2(name) {
1620
1631
  const c = COMMANDS2[name];
1621
1632
  if (!c)
1622
1633
  return null;
1623
- const lines = ["", ` ${bold2(c.usage)}`, ` ${dim2(c.summary)}`];
1634
+ const lines = ["", ` ${bold2(retarget(c.usage))}`, ` ${dim2(c.summary)}`];
1624
1635
  if (c.detail)
1625
1636
  lines.push("", wrap4(c.detail, 74, " "));
1626
1637
  if (c.options?.length) {
@@ -1632,7 +1643,7 @@ function commandHelp2(name) {
1632
1643
  if (c.examples?.length) {
1633
1644
  lines.push("");
1634
1645
  for (const ex of c.examples)
1635
- lines.push(` ${dim2("$")} ${ex}`);
1646
+ lines.push(` ${dim2("$")} ${retarget(ex)}`);
1636
1647
  }
1637
1648
  lines.push("");
1638
1649
  return lines.join(`
@@ -1941,7 +1952,7 @@ async function main() {
1941
1952
  const handler = COMMANDS3[command];
1942
1953
  if (!handler) {
1943
1954
  fail2(`Unknown command: ${command}`);
1944
- note2(dim4("Run `innernote --help` to see what there is."));
1955
+ note2(dim4(`Run \`${CMD2} --help\` to see what there is.`));
1945
1956
  return 1;
1946
1957
  }
1947
1958
  if (args.includes("--help")) {
@@ -1955,7 +1966,7 @@ main().then((code) => {
1955
1966
  }).catch((err) => {
1956
1967
  if (isNotLoggedIn(err)) {
1957
1968
  fail2("Not connected to an account.");
1958
- note2(dim4("Run `innernote login` to connect this machine."));
1969
+ note2(dim4(`Run \`${CMD2} login\` to connect this machine.`));
1959
1970
  process.exitCode = 2;
1960
1971
  return;
1961
1972
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "innernote",
3
- "version": "0.1.0",
3
+ "version": "0.1.1",
4
4
  "description": "Write LinkedIn posts in your voice, from the terminal.",
5
5
  "type": "module",
6
6
  "bin": {