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

View File

@ -12,7 +12,7 @@
"script:download-currencies": "npm run scripts/download-currencies.ts", "script:download-currencies": "npm run scripts/download-currencies.ts",
"script:download-wording-keys": "npm run scripts/download-wording-keys.ts", "script:download-wording-keys": "npm run scripts/download-wording-keys.ts",
"prettier": "prettier --write --list-different --plugin=prettier-plugin-astro .", "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": { "engines": {
"npm": ">=10.0.0", "npm": ">=10.0.0",
@ -33,9 +33,8 @@
"@types/ua-parser-js": "^0.7.39", "@types/ua-parser-js": "^0.7.39",
"astro-meta-tags": "^0.3.0", "astro-meta-tags": "^0.3.0",
"autoprefixer": "^10.4.19", "autoprefixer": "^10.4.19",
"bun-types": "^1.1.10",
"postcss-preset-env": "^9.5.14", "postcss-preset-env": "^9.5.14",
"prettier": "^3.2.5", "prettier": "^3.3.0",
"prettier-plugin-astro": "^0.14.0", "prettier-plugin-astro": "^0.14.0",
"typescript": "^5.4.5" "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 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=${ const ratesUrl = `https://openexchangerates.org/api/latest.json?app_id=${
import.meta.env.OER_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); const rates = await fetch(ratesUrl);
if (rates.ok) { if (rates.ok) {
writeFileSync(`${OPEN_EXCHANGE_FOLDER}/rates.json`, await rates.text(), { writeFileSync(RATE_JSON_PATH, await rates.text(), {
encoding: "utf-8", encoding: "utf-8",
}); });
} else { } else {
@ -22,7 +37,7 @@ if (rates.ok) {
const currencies = await fetch(currenciesUrl); const currencies = await fetch(currenciesUrl);
if (currencies.ok) { if (currencies.ok) {
writeFileSync(`${OPEN_EXCHANGE_FOLDER}/currencies.json`, await currencies.text(), { writeFileSync(CURRENCIES_JSON_PATH, await currencies.text(), {
encoding: "utf-8", encoding: "utf-8",
}); });
} else { } else {

View File

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

View File

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

View File

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

View File

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