mdpockla 0.2.0 → 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.
- package/README.md +5 -0
- package/package.json +1 -1
- package/src/commands/note.mjs +7 -15
- package/src/index.mjs +10 -2
package/README.md
CHANGED
|
@@ -48,6 +48,11 @@ mdpockla note version restore "$URL" 3
|
|
|
48
48
|
mdpockla note edit "$URL" --content ./CHANGELOG.md --save-version --label "Release $TAG"
|
|
49
49
|
```
|
|
50
50
|
|
|
51
|
+
`--save-version` applies the edit and snapshots the result as a new
|
|
52
|
+
version in a single request. If the note has no versions yet, the
|
|
53
|
+
pre-edit content is also captured as a baseline so the original stays
|
|
54
|
+
recoverable.
|
|
55
|
+
|
|
51
56
|
### Commands
|
|
52
57
|
|
|
53
58
|
```
|
package/package.json
CHANGED
package/src/commands/note.mjs
CHANGED
|
@@ -65,24 +65,16 @@ export async function noteEdit(argv) {
|
|
|
65
65
|
if (Object.keys(body).length === 0) {
|
|
66
66
|
throw exit("Nothing to update — pass at least one of --content, --title, --visibility, --tag");
|
|
67
67
|
}
|
|
68
|
+
// --save-version is handled server-side in one PATCH: the edit is
|
|
69
|
+
// applied and the result is snapshotted as a new version (plus a
|
|
70
|
+
// baseline of the pre-edit content when the note has no versions yet).
|
|
71
|
+
if (args["save-version"]) {
|
|
72
|
+
body.save_as_version = true;
|
|
73
|
+
if (args.label != null) body.version_label = args.label;
|
|
74
|
+
}
|
|
68
75
|
const note = await api("PATCH", `/api/v1/notes/${encodeURIComponent(target)}`, {
|
|
69
76
|
body,
|
|
70
77
|
});
|
|
71
|
-
if (args["save-version"]) {
|
|
72
|
-
try {
|
|
73
|
-
await api(
|
|
74
|
-
"POST",
|
|
75
|
-
`/api/v1/notes/${encodeURIComponent(target)}/versions`,
|
|
76
|
-
{ body: { label: args.label ?? null } }
|
|
77
|
-
);
|
|
78
|
-
} catch (err) {
|
|
79
|
-
// Snapshot failed but the edit landed — surface the warning but
|
|
80
|
-
// exit 0 so the user can see the share URL.
|
|
81
|
-
process.stderr.write(
|
|
82
|
-
`warning: --save-version failed: ${err.message ?? err}\n`
|
|
83
|
-
);
|
|
84
|
-
}
|
|
85
|
-
}
|
|
86
78
|
if (args.json) process.stdout.write(JSON.stringify(note, null, 2) + "\n");
|
|
87
79
|
else process.stdout.write(note.url + "\n");
|
|
88
80
|
}
|
package/src/index.mjs
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { readFileSync } from "node:fs";
|
|
1
2
|
import { login, logout, whoami } from "./commands/auth.mjs";
|
|
2
3
|
import {
|
|
3
4
|
noteCreate,
|
|
@@ -15,6 +16,12 @@ import {
|
|
|
15
16
|
noteVersionDelete,
|
|
16
17
|
} from "./commands/note.mjs";
|
|
17
18
|
|
|
19
|
+
// Single source of truth for the version — read from package.json so
|
|
20
|
+
// `--version` can never drift from the published package again.
|
|
21
|
+
const VERSION = JSON.parse(
|
|
22
|
+
readFileSync(new URL("../package.json", import.meta.url), "utf8")
|
|
23
|
+
).version;
|
|
24
|
+
|
|
18
25
|
const HELP = `mdpockla — md.pockla.com from your shell.
|
|
19
26
|
|
|
20
27
|
Authentication
|
|
@@ -34,7 +41,8 @@ Notes
|
|
|
34
41
|
--title <s> Set title.
|
|
35
42
|
--visibility <public|private> Change visibility.
|
|
36
43
|
--tag <name> ... Replace tag set.
|
|
37
|
-
--save-version
|
|
44
|
+
--save-version Save the edit as a new version
|
|
45
|
+
(baselines the original first).
|
|
38
46
|
--label <s> Label for the new version.
|
|
39
47
|
|
|
40
48
|
mdpockla note get <id|url> Fetch a note.
|
|
@@ -72,7 +80,7 @@ export async function run(argv) {
|
|
|
72
80
|
return;
|
|
73
81
|
}
|
|
74
82
|
if (argv[0] === "--version" || argv[0] === "-V") {
|
|
75
|
-
process.stdout.write("
|
|
83
|
+
process.stdout.write(VERSION + "\n");
|
|
76
84
|
return;
|
|
77
85
|
}
|
|
78
86
|
const [cmd, ...rest] = argv;
|