This repository has been archived on 2024-07-22. You can view files and clone it, but cannot push or open issues or pull requests.
2021-09-07 10:11:15 -07:00
|
|
|
require('../src/dotenv')();
|
|
|
|
|
2021-06-09 23:45:13 -07:00
|
|
|
const dbConnection = require('./db');
|
|
|
|
const {calculateStats, statsFile} = require('../src/stats');
|
|
|
|
const locales = require('../src/locales');
|
|
|
|
const fs = require('fs');
|
|
|
|
|
|
|
|
// TODO duplication
|
|
|
|
const buildDict = (fn, ...args) => {
|
|
|
|
const dict = {};
|
|
|
|
for (let [key, value] of fn(...args)) {
|
|
|
|
dict[key] = value;
|
|
|
|
}
|
|
|
|
return dict;
|
|
|
|
}
|
|
|
|
const buildLocaleList = () => {
|
|
|
|
return buildDict(function* () {
|
|
|
|
for (let [code, name, url, published] of locales) {
|
|
|
|
if (published) {
|
|
|
|
yield [code, {name, url, published}];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
async function calculate() {
|
|
|
|
const db = await dbConnection();
|
|
|
|
const stats = await calculateStats(db, buildLocaleList());
|
|
|
|
await db.close();
|
|
|
|
|
|
|
|
console.log(stats);
|
|
|
|
fs.writeFileSync(statsFile, JSON.stringify(stats));
|
|
|
|
}
|
|
|
|
|
|
|
|
calculate();
|