diff --git a/src/main.js b/src/main.js index 060fa86..4525c20 100644 --- a/src/main.js +++ b/src/main.js @@ -30,6 +30,7 @@ import { ConfigMenu } from "./ui/configMenu.js"; import { PathSelector } from "./utils/pathSelector.js"; import { NumberSelector } from "./utils/numberSelector.js"; import { MenuLoop } from "./utils/menuLoop.js"; +import { DataDirMover } from "./utils/dataDirMover.js"; async function showNavigationMenu() { console.log("\n"); diff --git a/src/services/configService.js b/src/services/configService.js index ffe5452..3b4b3b2 100644 --- a/src/services/configService.js +++ b/src/services/configService.js @@ -10,7 +10,7 @@ import { const defaultConfig = { codexExe: "", // User-selected config options: - codexPath: getCodexBinPath(), + codexInstallPath: getCodexBinPath(), dataDir: getCodexDataDirDefaultPath(), logsDir: getCodexLogsDefaultPath(), storageQuota: 8 * 1024 * 1024 * 1024, diff --git a/src/utils/command.js b/src/utils/command.js new file mode 100644 index 0000000..9ef5c91 --- /dev/null +++ b/src/utils/command.js @@ -0,0 +1,14 @@ +import { exec } from "child_process"; +import { promisify } from "util"; + +export const execAsync = promisify(exec); + +export async function runCommand(command) { + try { + const { stdout, stderr } = await execAsync(command); + return stdout; + } catch (error) { + console.error("Error:", error.message); + throw error; + } +} diff --git a/src/utils/pathSelector.js b/src/utils/pathSelector.js index af39af6..f75eba9 100644 --- a/src/utils/pathSelector.js +++ b/src/utils/pathSelector.js @@ -140,8 +140,13 @@ export class PathSelector { getSubDirOptions = () => { const fullPath = this.combine(this.currentPath); - const entries = this.fs.readDir(fullPath); - return entries.filter((entry) => this.isSubDir(entry)); + try { + const entries = this.fs.readDir(fullPath); + return entries.filter((entry) => this.isSubDir(entry)); + } + catch { + return []; + } }; downOne = async () => { diff --git a/src/utils/pathSelector.test.js b/src/utils/pathSelector.test.js index 16d5439..1cfebb1 100644 --- a/src/utils/pathSelector.test.js +++ b/src/utils/pathSelector.test.js @@ -101,6 +101,16 @@ describe("PathSelector", () => { expect(mockFsService.readDir).toHaveBeenCalledWith(mockStartPath); }); + it("handles non-existing paths", async () => { + mockFsService.readDir.mockImplementationOnce(() => { throw new Error("A!"); }); + + await pathSelector.downOne(); + + expect(mockUiService.showInfoMessage).toHaveBeenCalledWith( + "There are no subdirectories here." + ); + }); + it("can navigate to a subdirectory", async () => { const subdir = "subdir1"; mockFsService.readDir.mockReturnValue([subdir]);