Skip to content

Commit ef5e008

Browse files
committed
1 parent e59bf92 commit ef5e008

File tree

1 file changed

+50
-52
lines changed

1 file changed

+50
-52
lines changed

scripts/APIv3.js

+50-52
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
11
#!/usr/bin/env node
22

3-
const fs = require("fs");
4-
const path = require("path");
3+
const fs = require('fs');
4+
const path = require('path');
55

66
let all = {};
77
let tfa = {};
88
let regions = {};
99

1010
// Read all JSON files from the 'entries' directory
11-
fs.readdirSync("entries").forEach((dir) => {
12-
fs.readdirSync(path.join("entries", dir)).forEach((file) => {
13-
if (file.endsWith(".json")) {
11+
fs.readdirSync('entries').forEach((dir) => {
12+
fs.readdirSync(path.join('entries', dir)).forEach((file) => {
13+
if (file.endsWith('.json')) {
1414
let data = JSON.parse(
15-
fs.readFileSync(path.join("entries", dir, file), "utf8"),
15+
fs.readFileSync(path.join('entries', dir, file), 'utf8'),
1616
);
1717
let key = Object.keys(data)[0];
1818
all[key] = data[key];
@@ -21,72 +21,70 @@ fs.readdirSync("entries").forEach((dir) => {
2121
});
2222

2323
// Process all entries
24-
Object.keys(all)
25-
.sort()
26-
.forEach((entryName) => {
27-
let entry = all[entryName];
28-
29-
// Process tfa methods
30-
if ("tfa" in entry) {
31-
entry["tfa"].forEach((method) => {
32-
if (!tfa[method]) tfa[method] = {};
33-
34-
tfa[method][entryName] = entry;
35-
});
36-
}
37-
38-
// Process regions
39-
if ("regions" in entry) {
40-
entry["regions"].forEach((region) => {
41-
if (region[0] !== "-") {
42-
if (!regions[region]) regions[region] = { count: 0 };
43-
44-
regions[region]["count"] += 1;
45-
}
46-
});
47-
}
48-
49-
// Rename 'categories' to 'keywords'
50-
if ("categories" in entry) {
51-
entry["keywords"] = entry["categories"];
52-
delete entry["categories"];
53-
}
54-
});
24+
Object.keys(all).sort().forEach((entryName) => {
25+
let entry = all[entryName];
26+
27+
// Process tfa methods
28+
if ('tfa' in entry) {
29+
entry['tfa'].forEach((method) => {
30+
if (!tfa[method]) tfa[method] = {};
31+
32+
tfa[method][entryName] = entry;
33+
});
34+
}
35+
36+
// Process regions
37+
if ('regions' in entry) {
38+
entry['regions'].forEach((region) => {
39+
if (region[0] !== '-') {
40+
if (!regions[region]) regions[region] = {count: 0};
41+
42+
regions[region]['count'] += 1;
43+
}
44+
});
45+
}
46+
47+
// Rename 'categories' to 'keywords'
48+
if ('categories' in entry) {
49+
entry['keywords'] = entry['categories'];
50+
delete entry['categories'];
51+
}
52+
});
5553

5654
// Write the all.json and tfa files
57-
const outputDir = "api/v3";
58-
if (!fs.existsSync(outputDir)) fs.mkdirSync(outputDir, { recursive: true });
55+
const outputDir = 'api/v3';
56+
if (!fs.existsSync(outputDir)) fs.mkdirSync(outputDir, {recursive: true});
5957

6058
const writeJsonFile = (filename, data) =>
6159
fs.writeFileSync(
6260
path.join(outputDir, filename),
63-
JSON.stringify(data, null, 2),
61+
JSON.stringify(data),
6462
);
6563

66-
writeJsonFile("all.json", { all });
64+
writeJsonFile('all.json', all);
6765

6866
Object.keys(tfa).forEach((method) =>
6967
writeJsonFile(`${method}.json`, tfa[method]),
7068
);
7169

7270
// Add the 'int' region
73-
regions["int"] = { count: Object.keys(all).length, selection: true };
71+
regions['int'] = {count: Object.keys(all).length, selection: true};
7472

7573
// Write regions.json
76-
const sortedRegions = Object.entries(regions)
77-
.sort(([, a], [, b]) => b.count - a.count)
78-
.reduce((acc, [k, v]) => {
74+
const sortedRegions = Object.entries(regions).
75+
sort(([, a], [, b]) => b.count - a.count).
76+
reduce((acc, [k, v]) => {
7977
acc[k] = v;
8078
return acc;
8179
}, {});
82-
writeJsonFile("regions.json", sortedRegions);
80+
writeJsonFile('regions.json', sortedRegions);
8381

8482
// Write tfa.json
85-
const tfaEntries = Object.entries(all)
86-
.filter(([, entry]) => entry.tfa)
87-
.sort(([a], [b]) => a.toLowerCase().localeCompare(b.toLowerCase()))
88-
.reduce((acc, [k, v]) => {
89-
acc[k] = v;
83+
const tfaEntries = Object.keys(all).
84+
filter((key) => all[key].tfa).
85+
sort((a, b) => a.toLowerCase().localeCompare(b.toLowerCase())).
86+
reduce((acc, key) => {
87+
acc[key] = all[key];
9088
return acc;
9189
}, {});
92-
writeJsonFile("tfa.json", tfaEntries);
90+
writeJsonFile('tfa.json', tfaEntries);

0 commit comments

Comments
 (0)