Skip to content

Commit ea417ed

Browse files
committed
feat: add summary json, improve logging
1 parent 98f2b38 commit ea417ed

File tree

1 file changed

+31
-11
lines changed

1 file changed

+31
-11
lines changed

src/scripts/crowdin/leaderboard/getLeaderboardReports.ts

Lines changed: 31 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -19,25 +19,27 @@ import "dotenv/config"
1919
const projectId = Number(process.env.CROWDIN_PROJECT_ID) || 363359
2020

2121
const dates = {
22-
allTime: {
23-
from: ALL_TIME_START,
24-
to: new Date().toISOString(),
22+
month: {
23+
from: getLastMonth().from,
24+
to: getLastMonth().to,
2525
},
2626
quarter: {
2727
from: getLastQuarter().from,
2828
to: getLastQuarter().to,
2929
},
30-
month: {
31-
from: getLastMonth().from,
32-
to: getLastMonth().to,
30+
allTime: {
31+
from: ALL_TIME_START,
32+
to: new Date().toISOString(),
3333
},
3434
}
3535

3636
const reports = Object.keys(dates)
3737

3838
async function main() {
3939
// Log calculated dates being used for report generation
40-
console.log(dates)
40+
console.table(dates)
41+
42+
const summary = {}
4143

4244
for (const report of reports) {
4345
// Generate a report for the given date range
@@ -63,11 +65,29 @@ async function main() {
6365
const data = parseData(json)
6466

6567
// Write parsed data to file system
66-
fs.writeFileSync(
67-
join(DATA_SAVE_PATH, report, `${report}-data.json`).toLowerCase(),
68-
JSON.stringify(data, null, 2)
69-
)
68+
const filePath = join(
69+
DATA_SAVE_PATH,
70+
report,
71+
`${report}-data.json`
72+
).toLowerCase()
73+
fs.writeFileSync(filePath, JSON.stringify(data, null, 2))
74+
75+
// Add report to summary table
76+
summary[report] = {
77+
reportId,
78+
from: dates[report].from,
79+
to: dates[report].to,
80+
filePath,
81+
}
7082
}
83+
84+
// Write summary table
85+
fs.writeFileSync(
86+
join(DATA_SAVE_PATH, "leaderboard-import-summary.json"),
87+
JSON.stringify(summary, null, 2)
88+
)
89+
90+
console.table(summary, ["filePath"])
7191
}
7292

7393
main()

0 commit comments

Comments
 (0)