mirror of
https://seed.radicle.dev/rad:z4V1sjrXqjvFdnCUbxPFqd5p4DtH5.git
synced 2026-11-29 10:10:30 +08:00
Refactor config json into a virtual module
This commit is contained in:
+1
-1
@@ -31,7 +31,7 @@
|
||||
|
||||
void httpd.initialize().finally(() => void router.loadFromLocation());
|
||||
|
||||
if (!window.VITEST && !window.PLAYWRIGHT && import.meta.env.PROD) {
|
||||
if (import.meta.env.PROD) {
|
||||
const plausible = Plausible({ domain: "app.radicle.xyz" });
|
||||
|
||||
plausible.enableAutoPageviews();
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
<script lang="ts">
|
||||
import { api, changeHttpdPort } from "@app/lib/httpd";
|
||||
import { config } from "@app/lib/config";
|
||||
import config from "virtual:config";
|
||||
import {
|
||||
codeFont,
|
||||
codeFonts,
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
import type { ComponentProps } from "svelte";
|
||||
import type { ErrorParam } from "@app/lib/router/definitions";
|
||||
|
||||
import { config } from "@app/lib/config";
|
||||
import config from "virtual:config";
|
||||
import Command from "./Command.svelte";
|
||||
import ExternalLink from "./ExternalLink.svelte";
|
||||
import Icon from "./Icon.svelte";
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
|
||||
import { createEventDispatcher } from "svelte";
|
||||
|
||||
import config from "@app/config.json";
|
||||
import config from "virtual:config";
|
||||
|
||||
import IconButton from "./IconButton.svelte";
|
||||
import IconSmall from "./IconSmall.svelte";
|
||||
|
||||
@@ -1,27 +0,0 @@
|
||||
{
|
||||
"nodes": {
|
||||
"fallbackPublicExplorer": "https://app.radicle.xyz/nodes/$host/$rid$path",
|
||||
"apiVersion": "0.1.0",
|
||||
"defaultHttpdPort": 443,
|
||||
"defaultLocalHttpdPort": 8080,
|
||||
"defaultHttpdHostname": "seed.radicle.garden",
|
||||
"defaultHttpdScheme": "https",
|
||||
"defaultNodePort": 8776,
|
||||
"pinned": [
|
||||
{
|
||||
"baseUrl": {
|
||||
"hostname": "seed.radicle.xyz",
|
||||
"port": 443,
|
||||
"scheme": "https"
|
||||
}
|
||||
}
|
||||
]
|
||||
},
|
||||
"supportWebsite": "https://radicle.zulipchat.com",
|
||||
"reactions": ["👍", "👎", "😄", "🎉", "🙁", "🚀", "👀"],
|
||||
"fallbackPreferredSeed": {
|
||||
"hostname": "seed.radicle.garden",
|
||||
"port": 443,
|
||||
"scheme": "https"
|
||||
}
|
||||
}
|
||||
Vendored
-25
@@ -1,25 +0,0 @@
|
||||
/* eslint-disable @typescript-eslint/naming-convention */
|
||||
import type { Config } from "@app/lib/config";
|
||||
import type { FakeTimers } from "@sinonjs/fake-timers";
|
||||
|
||||
declare global {
|
||||
interface Window {
|
||||
// Defined in vite.config.ts and are available in all environments except
|
||||
// production.
|
||||
VITEST: boolean;
|
||||
PLAYWRIGHT: boolean;
|
||||
|
||||
// APP_CONFIG is set from within Playwright tests at runtime.
|
||||
// To better understand how it works together, have a look at:
|
||||
// tests/support/fixtures.ts
|
||||
// src/config.ts
|
||||
APP_CONFIG: Config;
|
||||
// eslint-disable-next-line @typescript-eslint/ban-types
|
||||
initializeTestStubs?: Function;
|
||||
e2eTestStubs: {
|
||||
FakeTimers: FakeTimers;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
export {};
|
||||
@@ -1,48 +0,0 @@
|
||||
import type { BaseUrl } from "@httpd-client";
|
||||
|
||||
import configJson from "@app/config.json";
|
||||
|
||||
export interface Config {
|
||||
nodes: {
|
||||
apiVersion: string;
|
||||
fallbackPublicExplorer: string;
|
||||
defaultHttpdPort: number;
|
||||
defaultHttpdHostname: string;
|
||||
defaultLocalHttpdPort: number;
|
||||
defaultNodePort: number;
|
||||
defaultHttpdScheme: string;
|
||||
pinned: { baseUrl: BaseUrl }[];
|
||||
};
|
||||
supportWebsite: string;
|
||||
fallbackPreferredSeed: BaseUrl;
|
||||
}
|
||||
|
||||
function getConfig(): Config {
|
||||
if (window.VITEST) {
|
||||
return {
|
||||
nodes: {
|
||||
fallbackPublicExplorer: "https://app.radicle.xyz/nodes/$host/$rid$path",
|
||||
apiVersion: "0.1.0",
|
||||
defaultHttpdHostname: "127.0.0.1",
|
||||
defaultHttpdPort: 8081,
|
||||
defaultLocalHttpdPort: 8081,
|
||||
defaultHttpdScheme: "http",
|
||||
defaultNodePort: 8776,
|
||||
pinned: [],
|
||||
},
|
||||
supportWebsite: "https://radicle.zulipchat.com",
|
||||
fallbackPreferredSeed: {
|
||||
hostname: "seed.radicle.garden",
|
||||
port: 443,
|
||||
scheme: "https",
|
||||
},
|
||||
};
|
||||
} else if (window.PLAYWRIGHT) {
|
||||
return window.APP_CONFIG;
|
||||
} else {
|
||||
// In dev and production environments we use data from config.json.
|
||||
return configJson;
|
||||
}
|
||||
}
|
||||
|
||||
export const config = getConfig();
|
||||
+1
-1
@@ -4,7 +4,7 @@ import { get, writable } from "svelte/store";
|
||||
import { withTimeout, Mutex, E_CANCELED, E_TIMEOUT } from "async-mutex";
|
||||
|
||||
import { HttpdClient } from "@httpd-client";
|
||||
import { config } from "@app/lib/config";
|
||||
import config from "virtual:config";
|
||||
import { deduplicateStore } from "@app/lib/deduplicateStore";
|
||||
import { experimental } from "./appearance";
|
||||
|
||||
|
||||
+1
-1
@@ -5,7 +5,7 @@ import { get, writable } from "svelte/store";
|
||||
|
||||
import * as mutexExecutor from "@app/lib/mutexExecutor";
|
||||
import * as utils from "@app/lib/utils";
|
||||
import { config } from "@app/lib/config";
|
||||
import config from "virtual:config";
|
||||
import {
|
||||
projectRouteToPath,
|
||||
projectTitle,
|
||||
|
||||
+1
-1
@@ -5,7 +5,7 @@ import { writable, derived, get } from "svelte/store";
|
||||
import { number, string, object } from "zod";
|
||||
|
||||
import { api, httpdStore, type HttpdState } from "./httpd";
|
||||
import { config } from "./config";
|
||||
import config from "virtual:config";
|
||||
|
||||
const preferredSeedSchema = object({
|
||||
hostname: string(),
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
<script lang="ts">
|
||||
import { config } from "@app/lib/config";
|
||||
import config from "virtual:config";
|
||||
|
||||
import Command from "@app/components/Command.svelte";
|
||||
import ExternalLink from "@app/components/ExternalLink.svelte";
|
||||
|
||||
@@ -2,7 +2,7 @@ import type { BaseUrl, NodeStats, Policy, Scope } from "@httpd-client";
|
||||
import type { ErrorRoute, NotFoundRoute } from "@app/lib/router/definitions";
|
||||
|
||||
import { HttpdClient } from "@httpd-client";
|
||||
import { config } from "@app/lib/config";
|
||||
import config from "virtual:config";
|
||||
import { baseUrlToString } from "@app/lib/utils";
|
||||
import { handleError } from "@app/views/nodes/error";
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
<script lang="ts">
|
||||
import type { BaseUrl } from "@httpd-client";
|
||||
|
||||
import { config } from "@app/lib/config";
|
||||
import config from "virtual:config";
|
||||
import { parseRepositoryId } from "@app/lib/utils";
|
||||
|
||||
import Button from "@app/components/Button.svelte";
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
|
||||
import { activeUnloadedRouteStore, routeToPath } from "@app/lib/router";
|
||||
import { api } from "@app/lib/httpd";
|
||||
import { config } from "@app/lib/config";
|
||||
import config from "virtual:config";
|
||||
import { formatPublicExplorer } from "@app/lib/utils";
|
||||
import { queryProject } from "@app/lib/projects";
|
||||
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
import debounce from "lodash/debounce";
|
||||
import { api, httpdStore } from "@app/lib/httpd";
|
||||
import { isLocal, toClipboard } from "@app/lib/utils";
|
||||
import { config } from "@app/lib/config";
|
||||
import config from "virtual:config";
|
||||
|
||||
import Button from "@app/components/Button.svelte";
|
||||
import IconSmall from "@app/components/IconSmall.svelte";
|
||||
|
||||
Reference in New Issue
Block a user