mirror of
https://github.com/blitzkit/blitzkit.git
synced 2026-10-21 10:47:04 +02:00
feat: switched scripts to typescript
This commit is contained in:
1 parent
6d6a6bf738
commit
638402589f
5 files changed
+132
-23
No files matched your search
@@ -1,4 +1,4 @@
|
||||
import { build } from 'esbuild';
|
||||
import { BuildOptions, build } from 'esbuild';
|
||||
import { copyFile, mkdir, rm } from 'fs/promises';
|
||||
import { argv } from 'process';
|
||||
|
||||
@@ -7,6 +7,8 @@ const buildAll = argv.includes('--build=all');
|
||||
const buildBot = argv.includes('--build=bot') || buildAll;
|
||||
const buildServer = argv.includes('--build=server') || buildAll;
|
||||
|
||||
console.log(buildAll, buildBot, buildServer);
|
||||
|
||||
if (isProd) {
|
||||
// only remove in production to ensure no time is wasted in dev
|
||||
console.log('Removing dist...');
|
||||
@@ -23,7 +25,7 @@ if (isProd) {
|
||||
);
|
||||
}
|
||||
|
||||
const commonOptions = {
|
||||
const commonOptions: BuildOptions = {
|
||||
platform: 'node',
|
||||
loader: {
|
||||
'.node': 'copy',
|
||||
@@ -3,6 +3,19 @@ import { rm, writeFile } from 'fs/promises';
|
||||
import { argv, env } from 'process';
|
||||
import commitMultipleFiles from './commitMultipleFiles.js';
|
||||
|
||||
interface RatingsSeasonInfo {
|
||||
count: number;
|
||||
}
|
||||
|
||||
interface RatingsPlayer {
|
||||
number: number;
|
||||
spa_id: number;
|
||||
}
|
||||
|
||||
interface RatingsNeighbors {
|
||||
neighbors: RatingsPlayer[];
|
||||
}
|
||||
|
||||
/*
|
||||
* Central North American Time (UTC-5): use 0 5 * * *.
|
||||
* Central European Time (UTC+1): use 0 23 * * *.
|
||||
@@ -23,22 +36,22 @@ const NEIGHBORS = 1000;
|
||||
const PLAYERS = await fetch(
|
||||
`https://${server}.wotblitz.com/en/api/rating-leaderboards/season/`,
|
||||
)
|
||||
.then((response) => response.json())
|
||||
.then((response) => response.json() as Promise<RatingsSeasonInfo>)
|
||||
.then((data) => data.count);
|
||||
|
||||
const players = {};
|
||||
const leaderboard = [];
|
||||
const players: Record<number, RatingsPlayer> = {};
|
||||
const leaderboard: RatingsPlayer[] = [];
|
||||
let registered = 0;
|
||||
|
||||
async function branchFromPlayer(id) {
|
||||
async function branchFromPlayer(id: number) {
|
||||
const { neighbors } = await fetch(
|
||||
`https://${server}.wotblitz.com/en/api/rating-leaderboards/user/${id}/?neighbors=${NEIGHBORS}`,
|
||||
).then((response) => response.json());
|
||||
).then((response) => response.json() as Promise<RatingsNeighbors>);
|
||||
|
||||
const firstPlayer = neighbors[0];
|
||||
const lastPlayer = neighbors[neighbors.length - 1];
|
||||
|
||||
const branches = [];
|
||||
const branches: Promise<void>[] = [];
|
||||
if (!players[firstPlayer.number])
|
||||
branches.push(branchFromPlayer(firstPlayer.spa_id));
|
||||
if (!players[lastPlayer.number])
|
||||
@@ -61,7 +74,7 @@ async function branchFromPlayer(id) {
|
||||
await Promise.all(branches);
|
||||
}
|
||||
|
||||
async function branchFromLeague(id) {
|
||||
async function branchFromLeague(id: number) {
|
||||
const { result } = await fetch(
|
||||
`https://${server}.wotblitz.com/en/api/rating-leaderboards/league/${id}/top/`,
|
||||
).then((response) => response.json());
|
||||
@@ -75,7 +88,7 @@ async function branchFromLeague(id) {
|
||||
]);
|
||||
}
|
||||
|
||||
console.log('Branching form leagues...');
|
||||
console.log('Branching from leagues...');
|
||||
await Promise.all([
|
||||
branchFromLeague(0),
|
||||
branchFromLeague(1),
|
||||
@@ -1,10 +1,12 @@
|
||||
import { Octokit } from '@octokit/rest';
|
||||
|
||||
export default async function commitMultipleFiles(
|
||||
octokit,
|
||||
owner,
|
||||
repo,
|
||||
branch,
|
||||
message,
|
||||
changes,
|
||||
octokit: Octokit,
|
||||
owner: string,
|
||||
repo: string,
|
||||
branch: string,
|
||||
message: string,
|
||||
changes: { path: string; content: string }[],
|
||||
) {
|
||||
// Get the latest commit SHA on the specified branch
|
||||
const { data: refData } = await octokit.git.getRef({
|
||||
@@ -31,12 +33,13 @@ export default async function commitMultipleFiles(
|
||||
content: change.content,
|
||||
encoding: 'utf-8',
|
||||
});
|
||||
|
||||
return {
|
||||
sha: blobData.sha,
|
||||
path: change.path,
|
||||
mode: '100644',
|
||||
type: 'blob',
|
||||
};
|
||||
} as const;
|
||||
}),
|
||||
);
|
||||
|
||||
Reference in new issue
Block a user