(filePath: string, tempFilePath: string)
| 53 | } |
| 54 | |
| 55 | function getDiff(filePath: string, tempFilePath: string): Promise<void> { |
| 56 | return new Promise((resolve, reject) => { |
| 57 | const { platform } = process; |
| 58 | let editor = ""; |
| 59 | |
| 60 | // Determine the editor based on platform and availability of VS Code |
| 61 | if (platform === "win32") { |
| 62 | if (checkIfCodeInstalled()) { |
| 63 | editor = "code"; |
| 64 | } else { |
| 65 | reject( |
| 66 | new Error("Visual Studio Code is not installed. Please install VS Code to continue."), |
| 67 | ); |
| 68 | return; |
| 69 | } |
| 70 | } else if (platform === "darwin" || platform === "linux") { |
| 71 | editor = checkIfCodeInstalled() ? "code" : "vim"; |
| 72 | } else { |
| 73 | reject(new Error(`Unsupported platform: ${platform}`)); |
| 74 | return; |
| 75 | } |
| 76 | |
| 77 | // Construct the appropriate diff command |
| 78 | let diffCommand = ""; |
| 79 | |
| 80 | if (editor === "code") { |
| 81 | diffCommand = `${editor} --diff ${filePath} ${tempFilePath}`; |
| 82 | } else if (editor === "vim") { |
| 83 | diffCommand = `${editor} -d ${filePath} ${tempFilePath}`; |
| 84 | } |
| 85 | |
| 86 | // Execute the diff command |
| 87 | const diffProcess = spawn(diffCommand, { shell: true, stdio: "inherit" }); |
| 88 | |
| 89 | diffProcess.on("exit", (code) => { |
| 90 | if (code !== 0) { |
| 91 | reject(new Error("Error opening diff in editor")); |
| 92 | } else { |
| 93 | resolve(); |
| 94 | } |
| 95 | }); |
| 96 | }); |
| 97 | } |
| 98 | |
| 99 | async function renderTemplate( |
| 100 | template: string | undefined, |
no test coverage detected