-
Notifications
You must be signed in to change notification settings - Fork 80
/
build-flags.js
executable file
·52 lines (43 loc) · 1.36 KB
/
build-flags.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#!/usr/bin/env node
/* eslint-disable no-console */
const fs = require("fs");
const { optimize } = require("svgo");
const translationsPath = "./src/locales/en.json";
const sourcePath = "./node_modules/flagpack-core/svg/l/";
const distPath = "./src/assets/flags/";
const servers = require("./public/data/servers.json");
const communities = require("./src/data/communities.json");
const translations = require(translationsPath);
const countryCodeList = require("./node_modules/flagpack-core/countryCodeList.json");
let flags = [];
servers.forEach(s => {
let f = s.flag.toUpperCase();
if (!flags.includes(f)) {
flags.push(f);
}
});
communities.forEach(c => {
c.flags?.forEach(flag => {
let f = flag.toUpperCase();
if (!flags.includes(f)) {
flags.push(f);
}
});
});
fs.rmdirSync(distPath, { recursive: true });
fs.mkdirSync(distPath, { recursive: true });
flags.forEach(f => {
const content = fs.readFileSync(`${sourcePath}${f.toUpperCase()}.svg`);
const result = optimize(content, {
multipass: true
});
fs.writeFileSync(`${distPath}${f.toLowerCase()}.svg`, result.data);
});
let countries = {};
countryCodeList
.filter(c => flags.includes(c.alpha2))
.forEach(c => {
countries[c.alpha2.toLowerCase()] = c.countryName;
});
translations.countries = countries;
fs.writeFileSync(translationsPath, JSON.stringify(translations, 0, 2));