add generateCountryOptions.ts

This commit is contained in:
turnoffthiscomputer
2024-10-26 11:10:28 +02:00
parent 792a1a454f
commit 5e8a8f9be6
2 changed files with 26 additions and 0 deletions

View File

@@ -0,0 +1,24 @@
import { countryCodes } from '../constants/constants';
import getCountryISO2 from "country-iso-3-to-2";
import { flag } from 'country-emoji';
import fs from 'fs';
import path from 'path';
try {
console.log('Generating country options...');
const countryOptions = Object.keys(countryCodes).map((countryCode, index) => ({
countryCode,
countryName: countryCodes[countryCode as keyof typeof countryCodes],
flagEmoji: flag(getCountryISO2(countryCode)),
index,
}));
const outputPath = path.join(__dirname, './countryOptions.json');
fs.writeFileSync(outputPath, JSON.stringify(countryOptions, null, 2));
console.log(`Generated country options at ${outputPath}`);
} catch (error) {
console.error('Error generating country options:', error);
process.exit(1);
}