mirror of
https://github.com/gradio-app/gradio.git
synced 2025-04-06 12:30:29 +08:00
Add error handling for missing js/_website/version.json
(#7451)
* add error handling for version.json * tweak error * add changeset * formatting * tweak logic * fix build * tweak * fix ENOENT error during build * revert removal of 3.50.2 routes Co-authored-by: Ali Abdalla <ali.si3luwa@gmail.com> --------- Co-authored-by: gradio-pr-bot <gradio-pr-bot@users.noreply.github.com> Co-authored-by: Ali Abdalla <ali.si3luwa@gmail.com>
This commit is contained in:
parent
1fa2e914ca
commit
65f114a117
5
.changeset/ripe-mirrors-count.md
Normal file
5
.changeset/ripe-mirrors-count.md
Normal file
@ -0,0 +1,5 @@
|
||||
---
|
||||
"website": minor
|
||||
---
|
||||
|
||||
feat:Add error handling for missing `js/_website/version.json`
|
@ -1,16 +1,45 @@
|
||||
import adapter from "@sveltejs/adapter-static";
|
||||
import { vitePreprocess } from "@sveltejs/kit/vite";
|
||||
import _version from "./src/lib/json/version.json" assert { type: "json" };
|
||||
import { redirects } from "./src/routes/redirects.js";
|
||||
import fs from "fs";
|
||||
import path from "path";
|
||||
import { fileURLToPath } from "url";
|
||||
|
||||
const version = _version.version;
|
||||
const currentDir = path.dirname(fileURLToPath(import.meta.url));
|
||||
let version = "4.0.0";
|
||||
|
||||
const get_version = async () => {
|
||||
try {
|
||||
const versionPath = path.join(
|
||||
currentDir,
|
||||
"src",
|
||||
"lib",
|
||||
"json",
|
||||
"version.json"
|
||||
);
|
||||
if (!fs.existsSync(versionPath)) {
|
||||
console.error(
|
||||
"Using fallback version 4.0.0 as version.json was not found. Run `generate_jsons/generate.py` to get the latest version."
|
||||
);
|
||||
return version;
|
||||
} else {
|
||||
const versionData = fs.readFileSync(versionPath, "utf8");
|
||||
const versionJson = JSON.parse(versionData);
|
||||
version = versionJson.version;
|
||||
}
|
||||
} catch (error) {
|
||||
console.error(
|
||||
"Using fallback version 4.0.0 as version.json was not found. Run `generate_jsons/generate.py` to get the latest version."
|
||||
);
|
||||
}
|
||||
return version;
|
||||
};
|
||||
|
||||
get_version();
|
||||
|
||||
/** @type {import('@sveltejs/kit').Config} */
|
||||
const config = {
|
||||
// Consult https://kit.svelte.dev/docs/integrations#preprocessors
|
||||
// for more information about preprocessors
|
||||
preprocess: vitePreprocess(),
|
||||
|
||||
kit: {
|
||||
prerender: {
|
||||
crawl: true,
|
||||
|
Loading…
x
Reference in New Issue
Block a user