mirror of
https://github.com/factbook/factbook.json.git
synced 2026-07-01 19:49:37 +02:00
37 lines
1 KiB
JavaScript
37 lines
1 KiB
JavaScript
|
|
const fs = require('fs');
|
||
|
|
|
||
|
|
const exclude = ['almanac.md', 'readme.md', 'summary.md', 'buildindex.js', 'package.json', 'meta', '.git', 'countryindex.json'];
|
||
|
|
|
||
|
|
const countryIndex = [];
|
||
|
|
|
||
|
|
const readFile = (dir, file) => {
|
||
|
|
const country = JSON.parse(fs.readFileSync(`${dir}/${file}`).toString());
|
||
|
|
const currentCountry = {
|
||
|
|
directory: dir,
|
||
|
|
filename: file
|
||
|
|
};
|
||
|
|
|
||
|
|
if (country.Government['Country name'] && country.Government['Country name']['conventional short form']) {
|
||
|
|
currentCountry.country = country.Government['Country name']['conventional short form'].text;
|
||
|
|
} else {
|
||
|
|
currentCountry.country = '';
|
||
|
|
}
|
||
|
|
|
||
|
|
countryIndex.push(currentCountry);
|
||
|
|
};
|
||
|
|
|
||
|
|
const readDir = (dir) => {
|
||
|
|
if (!exclude.includes(dir.toLowerCase())) {
|
||
|
|
const continent = fs.readdirSync(dir);
|
||
|
|
continent.forEach((country) => {
|
||
|
|
readFile(dir, country);
|
||
|
|
});
|
||
|
|
}
|
||
|
|
};
|
||
|
|
|
||
|
|
const continents = fs.readdirSync('./');
|
||
|
|
continents.forEach((continent) => {
|
||
|
|
readDir(continent);
|
||
|
|
});
|
||
|
|
|
||
|
|
fs.writeFileSync('countryIndex.json', JSON.stringify(countryIndex, null, 2));
|