-
Notifications
You must be signed in to change notification settings - Fork 55
Expand file tree
/
Copy pathgenerate-ramadhan-wrapped-2026.ts
More file actions
54 lines (44 loc) · 1.47 KB
/
generate-ramadhan-wrapped-2026.ts
File metadata and controls
54 lines (44 loc) · 1.47 KB
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
46
47
48
49
50
51
52
53
54
#!/usr/bin/env bun
import fs from "node:fs";
import path from "node:path";
import {
buildRamadhanWrappedMarkdown,
getRamadhanWrappedStats,
RAMADHAN_WRAPPED_CONFIG,
} from "@/lib/ramadhan-wrapped";
function resolveOutDir(argv: string[]): string {
const outDirFlag = argv.find((arg) => arg.startsWith("--outDir="));
if (outDirFlag) {
return path.resolve(outDirFlag.replace("--outDir=", ""));
}
const idx = argv.indexOf("--outDir");
if (idx !== -1 && argv[idx + 1]) {
return path.resolve(argv[idx + 1]);
}
return path.resolve(process.cwd(), "reports");
}
async function main() {
const outDir = resolveOutDir(process.argv.slice(2));
const stats = await getRamadhanWrappedStats();
const markdown = buildRamadhanWrappedMarkdown(stats);
fs.mkdirSync(outDir, { recursive: true });
const dateLabel = `${RAMADHAN_WRAPPED_CONFIG.startDate}_to_${RAMADHAN_WRAPPED_CONFIG.endDate}`;
const jsonPath = path.join(
outDir,
`ramadhan-wrapped-${RAMADHAN_WRAPPED_CONFIG.year}-${dateLabel}.json`,
);
const mdPath = path.join(
outDir,
`ramadhan-wrapped-${RAMADHAN_WRAPPED_CONFIG.year}-${dateLabel}.md`,
);
fs.writeFileSync(jsonPath, `${JSON.stringify(stats, null, 2)}\n`, "utf-8");
fs.writeFileSync(mdPath, markdown, "utf-8");
console.log("Ramadhan Wrapped report generated.");
console.log(`JSON: ${jsonPath}`);
console.log(`MD: ${mdPath}`);
process.exit(0);
}
main().catch((error) => {
console.error("Failed to generate Ramadhan Wrapped report:", error);
process.exit(1);
});