feat(build): handle offline

This commit is contained in:
Pihkaal
2024-07-31 15:12:43 +02:00
parent 946ef0311b
commit 1dcae0c20a

View File

@@ -1,8 +1,9 @@
import { Plugin } from "vite"; import { Plugin } from "vite";
import { readFile, writeFile } from "fs/promises"; import { readFile, writeFile } from "fs/promises";
import { spawnSync } from "child_process"; import { spawnSync } from "child_process";
import { Octokit } from "@octokit/rest"; import { Octokit, RestEndpointMethodTypes } from "@octokit/rest";
import { env } from "./env"; import { env } from "./env";
import { existsSync } from "fs";
type Manifest = { type Manifest = {
files: string[]; files: string[];
@@ -26,11 +27,23 @@ export const manifest = (): Plugin => ({
name: "generate-pages-plugin", name: "generate-pages-plugin",
buildStart: async () => { buildStart: async () => {
const octokit = new Octokit({ auth: env.GITHUB_PAT }); const octokit = new Octokit({ auth: env.GITHUB_PAT });
let manifestRepo: RestEndpointMethodTypes["repos"]["get"]["response"]["data"];
const { data: manifestRepo } = await octokit.repos.get({ try {
const { data } = await octokit.repos.get({
owner: env.GITHUB_USERNAME, owner: env.GITHUB_USERNAME,
repo: env.GITHUB_USERNAME, repo: env.GITHUB_USERNAME,
}); });
manifestRepo = data;
} catch {
if (existsSync("./node_modules/.cache/assets")) {
console.warn("WARNING: Can't update assets, using cached ones");
return;
} else {
throw new Error("Can't update assets, nothing cached");
}
}
try { try {
const storedUpdatedAt = ( const storedUpdatedAt = (
await readFile("./node_modules/.cache/assets") await readFile("./node_modules/.cache/assets")