Skip to content

Commit a9386cb

Browse files
🐛 Fix entries, summary key name
1 parent 69835b8 commit a9386cb

File tree

2 files changed

+9
-4
lines changed

2 files changed

+9
-4
lines changed

src/cli.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import {
1313
Twitter,
1414
Wakatime,
1515
} from "./";
16-
import { zero } from "./common";
16+
import { sortObject, zero } from "./common";
1717

1818
const INTEGRATIONS = [
1919
Clockify,
@@ -70,8 +70,8 @@ const cli = async () => {
7070
for (const month of months) {
7171
const file = join(".", "data", dir, "summary", "days", year, month);
7272
const data = (await readJson(file)) as Record<string, any>;
73-
Object.values(data).forEach(([day, value]) => {
74-
summary[`${zero(year)}-${zero(month)}-${zero(day)}`] = value;
73+
Object.entries(data).forEach(([day, value]) => {
74+
summary[`${zero(year)}-${zero(month.replace(".json", ""))}-${zero(day)}`] = value;
7575
});
7676
}
7777
}
@@ -80,7 +80,7 @@ const cli = async () => {
8080
if (Object.keys(summary).length)
8181
await writeFile(
8282
join(".", "data", dir, "summary", "days.json"),
83-
JSON.stringify(summary, null, 2) + "\n"
83+
JSON.stringify(sortObject(summary), null, 2) + "\n"
8484
);
8585
}
8686
} else {

src/common.ts

+5
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,8 @@ export const write = async (name: string, contents: any) => {
1515
};
1616

1717
export const zero = (num: string) => (parseInt(num) > 9 ? num : `0${num}`);
18+
19+
export const sortObject = <T>(o: Record<string, T>) =>
20+
Object.keys(o)
21+
.sort()
22+
.reduce((r, k) => ((r[k] = o[k]), r), {} as Record<string, T>);

0 commit comments

Comments
 (0)