Migrate Node -> Bun (#1827)

* Initial

* Faster user page

* Remove redundant function

* Favorite badge sorting

* Upgrade deps

* Simplify entry.server

* Bun tests initial

* Update package.json npm -> bun

* Update README

* Type safe translations again

* Don't load streams info for finalized tournaments

* Translations as an object

* More unit test work

* Convert match.server.test

* test

* test

* test

* test

* test

* test

* test

* test

* test

* test

* test

* test

* test

* test

* test

* test

* test

* Test & all done

* Working cf

* Bun GA try

* No cache

* spacing

* spacing 2

* Add SQL logging

* Remove NR

* Hmm

* Hmm 2

* Interesting

* SKALOP_SYSTEM_MESSAGE_URL

* .

* .

* ?

* .

* ?

* Server.ts adjust

* Downgrade Tldraw

* E2E test fix

* Fix lint
This commit is contained in:
Kalle
2024-08-11 16:09:41 +03:00
committed by GitHub
parent 440e9baab3
commit 700a309e7f
111 changed files with 5193 additions and 31742 deletions

View File

@@ -55,6 +55,9 @@ for (const file of fileNames) {
}
for (const lang of allOtherLanguages) {
// .DS_STORE
if (lang.startsWith(".")) continue;
try {
const otherRawContent = fs
.readFileSync(otherLanguageTranslationPath(lang, file), "utf8")

View File

@@ -0,0 +1,78 @@
import { Glob, pathToFileURL } from "bun";
import camelCase from "just-camel-case";
import { capitalize } from "~/utils/strings";
const glob = new Glob("locales/*/*.json");
const targetPath = pathToFileURL("./app/modules/i18n/resources.server.ts");
function main() {
const record: Record<string, string[]> = {};
const lines: string[] = [
"// This file is generated by scripts/generate-resources-file.ts",
"\n",
];
for (const file of glob.scanSync(".")) {
const [, lang, namespace] = file.replace(".json", "").split("/");
if (!record[lang]) {
record[lang] = [];
}
record[lang].push(namespace);
}
lines.push(...imports(record));
lines.push("\n");
lines.push("export const resources = {", ...resourcesObject(record), "};");
lines.push("\n");
lines.push("export type Namespace = keyof typeof resources.en;");
Bun.write(targetPath, lines.join("\n"));
}
function imports(record: Record<string, string[]>) {
const lines: string[] = [];
for (const lang in record) {
const namespaces = record[lang];
const imports = namespaces.map(
(namespace) =>
`import ${namespaceLangToLocalVar(lang, namespace)} from "../../../locales/${lang}/${namespace}.json";`,
);
lines.push(...imports);
}
return lines;
}
function namespaceLangToLocalVar(lang: string, namespace: string) {
const base = camelCase(namespace);
if (lang === "en") return base;
return `${base}${capitalize(camelCase(lang))}`;
}
function resourcesObject(record: Record<string, string[]>) {
const lines: string[] = [];
for (const lang in record) {
const namespaces = record[lang];
lines.push(
` "${lang}": {`,
...namespaces.map(
(namespace) =>
`${namespace.includes("-") ? `"${namespace}"` : namespace}: ${namespaceLangToLocalVar(lang, namespace)},`,
),
" },",
);
}
return lines;
}
main();

View File

@@ -98,7 +98,10 @@ const skillStm = sql.prepare(/* sql */ `
const midPoints = Object.entries(groupedSkills).reduce(
(acc, [tier, skills]) => {
const midPoint = skills[Math.floor(skills.length / 2)];
const midPointSkill = skillStm.get(midPoint) as Skill;
const midPointSkill = skillStm.get({
userId: midPoint.userId,
ordinal: midPoint.ordinal,
}) as Skill;
invariant(midPointSkill, "midPointSkill not found");
acc[tier as TierName] = midPointSkill;

4
scripts/test-preload.ts Normal file
View File

@@ -0,0 +1,4 @@
const testDb = Bun.file("db-test.sqlite3");
await Bun.write("db-test-active.sqlite3", testDb);
export type {};