@hhkaos/webmentions-widget 0.5.1 → 0.5.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/bin/snapshot.js +21 -6
- package/package.json +1 -1
package/bin/snapshot.js
CHANGED
|
@@ -17,6 +17,7 @@
|
|
|
17
17
|
|
|
18
18
|
import {readFile, writeFile, mkdir} from 'node:fs/promises';
|
|
19
19
|
import {dirname} from 'node:path';
|
|
20
|
+
import {pathToFileURL} from 'node:url';
|
|
20
21
|
|
|
21
22
|
import {getSnapshotMentions, mergeSnapshot, parseWebmentionJson} from '../src/core.js';
|
|
22
23
|
|
|
@@ -27,7 +28,7 @@ const RETRIES = 8;
|
|
|
27
28
|
const RETRY_DELAY_MS = 3000;
|
|
28
29
|
const MAX_RETRY_DELAY_MS = 30000;
|
|
29
30
|
|
|
30
|
-
function parseArgs(argv) {
|
|
31
|
+
export function parseArgs(argv) {
|
|
31
32
|
const args = {};
|
|
32
33
|
|
|
33
34
|
argv.forEach((arg, index) => {
|
|
@@ -36,7 +37,18 @@ function parseArgs(argv) {
|
|
|
36
37
|
}
|
|
37
38
|
|
|
38
39
|
const [flag, inline] = arg.slice(2).split('=');
|
|
39
|
-
|
|
40
|
+
|
|
41
|
+
if (inline !== undefined) {
|
|
42
|
+
args[flag] = inline;
|
|
43
|
+
return;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
const next = argv[index + 1];
|
|
47
|
+
|
|
48
|
+
// A flag is boolean when nothing follows it, or when what follows is
|
|
49
|
+
// another flag. `--full` as the last argument is the common case, and
|
|
50
|
+
// reading it as its (missing) value silently disabled it.
|
|
51
|
+
args[flag] = next === undefined || next.startsWith('--') ? true : next;
|
|
40
52
|
});
|
|
41
53
|
|
|
42
54
|
return args;
|
|
@@ -170,7 +182,10 @@ async function main() {
|
|
|
170
182
|
console.log(`Snapshot updated: ${before} → ${snapshot.count} mentions (lastId ${snapshot.lastId}).`);
|
|
171
183
|
}
|
|
172
184
|
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
185
|
+
// Only run when invoked as a command, so the helpers above stay testable.
|
|
186
|
+
if (process.argv[1] && import.meta.url === pathToFileURL(process.argv[1]).href) {
|
|
187
|
+
main().catch((error) => {
|
|
188
|
+
console.error(error);
|
|
189
|
+
process.exit(1);
|
|
190
|
+
});
|
|
191
|
+
}
|
package/package.json
CHANGED