From a9386cb7072c54b3e43dfa2a520fc899da17445f Mon Sep 17 00:00:00 2001 From: Anand Chowdhary Date: Tue, 15 Nov 2022 22:27:14 +0100 Subject: [PATCH] :bug: Fix entries, summary key name --- src/cli.ts | 8 ++++---- src/common.ts | 5 +++++ 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/src/cli.ts b/src/cli.ts index 2a19ab7..322392b 100644 --- a/src/cli.ts +++ b/src/cli.ts @@ -13,7 +13,7 @@ import { Twitter, Wakatime, } from "./"; -import { zero } from "./common"; +import { sortObject, zero } from "./common"; const INTEGRATIONS = [ Clockify, @@ -70,8 +70,8 @@ const cli = async () => { for (const month of months) { const file = join(".", "data", dir, "summary", "days", year, month); const data = (await readJson(file)) as Record; - Object.values(data).forEach(([day, value]) => { - summary[`${zero(year)}-${zero(month)}-${zero(day)}`] = value; + Object.entries(data).forEach(([day, value]) => { + summary[`${zero(year)}-${zero(month.replace(".json", ""))}-${zero(day)}`] = value; }); } } @@ -80,7 +80,7 @@ const cli = async () => { if (Object.keys(summary).length) await writeFile( join(".", "data", dir, "summary", "days.json"), - JSON.stringify(summary, null, 2) + "\n" + JSON.stringify(sortObject(summary), null, 2) + "\n" ); } } else { diff --git a/src/common.ts b/src/common.ts index 90dbafb..23c8e2b 100644 --- a/src/common.ts +++ b/src/common.ts @@ -15,3 +15,8 @@ export const write = async (name: string, contents: any) => { }; export const zero = (num: string) => (parseInt(num) > 9 ? num : `0${num}`); + +export const sortObject = (o: Record) => + Object.keys(o) + .sort() + .reduce((r, k) => ((r[k] = o[k]), r), {} as Record);