Added flags to Geo.
This commit is contained in:
+14
-5
@@ -8,7 +8,11 @@ const { argv } = require('yargs');
|
||||
const countries = require('./countries.json');
|
||||
const states = require('./states-us.json');
|
||||
|
||||
const data = { countries, states };
|
||||
const data = {
|
||||
countries,
|
||||
states,
|
||||
flags: countries,
|
||||
};
|
||||
|
||||
/*
|
||||
async function fetchCountries() {
|
||||
@@ -26,13 +30,18 @@ async function fetchCountries() {
|
||||
*/
|
||||
|
||||
async function init() {
|
||||
const type = argv.states ? 'states' : 'countries';
|
||||
const type = argv.type || 'countries';
|
||||
|
||||
const countryImgs = await fs.readdir(`./assets/${type}`);
|
||||
const countriesByCode = Object.fromEntries(data[type].map((country) => [country.alpha2, country]));
|
||||
|
||||
const imgCountries = await Promise.all(countryImgs.filter((file) => !['encoded', 'disabled'].includes(file)).map(async (file) => {
|
||||
const code = file.match(/(\w+).png/)[1];
|
||||
const imgCountries = await Promise.all(countryImgs.map(async (file) => {
|
||||
const code = file.match(/(\w+).png/)?.[1];
|
||||
|
||||
if (!code || !countriesByCode[code]) {
|
||||
return null;
|
||||
}
|
||||
|
||||
const filename = `${crypto.createHash('md5').update(code).digest('hex').slice(0, 4)}.png`;
|
||||
|
||||
await fs.copyFile(`./assets/${type}/${file}`, `./assets/${type}/encoded/${filename}`);
|
||||
@@ -42,7 +51,7 @@ async function init() {
|
||||
code,
|
||||
...countriesByCode[code],
|
||||
};
|
||||
}));
|
||||
}).filter(Boolean));
|
||||
|
||||
await fs.writeFile(`./assets/${type}-curated.json`, JSON.stringify(imgCountries, null, 4));
|
||||
|
||||
|
||||
Reference in New Issue
Block a user