innernote 0.1.0 → 0.1.2
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.
- package/dist/index.js +29 -15
- 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(
|
|
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);
|
|
@@ -333,10 +344,11 @@ async function login(args) {
|
|
|
333
344
|
let code = args.find((a) => !a.startsWith("-"))?.trim();
|
|
334
345
|
if (!code) {
|
|
335
346
|
out(`Open ${bold2(config.apiUrl + PAIR_PAGE)} and copy your pairing code.`);
|
|
347
|
+
out(dim2(`New here? Sign in at ${config.apiUrl.replace(/^https?:\/\//, "")} first.`));
|
|
336
348
|
out();
|
|
337
349
|
if (!process.stdin.isTTY) {
|
|
338
350
|
fail("No pairing code given, and there is no terminal to ask on.");
|
|
339
|
-
note(dim2(
|
|
351
|
+
note(dim2(`Pass it directly: ${CMD} login ABCD-2345`));
|
|
340
352
|
return 1;
|
|
341
353
|
}
|
|
342
354
|
code = (prompt("Pairing code:") ?? "").trim();
|
|
@@ -898,7 +910,7 @@ async function queue(args) {
|
|
|
898
910
|
const id = rest[0];
|
|
899
911
|
if (!id) {
|
|
900
912
|
fail("Which post?");
|
|
901
|
-
note(dim2(
|
|
913
|
+
note(dim2(`${CMD} queue <post-id> (ids come from \`${CMD} drafts --json\`)`));
|
|
902
914
|
return 1;
|
|
903
915
|
}
|
|
904
916
|
const result = await request(`/api/posts/${encodeURIComponent(id)}/queue`, { method: "POST", timeoutMs: 60000 });
|
|
@@ -1312,7 +1324,7 @@ function commandHelp(name) {
|
|
|
1312
1324
|
const c = COMMANDS[name];
|
|
1313
1325
|
if (!c)
|
|
1314
1326
|
return null;
|
|
1315
|
-
const lines = ["", ` ${bold2(c.usage)}`, ` ${dim2(c.summary)}`];
|
|
1327
|
+
const lines = ["", ` ${bold2(retarget(c.usage))}`, ` ${dim2(c.summary)}`];
|
|
1316
1328
|
if (c.detail)
|
|
1317
1329
|
lines.push("", wrap3(c.detail, 74, " "));
|
|
1318
1330
|
if (c.options?.length) {
|
|
@@ -1324,7 +1336,7 @@ function commandHelp(name) {
|
|
|
1324
1336
|
if (c.examples?.length) {
|
|
1325
1337
|
lines.push("");
|
|
1326
1338
|
for (const ex of c.examples)
|
|
1327
|
-
lines.push(` ${dim2("$")} ${ex}`);
|
|
1339
|
+
lines.push(` ${dim2("$")} ${retarget(ex)}`);
|
|
1328
1340
|
}
|
|
1329
1341
|
lines.push("");
|
|
1330
1342
|
return lines.join(`
|
|
@@ -1395,27 +1407,29 @@ function landingDisconnected(apiUrl, version) {
|
|
|
1395
1407
|
"",
|
|
1396
1408
|
dim2("Write LinkedIn posts in your voice, without leaving here."),
|
|
1397
1409
|
"",
|
|
1398
|
-
`${caramel(
|
|
1410
|
+
`${caramel(`${CMD} login`)}${pad("", Math.max(3, 20 - width(`${CMD} login`)))}${dim2("connect this machine")}`,
|
|
1399
1411
|
dim2(`Get a code at ${apiUrl.replace(/^https?:\/\//, "")}/dashboard/settings`),
|
|
1412
|
+
"",
|
|
1413
|
+
`${dim2("No account yet?")} ${caramel(apiUrl.replace(/^https?:\/\//, ""))}`,
|
|
1400
1414
|
""
|
|
1401
1415
|
]);
|
|
1402
1416
|
}
|
|
1403
1417
|
function suggest(state) {
|
|
1404
1418
|
if (state.scheduled === 0 && state.ideas > 0) {
|
|
1405
|
-
return { command:
|
|
1419
|
+
return { command: `${CMD} ideas`, why: "nothing scheduled, and you have things saved" };
|
|
1406
1420
|
}
|
|
1407
1421
|
if (state.scheduled === 0) {
|
|
1408
|
-
return { command:
|
|
1422
|
+
return { command: `${CMD} write`, why: "the week is empty" };
|
|
1409
1423
|
}
|
|
1410
1424
|
if (state.ideas >= 5) {
|
|
1411
|
-
return { command:
|
|
1425
|
+
return { command: `${CMD} ideas`, why: "your inbox is filling up" };
|
|
1412
1426
|
}
|
|
1413
|
-
return { command:
|
|
1427
|
+
return { command: `${CMD} write`, why: "start something" };
|
|
1414
1428
|
}
|
|
1415
1429
|
// package.json
|
|
1416
1430
|
var package_default = {
|
|
1417
1431
|
name: "innernote",
|
|
1418
|
-
version: "0.1.
|
|
1432
|
+
version: "0.1.2",
|
|
1419
1433
|
description: "Write LinkedIn posts in your voice, from the terminal.",
|
|
1420
1434
|
type: "module",
|
|
1421
1435
|
bin: {
|
|
@@ -1620,7 +1634,7 @@ function commandHelp2(name) {
|
|
|
1620
1634
|
const c = COMMANDS2[name];
|
|
1621
1635
|
if (!c)
|
|
1622
1636
|
return null;
|
|
1623
|
-
const lines = ["", ` ${bold2(c.usage)}`, ` ${dim2(c.summary)}`];
|
|
1637
|
+
const lines = ["", ` ${bold2(retarget(c.usage))}`, ` ${dim2(c.summary)}`];
|
|
1624
1638
|
if (c.detail)
|
|
1625
1639
|
lines.push("", wrap4(c.detail, 74, " "));
|
|
1626
1640
|
if (c.options?.length) {
|
|
@@ -1632,7 +1646,7 @@ function commandHelp2(name) {
|
|
|
1632
1646
|
if (c.examples?.length) {
|
|
1633
1647
|
lines.push("");
|
|
1634
1648
|
for (const ex of c.examples)
|
|
1635
|
-
lines.push(` ${dim2("$")} ${ex}`);
|
|
1649
|
+
lines.push(` ${dim2("$")} ${retarget(ex)}`);
|
|
1636
1650
|
}
|
|
1637
1651
|
lines.push("");
|
|
1638
1652
|
return lines.join(`
|
|
@@ -1941,7 +1955,7 @@ async function main() {
|
|
|
1941
1955
|
const handler = COMMANDS3[command];
|
|
1942
1956
|
if (!handler) {
|
|
1943
1957
|
fail2(`Unknown command: ${command}`);
|
|
1944
|
-
note2(dim4(
|
|
1958
|
+
note2(dim4(`Run \`${CMD2} --help\` to see what there is.`));
|
|
1945
1959
|
return 1;
|
|
1946
1960
|
}
|
|
1947
1961
|
if (args.includes("--help")) {
|
|
@@ -1955,7 +1969,7 @@ main().then((code) => {
|
|
|
1955
1969
|
}).catch((err) => {
|
|
1956
1970
|
if (isNotLoggedIn(err)) {
|
|
1957
1971
|
fail2("Not connected to an account.");
|
|
1958
|
-
note2(dim4(
|
|
1972
|
+
note2(dim4(`Run \`${CMD2} login\` to connect this machine.`));
|
|
1959
1973
|
process.exitCode = 2;
|
|
1960
1974
|
return;
|
|
1961
1975
|
}
|