style: fmt scripts
parent
63635cda07
commit
772af8da0d
|
|
@ -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<string> = 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<string, string> = {};
|
||||
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<string,string> = await context.request.body({ type: 'json' }).value;
|
||||
const body: Record<string, string> = 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 });
|
||||
|
|
|
|||
|
|
@ -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<Platform, string> = {
|
||||
'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<Platform, File>
|
||||
}
|
||||
version: string;
|
||||
notes: string;
|
||||
pub_date: string;
|
||||
platforms: Record<Platform, File>;
|
||||
};
|
||||
|
||||
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<Platform, File>;
|
||||
|
||||
|
||||
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) {
|
||||
|
|
|
|||
|
|
@ -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"
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue