diff --git a/gui/scripts/i18n-backend.ts b/gui/scripts/i18n-backend.ts index c5c36b8..4471c51 100644 --- a/gui/scripts/i18n-backend.ts +++ b/gui/scripts/i18n-backend.ts @@ -1,4 +1,4 @@ -import { Application, Router } from 'https://deno.land/x/oak@v12.1.0/mod.ts'; +import { Application, Router } from "https://deno.land/x/oak@v12.1.0/mod.ts"; import * as path from "https://deno.land/std@0.178.0/path/mod.ts"; const PORT = 1421; @@ -10,23 +10,29 @@ const keys: Set = new Set(); async function updateFile() { delayId = null; - for (const lng of ['en', 'zh-CN']) { - const translationPath = path.join(__dirname, `../src/i18n/translation/${lng}.json`); + for (const lng of ["en", "zh-CN"]) { + const translationPath = path.join( + __dirname, + `../src/i18n/translation/${lng}.json`, + ); let translations: Record = {}; try { translations = JSON.parse(await Deno.readTextFile(translationPath)); } catch (error) {} - const toAdd = [...keys].filter(k => !Object.keys(translations).includes(k)); + const toAdd = [...keys].filter((k) => + !Object.keys(translations).includes(k) + ); translations = Object.fromEntries( [ ...Object.entries(translations), ...toAdd - .map(i => [i, i] as const)] - .sort(([a], [b]) => a.localeCompare(b)), + .map((i) => [i, i] as const), + ] + .sort(([a], [b]) => a.localeCompare(b)), ); - console.log('Add keys:', toAdd, 'for', lng); + console.log("Add keys:", toAdd, "for", lng); await Deno.writeTextFile( translationPath, @@ -35,12 +41,14 @@ async function updateFile() { } keys.clear(); } -let delayId: number|null = null; +let delayId: number | null = null; -router.post('/locales/add/:lng/:ns', async (context) => { +router.post("/locales/add/:lng/:ns", async (context) => { try { // ns, lng is ignored - const body: Record = await context.request.body({ type: 'json' }).value; + const body: Record = await context.request.body({ + type: "json", + }).value; for (const key of Object.keys(body)) { keys.add(key); } @@ -51,7 +59,7 @@ router.post('/locales/add/:lng/:ns', async (context) => { delayId = setTimeout(updateFile, 1000); context.response.status = 200; - context.response.body = { message: 'Translation added.' }; + context.response.body = { message: "Translation added." }; } catch (error) { context.response.status = 500; context.response.body = { message: error.message }; @@ -61,5 +69,5 @@ router.post('/locales/add/:lng/:ns', async (context) => { app.use(router.routes()); app.use(router.allowedMethods()); -console.log(`Listening on port ${PORT}...`) +console.log(`Listening on port ${PORT}...`); await app.listen({ port: PORT }); diff --git a/gui/scripts/make-update.ts b/gui/scripts/make-update.ts index 262f8b2..81d33fd 100644 --- a/gui/scripts/make-update.ts +++ b/gui/scripts/make-update.ts @@ -1,36 +1,45 @@ -import { Octokit } from 'npm:@octokit/rest@19.0.7'; +import { Octokit } from "npm:@octokit/rest@19.0.7"; -const TAG_PREFIX = 'gui-' +const TAG_PREFIX = "gui-"; -type Platform = 'darwin-x86_64' | 'darwin-aarch64' | 'linux-x86_64' | 'windows-x86_64' -const PLATFORMS: Platform[] = ['darwin-x86_64', 'darwin-aarch64', 'linux-x86_64', 'windows-x86_64'] +type Platform = + | "darwin-x86_64" + | "darwin-aarch64" + | "linux-x86_64" + | "windows-x86_64"; +const PLATFORMS: Platform[] = [ + "darwin-x86_64", + "darwin-aarch64", + "linux-x86_64", + "windows-x86_64", +]; const PlatformSuffix: Record = { - 'darwin-x86_64': '.app.tar.gz', - 'darwin-aarch64': '.app.tar.gz', - 'linux-x86_64': '.AppImage.tar.gz', - 'windows-x86_64': '.msi.zip', -} + "darwin-x86_64": ".app.tar.gz", + "darwin-aarch64": ".app.tar.gz", + "linux-x86_64": ".AppImage.tar.gz", + "windows-x86_64": ".msi.zip", +}; type File = { - signature: string - url: string -} + signature: string; + url: string; +}; type UpdateJson = { - version: string - notes: string - pub_date: string - platforms: Record -} + version: string; + notes: string; + pub_date: string; + platforms: Record; +}; const REPO = { - owner: 'spacemeowx2', - repo: 's3si.ts', -} + owner: "spacemeowx2", + repo: "s3si.ts", +}; const octokit = new Octokit({ - auth: Deno.env.get('GITHUB_TOKEN'), + auth: Deno.env.get("GITHUB_TOKEN"), }); async function findFirstGuiRelease() { @@ -39,15 +48,15 @@ async function findFirstGuiRelease() { const { data: list } = await octokit.repos.listReleases({ ...REPO, page, - }) + }); if (list.length === 0) { - return undefined + return undefined; } for (const release of list) { if (release.tag_name.startsWith(TAG_PREFIX)) { - return release + return release; } } @@ -57,27 +66,26 @@ async function findFirstGuiRelease() { const release = await findFirstGuiRelease(); -const version = release?.tag_name.slice(TAG_PREFIX.length) ?? 'unknown'; -const notes = release?.body ?? 'unknown'; -const pub_date = release?.published_at ?? 'unknown'; +const version = release?.tag_name.slice(TAG_PREFIX.length) ?? "unknown"; +const notes = release?.body ?? "unknown"; +const pub_date = release?.published_at ?? "unknown"; async function makePlatforms(r: typeof release) { const assets = r?.assets ?? []; - const platforms = Object.fromEntries(PLATFORMS.map(p => { - const asset = assets.find(i => i.name.endsWith(PlatformSuffix[p])); + const platforms = Object.fromEntries(PLATFORMS.map((p) => { + const asset = assets.find((i) => i.name.endsWith(PlatformSuffix[p])); if (!asset) { - throw new Error(`Asset not found for ${p}`) + throw new Error(`Asset not found for ${p}`); } return [p, { - signature: asset.browser_download_url + '.sig', + signature: asset.browser_download_url + ".sig", url: asset.browser_download_url, - }] + }]; })) as Record; - - return platforms + return platforms; } const updateJson: UpdateJson = { @@ -85,7 +93,7 @@ const updateJson: UpdateJson = { notes, pub_date, platforms: await makePlatforms(release), -} +}; // fetch signatures for (const platform of PLATFORMS) { diff --git a/scripts/deno.lock b/scripts/deno.lock index 42a5e38..df6de4a 100644 --- a/scripts/deno.lock +++ b/scripts/deno.lock @@ -85,4 +85,4 @@ "https://deno.land/x/ts_essentials@v9.1.2/lib/types.ts": "7ee99797a880948c07020e90d569ca3c5d465c378949262110283aa7856f5603", "https://deno.land/x/ts_essentials@v9.1.2/mod.ts": "ffae461c16d4a1bf24c2179582ab8d5c81ad0df61e4ae2fba51ef5e5bdf90345" } -} +} \ No newline at end of file