-
Notifications
You must be signed in to change notification settings - Fork 214
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: use vscode settings for shell execution (#1134)
- Loading branch information
Showing
5 changed files
with
20 additions
and
113 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,59 +1,21 @@ | ||
import { detectPackageManager, getPackageManagerCommand } from '@nrwl/devkit'; | ||
import { ShellExecution } from 'vscode'; | ||
import { platform } from 'os'; | ||
import { execSync } from 'child_process'; | ||
|
||
export interface ShellConfig { | ||
/** Human-readable string which will be used to represent the terminal in the UI. */ | ||
name: string; | ||
program: string; | ||
args: string[]; | ||
cwd: string; | ||
displayCommand: string; | ||
} | ||
|
||
export function getShellExecutionForConfig( | ||
config: ShellConfig | ||
): ShellExecution { | ||
let execution: ShellExecution; | ||
if (platform() === 'win32') { | ||
execution = getWin32ShellExecution(config); | ||
} else { | ||
execution = getUnixShellExecution(config); | ||
} | ||
const packageManager = detectPackageManager(config.cwd); | ||
const packageManagerCommand = getPackageManagerCommand(packageManager); | ||
|
||
return execution; | ||
} | ||
|
||
function getWin32ShellExecution(config: ShellConfig): ShellExecution { | ||
return new ShellExecution(config.displayCommand, { | ||
cwd: config.cwd, | ||
executable: | ||
'C:\\WINDOWS\\System32\\WindowsPowerShell\\v1.0\\powershell.exe', | ||
shellArgs: [ | ||
`-Sta -NoLogo -NonInteractive -C "& {${config.program.replace( | ||
/ /g, | ||
'` ' // NOTE: In powershell ` is the escape key. | ||
)} ${config.args.join(' ')}}"`, | ||
], | ||
}); | ||
} | ||
|
||
let bashPath: string; | ||
function getUnixShellExecution(config: ShellConfig): ShellExecution { | ||
if (!bashPath) { | ||
try { | ||
bashPath = execSync('which bash').toString().trim() || '/bin/bash'; | ||
} catch { | ||
bashPath = '/bin/bash'; // Default to where bash is usually installed. | ||
return new ShellExecution( | ||
`${packageManagerCommand.exec} ${config.displayCommand}`, | ||
{ | ||
cwd: config.cwd, | ||
} | ||
} | ||
return new ShellExecution(config.displayCommand, { | ||
cwd: config.cwd, | ||
executable: bashPath, | ||
shellArgs: [ | ||
'-l', | ||
'-c', | ||
`${config.program.replace(/ /g, '\\ ')} ${config.args.join(' ')}`, | ||
], | ||
}); | ||
); | ||
} |