mirror of
https://gitlab.com/soapbox-pub/shakespeare.git
synced 2026-12-05 16:23:36 +00:00
Make FS paths configurable
This commit is contained in:
43 files changed
+393
-124
No files matched your search
@@ -50,6 +50,9 @@ describe('useAIProjectId', () => {
|
||||
showcaseEnabled: true,
|
||||
showcaseModerator: 'npub1jvnpg4c6ljadf5t6ry0w9q0rnm4mksde87kglkrc993z46c39axsgq89sc',
|
||||
ngitServers: ['git.shakespeare.diy', 'relay.ngit.dev'],
|
||||
fsPathProjects: '/projects',
|
||||
fsPathConfig: '/config',
|
||||
fsPathTmp: '/tmp',
|
||||
},
|
||||
updateConfig: vi.fn(),
|
||||
});
|
||||
|
||||
@@ -1,17 +1,19 @@
|
||||
import { useMutation } from "@tanstack/react-query";
|
||||
import { buildProject } from "@/lib/build";
|
||||
import { useFS } from "./useFS";
|
||||
import { useFSPaths } from "./useFSPaths";
|
||||
import { useAppContext } from "./useAppContext";
|
||||
|
||||
export function useBuildProject(projectId: string) {
|
||||
const { fs } = useFS();
|
||||
const { projectsPath } = useFSPaths();
|
||||
const { config } = useAppContext();
|
||||
|
||||
return useMutation({
|
||||
mutationFn: async () => {
|
||||
return await buildProject({
|
||||
fs,
|
||||
projectPath: `/projects/${projectId}`,
|
||||
projectPath: `${projectsPath}/${projectId}`,
|
||||
domParser: new DOMParser(),
|
||||
esmUrl: config.esmUrl,
|
||||
});
|
||||
|
||||
@@ -0,0 +1,19 @@
|
||||
import { useAppContext } from '@/hooks/useAppContext';
|
||||
|
||||
/**
|
||||
* Hook to access configured virtual filesystem paths
|
||||
*
|
||||
* @returns Object containing VFS path configurations
|
||||
*/
|
||||
export function useFSPaths() {
|
||||
const { config } = useAppContext();
|
||||
|
||||
return {
|
||||
/** Projects directory path (default: /projects) */
|
||||
projectsPath: config.fsPathProjects,
|
||||
/** Config directory path (default: /config) */
|
||||
configPath: config.fsPathConfig,
|
||||
/** Temporary files directory path (default: /tmp) */
|
||||
tmpPath: config.fsPathTmp,
|
||||
};
|
||||
}
|
||||
@@ -42,6 +42,9 @@ function createWrapper(corsProxy: string) {
|
||||
showcaseEnabled: true,
|
||||
showcaseModerator: 'npub1jvnpg4c6ljadf5t6ry0w9q0rnm4mksde87kglkrc993z46c39axsgq89sc',
|
||||
ngitServers: ['git.shakespeare.diy', 'relay.ngit.dev'],
|
||||
fsPathProjects: '/projects',
|
||||
fsPathConfig: '/config',
|
||||
fsPathTmp: '/tmp',
|
||||
};
|
||||
|
||||
return createElement(
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import { useQuery } from '@tanstack/react-query';
|
||||
import { useGit } from './useGit';
|
||||
import { useFSPaths } from './useFSPaths';
|
||||
|
||||
interface GitFileChange {
|
||||
filepath: string;
|
||||
@@ -41,6 +42,7 @@ interface GitStatus {
|
||||
|
||||
export function useGitStatus(projectId: string | null) {
|
||||
const { git } = useGit();
|
||||
const { projectsPath } = useFSPaths();
|
||||
|
||||
return useQuery({
|
||||
queryKey: ['git-status', projectId],
|
||||
@@ -61,7 +63,7 @@ export function useGitStatus(projectId: string | null) {
|
||||
}
|
||||
|
||||
try {
|
||||
const cwd = `/projects/${projectId}`;
|
||||
const cwd = `${projectsPath}/${projectId}`;
|
||||
|
||||
// Check if we're in a git repository
|
||||
try {
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import { useState, useEffect, useCallback } from 'react';
|
||||
import { useFS } from './useFS';
|
||||
import { useFSPaths } from './useFSPaths';
|
||||
|
||||
export interface ShakespeareProjectConfig {
|
||||
type: 'shakespeare';
|
||||
@@ -43,10 +44,11 @@ export interface ProjectDeploySettings {
|
||||
*/
|
||||
export function useProjectDeploySettings(projectId: string) {
|
||||
const fs = useFS();
|
||||
const { projectsPath } = useFSPaths();
|
||||
const [settings, setSettings] = useState<ProjectDeploySettings>({ providers: {} });
|
||||
const [isLoading, setIsLoading] = useState(true);
|
||||
|
||||
const settingsPath = `/projects/${projectId}/.git/shakespeare/deploy.json`;
|
||||
const settingsPath = `${projectsPath}/${projectId}/.git/shakespeare/deploy.json`;
|
||||
|
||||
const loadSettings = useCallback(async () => {
|
||||
try {
|
||||
@@ -78,7 +80,7 @@ export function useProjectDeploySettings(projectId: string) {
|
||||
const saveSettings = async (newSettings: ProjectDeploySettings) => {
|
||||
try {
|
||||
// Ensure .git/shakespeare directory exists
|
||||
const shakespeareDir = `/projects/${projectId}/.git/shakespeare`;
|
||||
const shakespeareDir = `${projectsPath}/${projectId}/.git/shakespeare`;
|
||||
try {
|
||||
await fs.fs.stat(shakespeareDir);
|
||||
} catch {
|
||||
|
||||
@@ -1,19 +1,21 @@
|
||||
import { useMemo } from 'react';
|
||||
import { ProjectsManager } from '@/lib/ProjectsManager';
|
||||
import { useFS } from '@/hooks/useFS';
|
||||
import { useFSPaths } from '@/hooks/useFSPaths';
|
||||
import { useGit } from './useGit';
|
||||
|
||||
/**
|
||||
* Hook that provides a ProjectsManager instance.
|
||||
* The ProjectsManager is memoized based on the fs instance.
|
||||
* The ProjectsManager is memoized based on the fs instance and configured paths.
|
||||
*/
|
||||
export function useProjectsManager() {
|
||||
const { fs } = useFS();
|
||||
const { git } = useGit();
|
||||
const { projectsPath } = useFSPaths();
|
||||
|
||||
const projectsManager = useMemo(() => {
|
||||
return new ProjectsManager({ fs, git });
|
||||
}, [fs, git]);
|
||||
return new ProjectsManager({ fs, git, projectsPath });
|
||||
}, [fs, git, projectsPath]);
|
||||
|
||||
return projectsManager;
|
||||
}
|
||||
Reference in new issue
Block a user