mirror of
https://github.com/blitzkit/blitzkit.git
synced 2026-10-21 18:57:03 +02:00
feat: some type prefixes
This commit is contained in:
1 parent
dc60cffdff
commit
0d8cb5c1ae
31 files changed
+225
-222
No files matched your search
@@ -1,8 +1,8 @@
|
||||
import { asset } from '@blitzkit/core';
|
||||
import ProgressBar from 'progress';
|
||||
import { compareUint8Arrays } from './compareUint8Arrays';
|
||||
import { GithubChangeBlob, createBlob } from './createBlob';
|
||||
import { octokit } from './octokit';
|
||||
import { asset } from "@blitzkit/core";
|
||||
import ProgressBar from "progress";
|
||||
import { compareUint8Arrays } from "./compareUint8Arrays";
|
||||
import { type GithubChangeBlob, createBlob } from "./createBlob";
|
||||
import { octokit } from "./octokit";
|
||||
|
||||
export interface FileChange {
|
||||
path: string;
|
||||
@@ -15,33 +15,33 @@ enum DiffStatus {
|
||||
Unchanged,
|
||||
}
|
||||
|
||||
const heuristicFormats = ['glb', 'webp', 'jpg', 'png'];
|
||||
const heuristicFormats = ["glb", "webp", "jpg", "png"];
|
||||
|
||||
export async function commitMultipleFiles(
|
||||
repoRaw: string,
|
||||
branch: string,
|
||||
message: string,
|
||||
changesRaw: FileChange[],
|
||||
changesRaw: FileChange[]
|
||||
) {
|
||||
const changes: FileChange[] = [];
|
||||
|
||||
await Promise.all(
|
||||
changesRaw.map(async (change) => {
|
||||
const response = await fetch(asset(change.path), {
|
||||
headers: { 'Accept-Encoding': 'identity' },
|
||||
headers: { "Accept-Encoding": "identity" },
|
||||
});
|
||||
let diff: { change: number; status: DiffStatus };
|
||||
|
||||
if (response.status === 404) {
|
||||
diff = { change: change.content.length, status: DiffStatus.New };
|
||||
} else if (
|
||||
response.headers.has('Content-Length') &&
|
||||
Number(response.headers.get('Content-Length')) !== change.content.length
|
||||
response.headers.has("Content-Length") &&
|
||||
Number(response.headers.get("Content-Length")) !== change.content.length
|
||||
) {
|
||||
diff = {
|
||||
change:
|
||||
change.content.length -
|
||||
Number(response.headers.get('Content-Length')),
|
||||
Number(response.headers.get("Content-Length")),
|
||||
status: DiffStatus.Changed,
|
||||
};
|
||||
} else if (response.status === 200) {
|
||||
@@ -68,7 +68,7 @@ export async function commitMultipleFiles(
|
||||
}
|
||||
} else {
|
||||
throw new Error(
|
||||
`Unexpected status code ${response.status} for ${change.path}`,
|
||||
`Unexpected status code ${response.status} for ${change.path}`
|
||||
);
|
||||
}
|
||||
|
||||
@@ -78,17 +78,17 @@ export async function commitMultipleFiles(
|
||||
} else {
|
||||
console.log(
|
||||
`${
|
||||
diff.status === DiffStatus.New ? '🟢' : '🟡'
|
||||
} (${diff.change > 0 ? '+' : ''}${diff.change.toLocaleString()}B) ${change.path}`,
|
||||
diff.status === DiffStatus.New ? "🟢" : "🟡"
|
||||
} (${diff.change > 0 ? "+" : ""}${diff.change.toLocaleString()}B) ${change.path}`
|
||||
);
|
||||
changes.push(change);
|
||||
}
|
||||
}),
|
||||
})
|
||||
);
|
||||
|
||||
if (changes.length === 0) return;
|
||||
|
||||
const [owner, repo] = repoRaw.split('/');
|
||||
const [owner, repo] = repoRaw.split("/");
|
||||
const latestCommitSha = (
|
||||
await octokit.git.getRef({
|
||||
owner,
|
||||
@@ -104,7 +104,7 @@ export async function commitMultipleFiles(
|
||||
})
|
||||
).data.tree.sha;
|
||||
const blobs: GithubChangeBlob[] = [];
|
||||
const bar = new ProgressBar('Blobs :bar', changes.length);
|
||||
const bar = new ProgressBar("Blobs :bar", changes.length);
|
||||
|
||||
for (const change of changes) {
|
||||
const createdBlob = await createBlob(owner, repo, change);
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
import { throttle } from 'lodash-es';
|
||||
import { FileChange } from './commitMultipleFiles';
|
||||
import { octokit } from './octokit';
|
||||
import { throttle } from "lodash-es";
|
||||
import type { FileChange } from "./commitMultipleFiles";
|
||||
import { octokit } from "./octokit";
|
||||
|
||||
export interface GithubChangeBlob {
|
||||
sha: string;
|
||||
path: string;
|
||||
mode: '100644';
|
||||
type: 'blob';
|
||||
mode: "100644";
|
||||
type: "blob";
|
||||
}
|
||||
|
||||
const TIME_PER_BLOB = 2 ** 4 * 1000;
|
||||
@@ -20,21 +20,21 @@ export const createBlob = throttle(
|
||||
await octokit.git.createBlob({
|
||||
owner,
|
||||
repo,
|
||||
content: Buffer.from(change.content).toString('base64'),
|
||||
encoding: 'base64',
|
||||
content: Buffer.from(change.content).toString("base64"),
|
||||
encoding: "base64",
|
||||
})
|
||||
).data;
|
||||
|
||||
return {
|
||||
sha,
|
||||
path: change.path,
|
||||
mode: '100644',
|
||||
type: 'blob',
|
||||
mode: "100644",
|
||||
type: "blob",
|
||||
} satisfies GithubChangeBlob;
|
||||
} catch (error) {
|
||||
console.warn(
|
||||
`Failed blob ${change.path}; retrying in ${TIME_PER_BLOB}ms...`,
|
||||
error,
|
||||
error
|
||||
);
|
||||
|
||||
await new Promise((resolve) => setTimeout(resolve, TIME_PER_BLOB));
|
||||
@@ -42,5 +42,5 @@ export const createBlob = throttle(
|
||||
}
|
||||
},
|
||||
(5000 / (60 * 60 * 1000)) * 0.9,
|
||||
{ trailing: true },
|
||||
{ trailing: true }
|
||||
);
|
||||
Reference in new issue
Block a user