Created dist folder if doesn't exists

This commit is contained in:
DrMint 2024-07-13 20:39:29 +02:00
parent 9679bc77fd
commit ba6de7244a
1 changed files with 5 additions and 1 deletions

View File

@ -1,5 +1,5 @@
// @ts-check
import { writeFileSync, readFileSync, existsSync } from "fs";
import { writeFileSync, readFileSync, existsSync, mkdirSync } from "fs";
const OPEN_EXCHANGE_FOLDER = `${process.cwd()}/src/dist/openExchange`;
const RATE_JSON_PATH = `${OPEN_EXCHANGE_FOLDER}/rates.json`;
@ -29,6 +29,10 @@ const currenciesUrl = `https://openexchangerates.org/api/currencies.json?app_id=
const rates = await fetch(ratesUrl);
if (!existsSync(OPEN_EXCHANGE_FOLDER)) {
mkdirSync(OPEN_EXCHANGE_FOLDER, { recursive: true });
}
if (rates.ok) {
writeFileSync(RATE_JSON_PATH, await rates.text(), {
encoding: "utf-8",