aboutsummaryrefslogtreecommitdiff
path: root/src/countries.ts
diff options
context:
space:
mode:
authorPridon Tetradze <[email protected]>2022-12-10 12:07:19 +0400
committerGitHub <[email protected]>2022-12-10 12:07:19 +0400
commitcb43f40f8f3c9e495f025359eed6e24a6542f47f (patch)
tree99ac12a50e997a78309d08b676b1a3d55e5d3096 /src/countries.ts
parentc7e06f35d9f4b6ac685d59de0ea7d062f520d0e0 (diff)
downloadcountryfetch-cb43f40f8f3c9e495f025359eed6e24a6542f47f.tar.xz
countryfetch-cb43f40f8f3c9e495f025359eed6e24a6542f47f.zip
add progress logger (#11)
Diffstat (limited to 'src/countries.ts')
-rw-r--r--src/countries.ts18
1 files changed, 13 insertions, 5 deletions
diff --git a/src/countries.ts b/src/countries.ts
index 2485c49..e2230dc 100644
--- a/src/countries.ts
+++ b/src/countries.ts
@@ -43,10 +43,9 @@ export class Countries {
this.cache.saveTxt("last-synced", JSON.stringify(Date.now()));
if (config?.flagAscii) {
- this.logger.alert(
- "Generating ASCII art for each country flag. This may take a minute..."
- );
- const flagStrings = await this.generateFlagImgs(countries);
+ const logTitle =
+ "Generating ASCII art for each country flag. This may take a minute...";
+ const flagStrings = await this.generateFlagImgs(countries, logTitle);
this.flags = flagStrings;
this.cache.saveJson("flags", flagStrings);
}
@@ -173,8 +172,12 @@ export class Countries {
return result.join(" | ");
}
- private async generateFlagImgs(countries: Country[]): Promise<FlagAscii[]> {
+ private async generateFlagImgs(
+ countries: Country[],
+ logTitle?: string
+ ): Promise<FlagAscii[]> {
const data = [];
+ let index = 0;
for (const country of countries) {
// Replace png with jpg as the library used has trouble with png
const flagUrl = country.flags["png"].replace(".png", ".jpg");
@@ -183,6 +186,11 @@ export class Countries {
countryName: country.name.common,
flagString,
});
+ index++;
+ this.logger.progress(index, countries.length, {
+ title: logTitle,
+ description: "Generating a flag for " + country.name.common,
+ });
}
return data;
}