Various CI fixes, auto reload language configs

This commit is contained in:
Radon Rosborough 2020-12-26 20:26:03 -08:00
parent 0ecc49b613
commit 2c12fdd04a
5 changed files with 43 additions and 23 deletions

View File

@ -1,13 +1,20 @@
import { promises as fs } from "fs";
import fsOrig, { promises as fs } from "fs";
import path from "path";
import debounce from "debounce";
import { log } from "./util.js";
// Map from language IDs to language configuration objects. This is
// populated at runtime and updated asynchronously.
export let langs = {};
// Read languages from JSON files in /opt/riju/langs, and update the
// global langs variable in this module. Never throw an error. If
// there is a problem then just leave the languages as they previously
// were.
async function readLangsFromDisk() {
try {
const newLangs = {};
for (const filename of await fs.readdir("/opt/riju/langs")) {
if (path.parse(filename).ext !== ".json") {
@ -26,11 +33,15 @@ async function readLangsFromDisk() {
newLangs[id] = langConfig;
}
log.info(
`Loaded ${Object.keys(newLangs).length} language configuration(s) from disk`
`Loaded ${
Object.keys(newLangs).length
} language configuration(s) from disk`
);
langs = newLangs;
} catch (err) {
log.error("Failed to read languages from disk:", err);
}
}
readLangsFromDisk().catch((err) => {
log.error("Failed to read languages from disk:", err);
});
readLangsFromDisk();
fsOrig.watch("/opt/riju/langs", debounce(readLangsFromDisk, 200));

View File

@ -47,6 +47,9 @@ tee /etc/sudoers.d/90-riju >/dev/null <<"EOF"
%sudo ALL=(ALL:ALL) NOPASSWD: ALL
EOF
mkdir -p /opt/riju/langs
touch /opt/riju/langs/.keep
popd
rm "$0"

View File

@ -12,6 +12,7 @@
"buffer": "^6.0.3",
"commander": "^6.2.1",
"css-loader": "^5.0.1",
"debounce": "^1.2.0",
"ejs": "^3.1.5",
"express": "^4.17.1",
"express-ws": "^4.0.0",

View File

@ -2,6 +2,6 @@
set -euo pipefail
echo "${DOCKER_PASSWORD}" | docker login --username "${DOCKER_USERNAME}" --password-stdin
echo "${DOCKER_PASSWORD}" | sudo -E docker login --username "${DOCKER_USERNAME}" --password-stdin
make publish

View File

@ -1302,6 +1302,11 @@ cssesc@^3.0.0:
resolved "https://registry.yarnpkg.com/cssesc/-/cssesc-3.0.0.tgz#37741919903b868565e1c09ea747445cd18983ee"
integrity sha512-/Tb/JcjK111nNScGob5MNtsntNM1aCNUDipB/TkwZFhyDrrE47SOx/18wF2bbjgc3ZzCSKW1T5nt5EbFoAz/Vg==
debounce@^1.2.0:
version "1.2.0"
resolved "https://registry.yarnpkg.com/debounce/-/debounce-1.2.0.tgz#44a540abc0ea9943018dc0eaa95cce87f65cd131"
integrity sha512-mYtLl1xfZLi1m4RtQYlZgJUNQjl4ZxVnHzIR8nLLgi4q1YT8o/WM+MK/f8yfcc9s5Ir5zRaPZyZU6xs1Syoocg==
debug@2.6.9:
version "2.6.9"
resolved "https://registry.yarnpkg.com/debug/-/debug-2.6.9.tgz#5d128515df134ff327e90a4c93f4e077a536341f"