Run download currencies on precommit

This commit is contained in:
DrMint 2024-06-02 09:27:30 +02:00
parent e0735fd429
commit 2c2dde250e
7 changed files with 188 additions and 183 deletions

32
package-lock.json generated
View File

@ -1,12 +1,12 @@
{
"name": "v3.accords-library.com",
"version": "0.0.1",
"version": "3.0.0-beta.1",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "v3.accords-library.com",
"version": "0.0.1",
"version": "3.0.0-beta.1",
"dependencies": {
"@astrojs/check": "^0.7.0",
"@astrojs/node": "^8.2.5",
@ -22,9 +22,8 @@
"@types/ua-parser-js": "^0.7.39",
"astro-meta-tags": "^0.3.0",
"autoprefixer": "^10.4.19",
"bun-types": "^1.1.10",
"postcss-preset-env": "^9.5.14",
"prettier": "^3.2.5",
"prettier": "^3.3.0",
"prettier-plugin-astro": "^0.14.0",
"typescript": "^5.4.5"
},
@ -2904,15 +2903,6 @@
"resolved": "https://registry.npmjs.org/@types/unist/-/unist-3.0.2.tgz",
"integrity": "sha512-dqId9J8K/vGi5Zr7oo212BGii5m3q5Hxlkwy3WpYuKPklmBEvsbMYYyLxAQpSffdLl/gdW0XUpKWFvYmyoWCoQ=="
},
"node_modules/@types/ws": {
"version": "8.5.10",
"resolved": "https://registry.npmjs.org/@types/ws/-/ws-8.5.10.tgz",
"integrity": "sha512-vmQSUcfalpIq0R9q7uTo2lXs6eGIpt9wtnLdMv9LVpIjCA/+ufZRozlVoVelIYixx1ugCBKDhn89vnsEGOCx9A==",
"dev": true,
"dependencies": {
"@types/node": "*"
}
},
"node_modules/@types/yauzl": {
"version": "2.10.3",
"resolved": "https://registry.npmjs.org/@types/yauzl/-/yauzl-2.10.3.tgz",
@ -3818,16 +3808,6 @@
"node": "*"
}
},
"node_modules/bun-types": {
"version": "1.1.10",
"resolved": "https://registry.npmjs.org/bun-types/-/bun-types-1.1.10.tgz",
"integrity": "sha512-oBsZ0Bf9HEKr1Ta5bUYgVO6sHkZtTlfHlEj9DGpghZphNdhKI/38eZ5dk+/et/HrStT1sfykHBUW4ughmoNKog==",
"dev": true,
"dependencies": {
"@types/node": "~20.12.8",
"@types/ws": "~8.5.10"
}
},
"node_modules/camelcase": {
"version": "7.0.1",
"resolved": "https://registry.npmjs.org/camelcase/-/camelcase-7.0.1.tgz",
@ -7697,9 +7677,9 @@
}
},
"node_modules/prettier": {
"version": "3.2.5",
"resolved": "https://registry.npmjs.org/prettier/-/prettier-3.2.5.tgz",
"integrity": "sha512-3/GWa9aOC0YeD7LUfvOG2NiDyhOWRvt1k+rcKhOuYnMY24iiCphgneUfJDyFXd6rZCAnuLBv6UeAULtrhT/F4A==",
"version": "3.3.0",
"resolved": "https://registry.npmjs.org/prettier/-/prettier-3.3.0.tgz",
"integrity": "sha512-J9odKxERhCQ10OC2yb93583f6UnYutOeiV5i0zEDS7UGTdUt0u+y8erxl3lBKvwo/JHyyoEdXjwp4dke9oyZ/g==",
"devOptional": true,
"bin": {
"prettier": "bin/prettier.cjs"

View File

@ -12,7 +12,7 @@
"script:download-currencies": "npm run scripts/download-currencies.ts",
"script:download-wording-keys": "npm run scripts/download-wording-keys.ts",
"prettier": "prettier --write --list-different --plugin=prettier-plugin-astro .",
"precommit": "npm run script:download-payload-sdk && npm run script:download-wording-keys && npm run prettier && npm run astro check"
"precommit": "npm run script:download-currencies && npm run script:download-payload-sdk && npm run script:download-wording-keys && npm run prettier && npm run astro check"
},
"engines": {
"npm": ">=10.0.0",
@ -33,9 +33,8 @@
"@types/ua-parser-js": "^0.7.39",
"astro-meta-tags": "^0.3.0",
"autoprefixer": "^10.4.19",
"bun-types": "^1.1.10",
"postcss-preset-env": "^9.5.14",
"prettier": "^3.2.5",
"prettier": "^3.3.0",
"prettier-plugin-astro": "^0.14.0",
"typescript": "^5.4.5"
}

View File

@ -1,6 +1,21 @@
import { writeFileSync } from "fs";
import { writeFileSync, readFileSync, existsSync } from "fs";
const OPEN_EXCHANGE_FOLDER = `${process.cwd()}/src/shared/openExchange`;
const RATE_JSON_PATH = `${OPEN_EXCHANGE_FOLDER}/rates.json`;
const CURRENCIES_JSON_PATH = `${OPEN_EXCHANGE_FOLDER}/currencies.json`;
const ONE_DAY_IN_MS = 1_000 * 60 * 60 * 24;
if (existsSync(RATE_JSON_PATH)) {
const rateBuffer = readFileSync(RATE_JSON_PATH, { encoding: "utf-8" });
const rateJSON = JSON.parse(rateBuffer);
const timestamp = rateJSON.timestamp * 1000;
const diff = Date.now() - timestamp;
if (diff < ONE_DAY_IN_MS) {
console.log("Currencies and rates are already up to date");
process.exit();
}
}
const ratesUrl = `https://openexchangerates.org/api/latest.json?app_id=${
import.meta.env.OER_APP_ID
@ -12,7 +27,7 @@ const currenciesUrl = `https://openexchangerates.org/api/currencies.json?app_id=
const rates = await fetch(ratesUrl);
if (rates.ok) {
writeFileSync(`${OPEN_EXCHANGE_FOLDER}/rates.json`, await rates.text(), {
writeFileSync(RATE_JSON_PATH, await rates.text(), {
encoding: "utf-8",
});
} else {
@ -22,7 +37,7 @@ if (rates.ok) {
const currencies = await fetch(currenciesUrl);
if (currencies.ok) {
writeFileSync(`${OPEN_EXCHANGE_FOLDER}/currencies.json`, await currencies.text(), {
writeFileSync(CURRENCIES_JSON_PATH, await currencies.text(), {
encoding: "utf-8",
});
} else {

View File

@ -169,4 +169,4 @@
"ZAR": "South African Rand",
"ZMW": "Zambian Kwacha",
"ZWL": "Zimbabwean Dollar"
}
}

View File

@ -1,177 +1,177 @@
{
"disclaimer": "Usage subject to terms: https://openexchangerates.org/terms",
"license": "https://openexchangerates.org/license",
"timestamp": 1708779609,
"timestamp": 1717311606,
"base": "USD",
"rates": {
"AED": 3.673,
"AFN": 72.50001,
"ALL": 95.741233,
"AMD": 405.666135,
"ANG": 1.800674,
"AOA": 831.5,
"ARS": 837.615005,
"AUD": 1.525553,
"AFN": 71.74764,
"ALL": 92.774572,
"AMD": 388.026453,
"ANG": 1.800967,
"AOA": 856.5,
"ARS": 895.75,
"AUD": 1.501051,
"AWG": 1.8,
"AZN": 1.7,
"BAM": 1.804826,
"BAM": 1.801335,
"BBD": 2,
"BDT": 109.657196,
"BGN": 1.804826,
"BHD": 0.376764,
"BIF": 2866,
"BDT": 117.319831,
"BGN": 1.80376,
"BHD": 0.376146,
"BIF": 2869.825082,
"BMD": 1,
"BND": 1.344887,
"BOB": 6.90352,
"BRL": 4.9955,
"BND": 1.350863,
"BOB": 6.919641,
"BRL": 5.2463,
"BSD": 1,
"BTC": 0.000019582906,
"BTN": 83.045533,
"BWP": 13.736447,
"BYN": 3.26969,
"BZD": 2.013934,
"CAD": 1.34865,
"CDF": 2763.615809,
"CHF": 0.88059,
"CLF": 0.035523,
"CLP": 980.2,
"CNH": 7.2038,
"CNY": 7.1949,
"COP": 3925.16035,
"CRC": 514.096076,
"BTC": 0.000014753422,
"BTN": 83.412383,
"BWP": 13.698365,
"BYN": 3.270274,
"BZD": 2.014276,
"CAD": 1.364236,
"CDF": 2795.476589,
"CHF": 0.902724,
"CLF": 0.033266,
"CLP": 917.92,
"CNH": 7.2598,
"CNY": 7.1059,
"COP": 3857.42575,
"CRC": 520.654,
"CUC": 1,
"CUP": 25.75,
"CVE": 101.753323,
"CZK": 23.4281,
"DJF": 177.917221,
"DKK": 6.88885,
"DOP": 58.708992,
"DZD": 134.498,
"EGP": 30.9,
"CVE": 101.556543,
"CZK": 22.754,
"DJF": 177.923131,
"DKK": 6.8745,
"DOP": 59.129634,
"DZD": 134.3668,
"EGP": 47.27,
"ERN": 15,
"ETB": 56.66553,
"EUR": 0.92315,
"FJD": 2.2352,
"FKP": 0.788706,
"GBP": 0.788706,
"GEL": 2.65,
"GGP": 0.788706,
"GHS": 12.539104,
"GIP": 0.788706,
"GMD": 67.275,
"GNF": 8595,
"GTQ": 7.807872,
"GYD": 209.034301,
"HKD": 7.8221,
"HNL": 24.669403,
"HRK": 6.96308,
"HTG": 132.721527,
"HUF": 359.514887,
"IDR": 15594.15,
"ILS": 3.63115,
"IMP": 0.788706,
"INR": 82.88195,
"IQD": 1308.817913,
"IRR": 42032.5,
"ISK": 137.8,
"JEP": 0.788706,
"JMD": 156.268155,
"JOD": 0.709,
"JPY": 150.48501336,
"KES": 143.376564,
"KGS": 89.43,
"KHR": 4080,
"KMF": 454.950092,
"ETB": 57.429333,
"EUR": 0.921107,
"FJD": 2.2605,
"FKP": 0.785114,
"GBP": 0.785114,
"GEL": 2.79,
"GGP": 0.785114,
"GHS": 14.73912,
"GIP": 0.785114,
"GMD": 67.775,
"GNF": 8595.915864,
"GTQ": 7.763297,
"GYD": 209.182545,
"HKD": 7.8194,
"HNL": 24.690766,
"HRK": 6.94517,
"HTG": 132.700916,
"HUF": 359.235427,
"IDR": 16255.1,
"ILS": 3.71944,
"IMP": 0.785114,
"INR": 83.460852,
"IQD": 1309.048153,
"IRR": 42225,
"ISK": 137.45,
"JEP": 0.785114,
"JMD": 155.514613,
"JOD": 0.7089,
"JPY": 157.25001195,
"KES": 130.5,
"KGS": 87.7,
"KHR": 4090.237951,
"KMF": 454.250319,
"KPW": 900,
"KRW": 1331,
"KWD": 0.307735,
"KYD": 0.832649,
"KZT": 450.61631,
"LAK": 20848.022178,
"LBP": 89399.224549,
"LKR": 310.644628,
"LRD": 190.650011,
"LSL": 19.023588,
"LYD": 4.826282,
"MAD": 10.030637,
"MDL": 17.88954,
"MGA": 4532.835312,
"MKD": 56.858767,
"MMK": 2098.190404,
"KRW": 1383.09,
"KWD": 0.306166,
"KYD": 0.832788,
"KZT": 446.714065,
"LAK": 21470.433423,
"LBP": 89485.773014,
"LKR": 300.649394,
"LRD": 193.899976,
"LSL": 18.731201,
"LYD": 4.848262,
"MAD": 9.928805,
"MDL": 17.608826,
"MGA": 4439.313241,
"MKD": 56.69353,
"MMK": 2098.457405,
"MNT": 3450,
"MOP": 8.051216,
"MRU": 39.915102,
"MUR": 45.735945,
"MVR": 15.4,
"MWK": 1681.909174,
"MXN": 17.1162,
"MYR": 4.7775,
"MZN": 63.850001,
"NAD": 19.023588,
"NGN": 1469.112057,
"NIO": 36.813954,
"NOK": 10.537366,
"NPR": 132.873147,
"NZD": 1.613164,
"OMR": 0.38496,
"MOP": 8.047893,
"MRU": 39.491596,
"MUR": 46.029291,
"MVR": 15.45,
"MWK": 1731.611843,
"MXN": 16.99024,
"MYR": 4.7075,
"MZN": 63.899991,
"NAD": 18.731201,
"NGN": 1487,
"NIO": 36.785631,
"NOK": 10.5091,
"NPR": 133.459805,
"NZD": 1.625752,
"OMR": 0.384904,
"PAB": 1,
"PEN": 3.786924,
"PGK": 3.811565,
"PHP": 55.935001,
"PKR": 279.130048,
"PLN": 3.979237,
"PYG": 7273.608817,
"QAR": 3.645458,
"RON": 4.5979,
"RSD": 108.338,
"RUB": 94.78673,
"RWF": 1274.303976,
"SAR": 3.750554,
"SBD": 8.500465,
"SCR": 13.493,
"PEN": 3.748377,
"PGK": 3.8945,
"PHP": 58.516495,
"PKR": 278.10123,
"PLN": 3.939029,
"PYG": 7533.099348,
"QAR": 3.646144,
"RON": 4.5904,
"RSD": 108.097,
"RUB": 90.415913,
"RWF": 1297.53527,
"SAR": 3.751069,
"SBD": 8.489576,
"SCR": 13.775731,
"SDG": 601,
"SEK": 10.3298,
"SGD": 1.343,
"SHP": 0.788706,
"SEK": 10.5301,
"SGD": 1.3534,
"SHP": 0.785114,
"SLL": 20969.5,
"SOS": 571.033242,
"SRD": 35.701,
"SOS": 571.125529,
"SRD": 32.1415,
"SSP": 130.26,
"STD": 22281.8,
"STN": 23.12,
"SVC": 8.742675,
"STN": 22.565047,
"SVC": 8.744186,
"SYP": 2512.53,
"SZL": 19.018416,
"THB": 35.86767,
"TJS": 10.940433,
"TMT": 3.51,
"TND": 3.1235,
"TOP": 2.360341,
"TRY": 30.818685,
"TTD": 6.790938,
"TWD": 31.617,
"TZS": 2550,
"UAH": 38.242329,
"UGX": 3903.120879,
"SZL": 18.741997,
"THB": 36.690767,
"TJS": 10.717385,
"TMT": 3.5,
"TND": 3.11625,
"TOP": 2.36145,
"TRY": 32.257201,
"TTD": 6.781487,
"TWD": 32.4795,
"TZS": 2603.181128,
"UAH": 40.526826,
"UGX": 3805.645029,
"USD": 1,
"UYU": 39.080883,
"UZS": 12479.072451,
"VES": 36.186223,
"VND": 24639.648555,
"UYU": 38.728685,
"UZS": 12610.529246,
"VES": 36.491554,
"VND": 25448.534056,
"VUV": 118.722,
"WST": 2.8,
"XAF": 605.546705,
"XAG": 0.04357204,
"XAU": 0.00049126,
"XAF": 604.206708,
"XAG": 0.03288554,
"XAU": 0.00042967,
"XCD": 2.70255,
"XDR": 0.75421,
"XOF": 605.546705,
"XPD": 0.00102701,
"XPF": 110.161098,
"XPT": 0.00111006,
"YER": 250.349961,
"ZAR": 19.29,
"ZMW": 22.954829,
"XDR": 0.755146,
"XOF": 604.206708,
"XPD": 0.00109906,
"XPF": 109.917326,
"XPT": 0.00096453,
"YER": 250.400036,
"ZAR": 18.79534,
"ZMW": 27.138531,
"ZWL": 322
}
}
}

View File

@ -142,6 +142,8 @@ export interface Image {
filesize?: number | null;
width?: number | null;
height?: number | null;
focalX?: number | null;
focalY?: number | null;
sizes?: {
thumb?: {
url?: string | null;
@ -620,6 +622,8 @@ export interface Scan {
filesize?: number | null;
width?: number | null;
height?: number | null;
focalX?: number | null;
focalY?: number | null;
sizes?: {
thumb?: {
url?: string | null;
@ -725,6 +729,8 @@ export interface Audio {
filesize?: number | null;
width?: number | null;
height?: number | null;
focalX?: number | null;
focalY?: number | null;
}
/**
* This interface was referenced by `Config`'s JSON-Schema
@ -740,6 +746,8 @@ export interface MediaThumbnail {
filesize?: number | null;
width?: number | null;
height?: number | null;
focalX?: number | null;
focalY?: number | null;
sizes?: {
thumb?: {
url?: string | null;
@ -865,6 +873,8 @@ export interface Video {
filesize?: number | null;
width?: number | null;
height?: number | null;
focalX?: number | null;
focalY?: number | null;
}
/**
* This interface was referenced by `Config`'s JSON-Schema
@ -878,6 +888,8 @@ export interface VideoSubtitle {
filesize?: number | null;
width?: number | null;
height?: number | null;
focalX?: number | null;
focalY?: number | null;
}
/**
* This interface was referenced by `Config`'s JSON-Schema

View File

@ -1,7 +1,6 @@
{
"extends": "astro/tsconfigs/strictest",
"compilerOptions": {
"types": ["bun-types"],
"baseUrl": ".",
"paths": {
"pages/*": ["src/pages/*"],