Make FS paths configurable

This commit is contained in:
Alex Gleason committed 2025-10-23 14:50:05 -05:00
1 parent f89a481c9c
commit d75bd386aa
43 files changed
+393 -124

No files matched your search

+3
View File
@@ -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(),
});
+3 -1
View File
@@ -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,
});
+19
View File
@@ -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,
};
}
+3
View File
@@ -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(
+3 -1
View File
@@ -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 {
+4 -2
View File
@@ -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 {
+5 -3
View File
@@ -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;
}