Added US states to Geo game.
This commit is contained in:
+10
-4
@@ -2,9 +2,13 @@
|
||||
|
||||
const fs = require('fs').promises;
|
||||
const crypto = require('crypto');
|
||||
const { argv } = require('yargs');
|
||||
// const bhttp = require('bhttp');
|
||||
|
||||
const countries = require('./countries.json');
|
||||
const states = require('./states-us.json');
|
||||
|
||||
const data = { countries, states };
|
||||
|
||||
/*
|
||||
async function fetchCountries() {
|
||||
@@ -22,14 +26,16 @@ async function fetchCountries() {
|
||||
*/
|
||||
|
||||
async function init() {
|
||||
const countryImgs = await fs.readdir('./assets/countries');
|
||||
const countriesByCode = Object.fromEntries(countries.map((country) => [country.alpha2, country]));
|
||||
const type = argv.states ? 'states' : '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 filename = `${crypto.createHash('md5').update(code).digest('hex').slice(0, 4)}.png`;
|
||||
|
||||
await fs.copyFile(`./assets/countries/${file}`, `./assets/countries/encoded/${filename}`);
|
||||
await fs.copyFile(`./assets/${type}/${file}`, `./assets/${type}/encoded/${filename}`);
|
||||
|
||||
return {
|
||||
file: filename,
|
||||
@@ -38,7 +44,7 @@ async function init() {
|
||||
};
|
||||
}));
|
||||
|
||||
await fs.writeFile('./assets/countries-curated.json', JSON.stringify(imgCountries, null, 4));
|
||||
await fs.writeFile(`./assets/${type}-curated.json`, JSON.stringify(imgCountries, null, 4));
|
||||
|
||||
console.log('Done!');
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user