|
|
@@ -226,8 +226,10 @@ export async function checkAllInstalled(): Promise<AllInstalledInfo> {
|
|
|
|
|
|
/**
|
|
|
* 获取 Node.js 安装命令
|
|
|
+ * @param version 版本号
|
|
|
+ * @param customPath 自定义安装路径 (仅 Windows 支持)
|
|
|
*/
|
|
|
-function getNodeInstallArgs(version = 'lts'): CommandResult {
|
|
|
+function getNodeInstallArgs(version = 'lts', customPath?: string): CommandResult {
|
|
|
const platform = os.platform() as Platform
|
|
|
const major = version.split('.')[0]
|
|
|
const majorNum = parseInt(major)
|
|
|
@@ -255,6 +257,9 @@ function getNodeInstallArgs(version = 'lts'): CommandResult {
|
|
|
if (version !== 'lts' && version.includes('.')) {
|
|
|
args.push('--version', version)
|
|
|
}
|
|
|
+ if (customPath) {
|
|
|
+ args.push('--location', customPath)
|
|
|
+ }
|
|
|
return { command: 'winget', args }
|
|
|
}
|
|
|
case 'darwin':
|
|
|
@@ -268,17 +273,21 @@ function getNodeInstallArgs(version = 'lts'): CommandResult {
|
|
|
|
|
|
/**
|
|
|
* 获取 VS Code 安装命令
|
|
|
+ * @param version 版本号
|
|
|
+ * @param customPath 自定义安装路径 (仅 Windows 支持)
|
|
|
*/
|
|
|
-function getVSCodeInstallArgs(version = 'stable'): CommandResult {
|
|
|
+function getVSCodeInstallArgs(version = 'stable', customPath?: string): CommandResult {
|
|
|
const platform = os.platform() as Platform
|
|
|
|
|
|
if (version === 'insiders') {
|
|
|
switch (platform) {
|
|
|
- case 'win32':
|
|
|
- return {
|
|
|
- command: 'winget',
|
|
|
- args: ['install', '-e', '--id', WINGET_PACKAGES.vscode.insiders, '--silent', '--accept-source-agreements', '--accept-package-agreements']
|
|
|
+ case 'win32': {
|
|
|
+ const args = ['install', '-e', '--id', WINGET_PACKAGES.vscode.insiders, '--silent', '--accept-source-agreements', '--accept-package-agreements']
|
|
|
+ if (customPath) {
|
|
|
+ args.push('--location', customPath)
|
|
|
}
|
|
|
+ return { command: 'winget', args }
|
|
|
+ }
|
|
|
case 'darwin':
|
|
|
return {
|
|
|
command: 'brew',
|
|
|
@@ -297,6 +306,9 @@ function getVSCodeInstallArgs(version = 'stable'): CommandResult {
|
|
|
if (version !== 'stable' && /^\d+\.\d+\.\d+$/.test(version)) {
|
|
|
args.push('--version', version)
|
|
|
}
|
|
|
+ if (customPath) {
|
|
|
+ args.push('--location', customPath)
|
|
|
+ }
|
|
|
return { command: 'winget', args }
|
|
|
}
|
|
|
case 'darwin':
|
|
|
@@ -313,14 +325,21 @@ function getVSCodeInstallArgs(version = 'stable'): CommandResult {
|
|
|
|
|
|
/**
|
|
|
* 获取 Git 安装命令
|
|
|
+ * @param version 版本号
|
|
|
+ * @param customPath 自定义安装路径 (仅 Windows 支持)
|
|
|
*/
|
|
|
-function getGitInstallArgs(version = 'stable'): CommandResult {
|
|
|
+function getGitInstallArgs(version = 'stable', customPath?: string): CommandResult {
|
|
|
const platform = os.platform() as Platform
|
|
|
|
|
|
if (version === 'mingit') {
|
|
|
switch (platform) {
|
|
|
- case 'win32':
|
|
|
- return { command: 'winget', args: ['install', '-e', '--id', WINGET_PACKAGES.git.mingit, '--silent', '--accept-source-agreements', '--accept-package-agreements'] }
|
|
|
+ case 'win32': {
|
|
|
+ const args = ['install', '-e', '--id', WINGET_PACKAGES.git.mingit, '--silent', '--accept-source-agreements', '--accept-package-agreements']
|
|
|
+ if (customPath) {
|
|
|
+ args.push('--location', customPath)
|
|
|
+ }
|
|
|
+ return { command: 'winget', args }
|
|
|
+ }
|
|
|
case 'darwin':
|
|
|
return { command: 'brew', args: ['install', BREW_PACKAGES.git.stable] }
|
|
|
case 'linux':
|
|
|
@@ -332,8 +351,13 @@ function getGitInstallArgs(version = 'stable'): CommandResult {
|
|
|
|
|
|
if (version === 'lfs') {
|
|
|
switch (platform) {
|
|
|
- case 'win32':
|
|
|
- return { command: 'winget', args: ['install', '-e', '--id', WINGET_PACKAGES.git.lfs, '--silent', '--accept-source-agreements', '--accept-package-agreements'] }
|
|
|
+ case 'win32': {
|
|
|
+ const args = ['install', '-e', '--id', WINGET_PACKAGES.git.lfs, '--silent', '--accept-source-agreements', '--accept-package-agreements']
|
|
|
+ if (customPath) {
|
|
|
+ args.push('--location', customPath)
|
|
|
+ }
|
|
|
+ return { command: 'winget', args }
|
|
|
+ }
|
|
|
case 'darwin':
|
|
|
return { command: 'brew', args: ['install', BREW_PACKAGES.git.lfs] }
|
|
|
case 'linux':
|
|
|
@@ -349,6 +373,9 @@ function getGitInstallArgs(version = 'stable'): CommandResult {
|
|
|
if (version !== 'stable' && /^\d+\.\d+\.\d+$/.test(version)) {
|
|
|
args.push('--version', version)
|
|
|
}
|
|
|
+ if (customPath) {
|
|
|
+ args.push('--location', customPath)
|
|
|
+ }
|
|
|
return { command: 'winget', args }
|
|
|
}
|
|
|
case 'darwin':
|
|
|
@@ -434,16 +461,21 @@ async function aptUpdate(onStatus: StatusCallback, software: SoftwareTypeWithAll
|
|
|
|
|
|
/**
|
|
|
* 安装 Node.js
|
|
|
+ * @param version 版本号
|
|
|
+ * @param installPnpm 是否安装 pnpm
|
|
|
+ * @param onStatus 状态回调
|
|
|
+ * @param customPath 自定义安装路径 (仅 Windows 支持)
|
|
|
*/
|
|
|
export async function installNodejs(
|
|
|
version = 'lts',
|
|
|
installPnpm = true,
|
|
|
- onStatus: StatusCallback
|
|
|
+ onStatus: StatusCallback,
|
|
|
+ customPath?: string
|
|
|
): Promise<void> {
|
|
|
resetCancelState()
|
|
|
|
|
|
onStatus('nodejs', `${STATUS_MESSAGES.INSTALLING} Node.js...`, 20)
|
|
|
- const args = getNodeInstallArgs(version)
|
|
|
+ const args = getNodeInstallArgs(version, customPath)
|
|
|
await executeCommand(args.command, args.args, true)
|
|
|
|
|
|
checkCancelled()
|
|
|
@@ -483,24 +515,30 @@ export async function installNodejs(
|
|
|
|
|
|
/**
|
|
|
* 安装 VS Code
|
|
|
+ * @param version 版本号
|
|
|
+ * @param onStatus 状态回调
|
|
|
+ * @param customPath 自定义安装路径 (仅 Windows 支持)
|
|
|
*/
|
|
|
-export async function installVscode(version = 'stable', onStatus: StatusCallback): Promise<void> {
|
|
|
+export async function installVscode(version = 'stable', onStatus: StatusCallback, customPath?: string): Promise<void> {
|
|
|
resetCancelState()
|
|
|
|
|
|
onStatus('vscode', `${STATUS_MESSAGES.INSTALLING} VS Code...`, 30)
|
|
|
- const args = getVSCodeInstallArgs(version)
|
|
|
+ const args = getVSCodeInstallArgs(version, customPath)
|
|
|
await executeCommand(args.command, args.args, true)
|
|
|
onStatus('vscode', STATUS_MESSAGES.COMPLETE, 100)
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 安装 Git
|
|
|
+ * @param version 版本号
|
|
|
+ * @param onStatus 状态回调
|
|
|
+ * @param customPath 自定义安装路径 (仅 Windows 支持)
|
|
|
*/
|
|
|
-export async function installGit(version = 'stable', onStatus: StatusCallback): Promise<void> {
|
|
|
+export async function installGit(version = 'stable', onStatus: StatusCallback, customPath?: string): Promise<void> {
|
|
|
resetCancelState()
|
|
|
|
|
|
onStatus('git', `${STATUS_MESSAGES.INSTALLING} Git...`, 30)
|
|
|
- const args = getGitInstallArgs(version)
|
|
|
+ const args = getGitInstallArgs(version, customPath)
|
|
|
await executeCommand(args.command, args.args, true)
|
|
|
onStatus('git', STATUS_MESSAGES.COMPLETE, 100)
|
|
|
}
|
|
|
@@ -529,11 +567,14 @@ export async function installAll(options: InstallOptions, onStatus: StatusCallba
|
|
|
const {
|
|
|
installNodejs: doNodejs = true,
|
|
|
nodejsVersion = 'lts',
|
|
|
+ nodejsPath,
|
|
|
installPnpm: doPnpm = true,
|
|
|
installVscode: doVscode = true,
|
|
|
vscodeVersion = 'stable',
|
|
|
+ vscodePath,
|
|
|
installGit: doGit = true,
|
|
|
gitVersion = 'stable',
|
|
|
+ gitPath,
|
|
|
installClaudeCode: doClaudeCode = false
|
|
|
} = options
|
|
|
|
|
|
@@ -549,7 +590,7 @@ export async function installAll(options: InstallOptions, onStatus: StatusCallba
|
|
|
if (doNodejs) {
|
|
|
checkCancelled()
|
|
|
onStatus('all', `${STATUS_MESSAGES.INSTALLING} Node.js...`, getProgress())
|
|
|
- const nodeArgs = getNodeInstallArgs(nodejsVersion)
|
|
|
+ const nodeArgs = getNodeInstallArgs(nodejsVersion, nodejsPath)
|
|
|
await executeCommand(nodeArgs.command, nodeArgs.args, true)
|
|
|
|
|
|
// 使用完整路径,避免 PATH 未生效的问题
|
|
|
@@ -582,7 +623,7 @@ export async function installAll(options: InstallOptions, onStatus: StatusCallba
|
|
|
if (doVscode) {
|
|
|
checkCancelled()
|
|
|
onStatus('all', `${STATUS_MESSAGES.INSTALLING} VS Code...`, getProgress())
|
|
|
- const vscodeArgs = getVSCodeInstallArgs(vscodeVersion)
|
|
|
+ const vscodeArgs = getVSCodeInstallArgs(vscodeVersion, vscodePath)
|
|
|
await executeCommand(vscodeArgs.command, vscodeArgs.args, true)
|
|
|
currentStep++
|
|
|
}
|
|
|
@@ -591,7 +632,7 @@ export async function installAll(options: InstallOptions, onStatus: StatusCallba
|
|
|
if (doGit) {
|
|
|
checkCancelled()
|
|
|
onStatus('all', `${STATUS_MESSAGES.INSTALLING} Git...`, getProgress())
|
|
|
- const gitArgs = getGitInstallArgs(gitVersion)
|
|
|
+ const gitArgs = getGitInstallArgs(gitVersion, gitPath)
|
|
|
await executeCommand(gitArgs.command, gitArgs.args, true)
|
|
|
currentStep++
|
|
|
}
|