Windows: Refactor Shell Scripts to Node.js for Cross-Platform Compatibility (#784)

This commit is contained in:
matt korwel
2025-06-09 12:19:42 -07:00
committed by GitHub
parent 2182a1cd2c
commit 3b943c1582
38 changed files with 1723 additions and 853 deletions

View File

@@ -15,7 +15,10 @@ interface DiffCommand {
function commandExists(cmd: string): boolean {
try {
execSync(`which ${cmd}`, { stdio: 'ignore' });
execSync(
process.platform === 'win32' ? `where.exe ${cmd}` : `command -v ${cmd}`,
{ stdio: 'ignore' },
);
return true;
} catch {
return false;
@@ -24,7 +27,9 @@ function commandExists(cmd: string): boolean {
export function checkHasEditor(editor: EditorType): boolean {
if (editor === 'vscode') {
return commandExists('code');
return process.platform === 'win32'
? commandExists('code.cmd')
: commandExists('code');
} else if (editor === 'vim') {
return commandExists('vim');
}
@@ -116,7 +121,10 @@ export async function openDiff(
});
} else {
// Use execSync for terminal-based editors like vim
const command = `${diffCommand.command} ${diffCommand.args.map((arg) => `"${arg}"`).join(' ')}`;
const command =
process.platform === 'win32'
? `${diffCommand.command} ${diffCommand.args.join(' ')}`
: `${diffCommand.command} ${diffCommand.args.map((arg) => `"${arg}"`).join(' ')}`;
execSync(command, {
stdio: 'inherit',
encoding: 'utf8',