mirror of
https://gitlab.com/soapbox-pub/shakespeare.git
synced 2026-12-03 07:57:22 +00:00
init
This commit is contained in:
1 parent
766c51ecde
commit
aa82aaf02c
15 files changed
+171
-25
No files matched your search
@@ -43,6 +43,7 @@ const defaultConfig: AppConfig = {
|
||||
theme: "system",
|
||||
relayUrl: "wss://relay.primal.net",
|
||||
deployServer: "shakespeare.wtf",
|
||||
esmUrl: "https://esm.shakespeare.diy",
|
||||
};
|
||||
|
||||
const presetRelays = [
|
||||
|
||||
@@ -9,6 +9,7 @@ import Preferences from "./pages/Preferences";
|
||||
import NostrSettings from "./pages/NostrSettings";
|
||||
import AISettings from "./pages/AISettings";
|
||||
import GitSettings from "./pages/GitSettings";
|
||||
import SystemSettings from "./pages/SystemSettings";
|
||||
import DataSettings from "./pages/DataSettings";
|
||||
import AboutSettings from "./pages/AboutSettings";
|
||||
|
||||
@@ -33,6 +34,7 @@ export function AppRouter() {
|
||||
<Route path="nostr" element={<NostrSettings />} />
|
||||
<Route path="ai" element={<AISettings />} />
|
||||
<Route path="git" element={<GitSettings />} />
|
||||
<Route path="system" element={<SystemSettings />} />
|
||||
<Route path="data" element={<DataSettings />} />
|
||||
<Route path="about" element={<AboutSettings />} />
|
||||
</Route>
|
||||
|
||||
@@ -19,6 +19,7 @@ const AppConfigSchema: z.ZodType<AppConfig, z.ZodTypeDef, unknown> = z.object({
|
||||
theme: z.enum(['dark', 'light', 'system']),
|
||||
relayUrl: z.string().url(),
|
||||
deployServer: z.string().min(1),
|
||||
esmUrl: z.string().url(),
|
||||
language: z.string().optional(),
|
||||
});
|
||||
|
||||
|
||||
@@ -9,6 +9,8 @@ export interface AppConfig {
|
||||
relayUrl: string;
|
||||
/** Deploy server domain (e.g., "shakespeare.wtf") */
|
||||
deployServer: string;
|
||||
/** ESM CDN URL for package imports */
|
||||
esmUrl: string;
|
||||
/** Selected language */
|
||||
language?: string;
|
||||
}
|
||||
|
||||
@@ -1,9 +1,11 @@
|
||||
import { useMutation } from "@tanstack/react-query";
|
||||
import { buildProject } from "@/lib/build";
|
||||
import { useFS } from "./useFS";
|
||||
import { useAppContext } from "./useAppContext";
|
||||
|
||||
export function useBuildProject(projectId: string) {
|
||||
const { fs } = useFS();
|
||||
const { config } = useAppContext();
|
||||
|
||||
return useMutation({
|
||||
mutationFn: async () => {
|
||||
@@ -11,6 +13,7 @@ export function useBuildProject(projectId: string) {
|
||||
fs,
|
||||
projectPath: `/projects/${projectId}`,
|
||||
domParser: new DOMParser(),
|
||||
esmUrl: config.esmUrl,
|
||||
});
|
||||
},
|
||||
});
|
||||
|
||||
@@ -23,10 +23,11 @@ interface EsmPluginOptions {
|
||||
packageJson: PackageJson;
|
||||
packageLock?: PackageLock;
|
||||
target?: string;
|
||||
esmUrl: string;
|
||||
}
|
||||
|
||||
export function esmPlugin(options: EsmPluginOptions): Plugin {
|
||||
const { packageJson, packageLock, target } = options;
|
||||
const { packageJson, packageLock, target, esmUrl } = options;
|
||||
/** Cache of URL redirects */
|
||||
const redirectedURLs = new Map<string, string>();
|
||||
|
||||
@@ -222,7 +223,7 @@ export function esmPlugin(options: EsmPluginOptions): Plugin {
|
||||
switch (moduleName) {
|
||||
case "buffer":
|
||||
return {
|
||||
path: `https://esm.sh/${moduleName}?target=${target ?? "esnext"}`,
|
||||
path: `${esmUrl}/${moduleName}?target=${target ?? "esnext"}`,
|
||||
namespace: "esm",
|
||||
};
|
||||
default:
|
||||
@@ -323,7 +324,7 @@ export function esmPlugin(options: EsmPluginOptions): Plugin {
|
||||
? `${cdnName}@${version}${packagePath}`
|
||||
: `${cdnName}${packagePath}`;
|
||||
|
||||
const url = new URL(`https://esm.sh/*${specifier}`);
|
||||
const url = new URL(`${esmUrl}/*${specifier}`);
|
||||
if (target) url.searchParams.set("target", target);
|
||||
if (childLockPath) url.searchParams.set("lp", encodeURIComponent(childLockPath));
|
||||
|
||||
@@ -441,9 +442,9 @@ export function esmPlugin(options: EsmPluginOptions): Plugin {
|
||||
};
|
||||
}
|
||||
|
||||
/** Extract package name from esm.sh-style URL */
|
||||
function extractPackageName(esmShURL: string): { pkg?: string; version?: string } {
|
||||
const full = new URL(esmShURL)
|
||||
/** Extract package name from ESM CDN-style URL */
|
||||
function extractPackageName(esmURL: string): { pkg?: string; version?: string } {
|
||||
const full = new URL(esmURL)
|
||||
.pathname
|
||||
.slice(1)
|
||||
.replace(/^\*/, "");
|
||||
|
||||
@@ -161,6 +161,7 @@ describe('buildProject', () => {
|
||||
fs: mockFS,
|
||||
projectPath: '/test/project',
|
||||
domParser: mockDOMParser,
|
||||
esmUrl: 'https://esm.shakespeare.diy',
|
||||
});
|
||||
|
||||
// Should include built files with hashed names
|
||||
@@ -220,6 +221,7 @@ describe('buildProject', () => {
|
||||
fs: mockFS,
|
||||
projectPath: '/test/project',
|
||||
domParser: mockDOMParser,
|
||||
esmUrl: 'https://esm.shakespeare.diy',
|
||||
});
|
||||
|
||||
// Should still include built files with hashed names
|
||||
@@ -278,6 +280,7 @@ describe('buildProject', () => {
|
||||
fs: mockFS,
|
||||
projectPath: '/test/project',
|
||||
domParser: mockDOMParser,
|
||||
esmUrl: 'https://esm.shakespeare.diy',
|
||||
});
|
||||
|
||||
// Should include built files with hashed names
|
||||
@@ -348,6 +351,7 @@ react@^18.0.0:
|
||||
fs: mockFS,
|
||||
projectPath: '/test/project',
|
||||
domParser: mockDOMParser,
|
||||
esmUrl: 'https://esm.shakespeare.diy',
|
||||
});
|
||||
|
||||
// Should successfully build with yarn.lock
|
||||
@@ -398,6 +402,7 @@ react@^18.0.0:
|
||||
fs: mockFS,
|
||||
projectPath: '/test/project',
|
||||
domParser: mockDOMParser,
|
||||
esmUrl: 'https://esm.shakespeare.diy',
|
||||
});
|
||||
|
||||
// Should successfully build with empty packages object
|
||||
@@ -457,6 +462,7 @@ react@^18.0.0:
|
||||
fs: mockFS,
|
||||
projectPath: '/test/project',
|
||||
domParser: mockDOMParser,
|
||||
esmUrl: 'https://esm.shakespeare.diy',
|
||||
});
|
||||
|
||||
// Should successfully build using package.json dependencies
|
||||
@@ -519,6 +525,7 @@ react@^18.0.0:
|
||||
fs: mockFS,
|
||||
projectPath: '/test/project',
|
||||
domParser: mockDOMParser,
|
||||
esmUrl: 'https://esm.shakespeare.diy',
|
||||
});
|
||||
|
||||
// Should successfully build with tsconfig.json
|
||||
|
||||
+12
-12
@@ -17,14 +17,14 @@ export interface BuildProjectOptions {
|
||||
domParser: DOMParser;
|
||||
target?: string;
|
||||
outputPath?: string;
|
||||
esmUrl: string;
|
||||
}
|
||||
|
||||
async function bundle(
|
||||
options: BuildProjectOptions,
|
||||
): Promise<Record<string, Uint8Array>> {
|
||||
const esbuild = await getEsbuild();
|
||||
|
||||
const { fs, projectPath, domParser, target = "esnext" } = options;
|
||||
const { fs, projectPath, domParser, target = "esnext", esmUrl } = options;
|
||||
const esbuild = await getEsbuild(esmUrl);
|
||||
|
||||
const indexHtmlText = await fs.readFile(
|
||||
`${projectPath}/index.html`,
|
||||
@@ -124,9 +124,9 @@ async function bundle(
|
||||
chunkNames: "[name]-[hash]",
|
||||
assetNames: "[name]-[hash]",
|
||||
plugins: [
|
||||
shakespearePlugin(),
|
||||
shakespearePlugin({ esmUrl }),
|
||||
fsPlugin({ fs, cwd: projectPath, tsconfig }),
|
||||
esmPlugin({ packageJson, packageLock, target }),
|
||||
esmPlugin({ packageJson, packageLock, target, esmUrl }),
|
||||
],
|
||||
define: {
|
||||
"import.meta.env": JSON.stringify({}),
|
||||
@@ -161,12 +161,12 @@ async function bundle(
|
||||
}
|
||||
}
|
||||
|
||||
// Parse CSP and ensure esm.sh is allowed for necessary directives
|
||||
// Parse CSP and ensure ESM CDN is allowed for necessary directives
|
||||
const cspMeta = doc.querySelector("meta[http-equiv=\"content-security-policy\"]");
|
||||
if (cspMeta) {
|
||||
const cspContent = cspMeta.getAttribute("content");
|
||||
if (cspContent) {
|
||||
const updatedCSP = updateCSPForEsmSh(cspContent);
|
||||
const updatedCSP = updateCSPForEsmSh(cspContent, esmUrl);
|
||||
cspMeta.setAttribute("content", updatedCSP);
|
||||
}
|
||||
}
|
||||
@@ -261,16 +261,16 @@ async function fileExists(fs: JSRuntimeFS, path: string): Promise<boolean> {
|
||||
}
|
||||
}
|
||||
|
||||
/** Updates CSP to allow esm.sh for scripts, assets, fonts, and CSS */
|
||||
export function updateCSPForEsmSh(csp: string): string {
|
||||
const esmShDirectives = [
|
||||
/** Updates CSP to allow ESM CDN for scripts, assets, fonts, and CSS */
|
||||
export function updateCSPForEsmSh(csp: string, esmUrl: string): string {
|
||||
const esmDirectives = [
|
||||
'script-src', // For JavaScript modules
|
||||
'img-src', // For images
|
||||
'media-src', // For video/audio
|
||||
'font-src', // For fonts
|
||||
'style-src', // For CSS
|
||||
'connect-src' // For fetch/XHR requests to esm.sh
|
||||
'connect-src' // For fetch/XHR requests to ESM CDN
|
||||
];
|
||||
|
||||
return addDomainToCSP(csp, 'https://esm.sh', esmShDirectives);
|
||||
return addDomainToCSP(csp, esmUrl, esmDirectives);
|
||||
}
|
||||
@@ -1,11 +1,15 @@
|
||||
import type { Plugin } from "esbuild-wasm";
|
||||
|
||||
interface ShakespearePluginOptions {
|
||||
esmUrl: string;
|
||||
}
|
||||
|
||||
/**
|
||||
* Shakespeare plugin for dependency polyfills and workarounds.
|
||||
* This plugin handles specific dependencies that need custom implementations
|
||||
* or dummy APIs to work correctly in the browser environment.
|
||||
*/
|
||||
export function shakespearePlugin(): Plugin {
|
||||
export function shakespearePlugin(options?: ShakespearePluginOptions): Plugin {
|
||||
return {
|
||||
name: "shakespeare",
|
||||
|
||||
@@ -23,7 +27,7 @@ export function shakespearePlugin(): Plugin {
|
||||
return {
|
||||
contents: `
|
||||
import tailwindConfig from "@/../${pathname}";
|
||||
import "https://esm.sh/tailwindcss-cdn@3";
|
||||
import "${options?.esmUrl}/tailwindcss-cdn@3";
|
||||
tailwind.config = tailwindConfig;
|
||||
`,
|
||||
loader: "js",
|
||||
|
||||
+4
-4
@@ -4,19 +4,19 @@ type ESBuild = typeof _ESBuild;
|
||||
|
||||
let promise: Promise<ESBuild> | undefined;
|
||||
|
||||
export function getEsbuild(): Promise<ESBuild> {
|
||||
export function getEsbuild(esmUrl: string): Promise<ESBuild> {
|
||||
if (!promise) {
|
||||
promise = loadEsbuild();
|
||||
promise = loadEsbuild(esmUrl);
|
||||
}
|
||||
return promise;
|
||||
}
|
||||
|
||||
async function loadEsbuild(): Promise<ESBuild> {
|
||||
async function loadEsbuild(esmUrl: string): Promise<ESBuild> {
|
||||
const { default: esbuild } = await import("esbuild-wasm");
|
||||
|
||||
await esbuild.initialize({
|
||||
worker: false,
|
||||
wasmURL: "https://esm.sh/[email protected]/esbuild.wasm",
|
||||
wasmURL: `${esmUrl}/[email protected]/esbuild.wasm`,
|
||||
});
|
||||
|
||||
return esbuild;
|
||||
|
||||
@@ -27,6 +27,12 @@ const resources = {
|
||||
language: 'Language',
|
||||
languageDescription: 'Select your preferred language for the interface.',
|
||||
|
||||
// System Settings Section
|
||||
systemSettings: 'System Settings',
|
||||
systemSettingsDescription: 'Configure system-level settings and advanced options.',
|
||||
esmUrl: 'ESM CDN URL',
|
||||
esmUrlDescription: 'Configure the ESM CDN URL for package imports. Default: https://esm.shakespeare.diy',
|
||||
|
||||
// Language Options
|
||||
english: 'English',
|
||||
portuguese: 'Portuguese',
|
||||
@@ -338,6 +344,12 @@ const resources = {
|
||||
language: 'Idioma',
|
||||
languageDescription: 'Selecione seu idioma preferido para a interface.',
|
||||
|
||||
// System Settings Section
|
||||
systemSettings: 'Configurações do Sistema',
|
||||
systemSettingsDescription: 'Configure configurações de nível de sistema e opções avançadas.',
|
||||
esmUrl: 'URL do CDN ESM',
|
||||
esmUrlDescription: 'Configure a URL do CDN ESM para importações de pacotes. Padrão: https://esm.shakespeare.diy',
|
||||
|
||||
// Language Options
|
||||
english: 'Inglês',
|
||||
portuguese: 'Português',
|
||||
@@ -649,6 +661,12 @@ const resources = {
|
||||
language: '语言',
|
||||
languageDescription: '选择您的界面首选语言。',
|
||||
|
||||
// System Settings Section
|
||||
systemSettings: '系统设置',
|
||||
systemSettingsDescription: '配置系统级设置和高级选项。',
|
||||
esmUrl: 'ESM CDN URL',
|
||||
esmUrlDescription: '配置包导入的 ESM CDN URL。默认:https://esm.shakespeare.diy',
|
||||
|
||||
// Language Options
|
||||
english: 'English',
|
||||
portuguese: 'Português',
|
||||
@@ -960,6 +978,12 @@ const resources = {
|
||||
language: 'Harshe',
|
||||
languageDescription: 'Zaɓi harshen da kuke so don dubawa.',
|
||||
|
||||
// System Settings Section
|
||||
systemSettings: 'Saitunan Tsarin',
|
||||
systemSettingsDescription: 'Saita saitunan matakin tsari da zaɓuɓɓuka na ci gaba.',
|
||||
esmUrl: 'URL na CDN ESM',
|
||||
esmUrlDescription: 'Saita URL na CDN ESM don shigo da fakitin. Tsoho: https://esm.shakespeare.diy',
|
||||
|
||||
// Language Options
|
||||
english: 'Turanci',
|
||||
portuguese: 'Fotigis',
|
||||
@@ -1271,6 +1295,12 @@ const resources = {
|
||||
language: 'Ede',
|
||||
languageDescription: 'Yan ede ti o fẹran fun wiwo.',
|
||||
|
||||
// System Settings Section
|
||||
systemSettings: 'Saitunan Eto',
|
||||
systemSettingsDescription: 'Tunto awọn saitan eto ati awọn ayanfẹ ti o pọju.',
|
||||
esmUrl: 'URL CDN ESM',
|
||||
esmUrlDescription: 'Tunto URL CDN ESM fun gbigbe awọn package. Aiyipada: https://esm.shakespeare.diy',
|
||||
|
||||
// Language Options
|
||||
english: 'Gẹẹsi',
|
||||
portuguese: 'Potogisi',
|
||||
@@ -1577,6 +1607,12 @@ const resources = {
|
||||
language: 'Asụsụ',
|
||||
languageDescription: 'Họrọ asụsụ ị chọrọ maka interface.',
|
||||
|
||||
// System Settings Section
|
||||
systemSettings: 'Ntọala Sistemu',
|
||||
systemSettingsDescription: 'Hazie ntọala ọkwa sistemu na nhọrọ ndị ọganihu.',
|
||||
esmUrl: 'URL CDN ESM',
|
||||
esmUrlDescription: 'Hazie URL CDN ESM maka mbubata ngwugwu. Default: https://esm.shakespeare.diy',
|
||||
|
||||
// Language Options
|
||||
english: 'Bekee',
|
||||
portuguese: 'Portuguese',
|
||||
|
||||
@@ -17,6 +17,7 @@ export class BuildProjectTool implements Tool<void> {
|
||||
try {
|
||||
// Build and write the project files
|
||||
const result = await buildProject({
|
||||
esmUrl: 'https://esm.shakespeare.diy',
|
||||
fs: this.fs,
|
||||
projectPath: this.cwd,
|
||||
domParser: new DOMParser(),
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { useNavigate } from 'react-router-dom';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
import { Bot, GitBranch, Database, Wifi, Settings2, Info } from 'lucide-react';
|
||||
import { Bot, GitBranch, Database, Wifi, Settings2, Info, Cog } from 'lucide-react';
|
||||
import { useIsMobile } from '@/hooks/useIsMobile';
|
||||
|
||||
interface SettingsItem {
|
||||
@@ -41,6 +41,13 @@ const getSettingsItems = (t: (key: string) => string): SettingsItem[] => [
|
||||
icon: Wifi,
|
||||
href: '/settings/nostr',
|
||||
},
|
||||
{
|
||||
id: 'system',
|
||||
title: t('systemSettings'),
|
||||
description: t('systemSettingsDescription'),
|
||||
icon: Cog,
|
||||
href: '/settings/system',
|
||||
},
|
||||
{
|
||||
id: 'data',
|
||||
title: t('dataSettings'),
|
||||
|
||||
@@ -0,0 +1,80 @@
|
||||
import { Settings2, ArrowLeft, Globe } from "lucide-react";
|
||||
import { useTranslation } from 'react-i18next';
|
||||
import { Button } from "@/components/ui/button";
|
||||
import { Input } from "@/components/ui/input";
|
||||
|
||||
import { Label } from "@/components/ui/label";
|
||||
import { useIsMobile } from "@/hooks/useIsMobile";
|
||||
import { useNavigate } from "react-router-dom";
|
||||
import { useAppContext } from "@/hooks/useAppContext";
|
||||
|
||||
export function SystemSettings() {
|
||||
const { t } = useTranslation();
|
||||
const isMobile = useIsMobile();
|
||||
const navigate = useNavigate();
|
||||
const { config, updateConfig } = useAppContext();
|
||||
|
||||
return (
|
||||
<div className="p-6 space-y-6">
|
||||
{isMobile && (
|
||||
<div className="space-y-3">
|
||||
<Button
|
||||
variant="ghost"
|
||||
size="sm"
|
||||
onClick={() => navigate('/settings')}
|
||||
className="h-8 w-auto px-2 -ml-2"
|
||||
>
|
||||
<ArrowLeft className="h-4 w-4 mr-2" />
|
||||
{t('backToSettings')}
|
||||
</Button>
|
||||
<div className="space-y-2">
|
||||
<h1 className="text-2xl font-bold flex items-center gap-3">
|
||||
<Settings2 className="h-6 w-6 text-primary" />
|
||||
{t('systemSettings')}
|
||||
</h1>
|
||||
<p className="text-muted-foreground">
|
||||
{t('systemSettingsDescription')}
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
|
||||
{!isMobile && (
|
||||
<div className="space-y-2">
|
||||
<h1 className="text-2xl font-bold flex items-center gap-3">
|
||||
<Settings2 className="h-6 w-6 text-primary" />
|
||||
{t('systemSettings')}
|
||||
</h1>
|
||||
<p className="text-muted-foreground">
|
||||
{t('systemSettingsDescription')}
|
||||
</p>
|
||||
</div>
|
||||
)}
|
||||
|
||||
<div className="space-y-6">
|
||||
<div className="space-y-2">
|
||||
<Label htmlFor="esm-url" className="flex items-center gap-2">
|
||||
<Globe className="h-4 w-4" />
|
||||
{t('esmUrl')}
|
||||
</Label>
|
||||
<Input
|
||||
id="esm-url"
|
||||
type="url"
|
||||
value={config.esmUrl}
|
||||
onChange={(e) => updateConfig((current) => ({
|
||||
...current,
|
||||
esmUrl: e.target.value,
|
||||
}))}
|
||||
className="w-full max-w-xs"
|
||||
placeholder="https://esm.shakespeare.diy"
|
||||
/>
|
||||
<p className="text-sm text-muted-foreground">
|
||||
{t('esmUrlDescription')}
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
export default SystemSettings;
|
||||
@@ -31,6 +31,7 @@ export function TestApp({ children }: TestAppProps) {
|
||||
theme: 'light',
|
||||
relayUrl: 'wss://relay.nostr.band',
|
||||
deployServer: 'shakespeare.wtf',
|
||||
esmUrl: 'https://esm.sh',
|
||||
language: 'en',
|
||||
};
|
||||
|
||||
|
||||
Reference in new issue
Block a user