From 26d518fb8e80259cead0a749af5732e79d0bb023 Mon Sep 17 00:00:00 2001 From: Nicolai Ort Date: Mon, 28 Apr 2025 20:24:22 +0200 Subject: [PATCH] feat: Added scripts to auto-update to latest version --- package.json | 2 ++ scripts/getliveopenapi.js | 27 +++++++++++++++++++++++++++ 2 files changed, 29 insertions(+) create mode 100644 scripts/getliveopenapi.js diff --git a/package.json b/package.json index f80e304..6456c22 100644 --- a/package.json +++ b/package.json @@ -26,6 +26,8 @@ "build:lib": "openapi --input ./openapi.json --output ./lib --client fetch", "build:compile": "tsc", "build:cleanup": "rimraf ./lib", + "update:openapi": "rimraf ./openapi.json && node ./scripts/getliveopenapi.js", + "update": "npm run update:openapi && npm run build && npm run release", "release": "release-it" }, "bugs": { diff --git a/scripts/getliveopenapi.js b/scripts/getliveopenapi.js new file mode 100644 index 0000000..2fd4a15 --- /dev/null +++ b/scripts/getliveopenapi.js @@ -0,0 +1,27 @@ +const https = require('https'); +const fs = require('fs'); + +const url = 'https://run.lauf-fuer-kaya.de/api/docs/openapi.json'; +const output = 'openapi.json'; + +https.get(url, (res) => { + if (res.statusCode !== 200) { + console.error(`Request Failed. Status Code: ${res.statusCode}`); + res.resume(); + return; + } + + let data = ''; + res.on('data', chunk => data += chunk); + res.on('end', () => { + fs.writeFile(output, data, (err) => { + if (err) { + console.error('Error writing file:', err); + } else { + console.log(`Saved latest OpenAPI JSON to ${output}`); + } + }); + }); +}).on('error', (e) => { + console.error(`Got error: ${e.message}`); +}); \ No newline at end of file