-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathstatus.js
45 lines (42 loc) · 1.15 KB
/
status.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
import config from "../config.js";
import fs from "node:fs/promises";
import { getDateDetails } from "./lib/get-date-details.js";
import path from "node:path";
import { runCommand } from "./lib/run-command.js";
import util from "node:util";
const {
positionals: [text],
} = util.parseArgs({ allowPositionals: true });
if (!text) {
throw new Error("Only 1 argument is required.");
}
const file = path.join(config.dir.data, "statuses.json");
const statuses = await fs.readFile(file).then(JSON.parse);
const published = Date.now();
const dt = getDateDetails(published);
const formatted = JSON.stringify(
[
{
description: text,
link: `/statuses/#${published}`,
published,
...dt,
title: text,
type: "status",
},
...statuses,
],
null,
2,
);
await fs.mkdir(path.dirname(file), { recursive: true });
await fs.writeFile(file, `${formatted}\n`);
await runCommand("git", ["add", "--", file]);
await runCommand("git", [
"commit",
"--message=Update status",
`--message=${text}`,
]);
const twitter = new URL("https://x.com/intent/tweet");
twitter.searchParams.append("text", text);
await runCommand("open", [twitter.href]);