Files
钟明原 6f4ee6861b fix: 内置 MinGit 彻底修复 Windows 程序内升级 git ENOENT/EINVAL
- 新增 scripts/bundle-git.mjs:下载 MinGit 到 resources/git/win/
- CI build-win.yml 新增 Bundle MinGit 步骤
- package.json Win extraResources 加入 resources/git/win -> git
- .gitignore 忽略 resources/git/
- bundled-process.ts 新增 getBundledGitBin()
- update.ts 移除 fake git 逻辑,改用内置 MinGit(npm_config_git)
2026-03-15 19:15:22 +08:00

52 lines
1.6 KiB
JavaScript
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
#!/usr/bin/env node
/**
* bundle-git.mjs — 下载 MinGit(Windows 最小 Git 分发)到 resources/git/win/
*
* 只在 Windows 上有效(CI build-win 步骤自动调用)。
* macOS / Linux 有系统 git,无需内置。
*/
import { execSync } from 'child_process'
import { existsSync } from 'fs'
import { mkdir } from 'fs/promises'
import { join, dirname } from 'path'
import { fileURLToPath } from 'url'
const __dirname = dirname(fileURLToPath(import.meta.url))
const root = join(__dirname, '..')
const GIT_VER = '2.47.0'
const DEST = join(root, 'resources', 'git', 'win')
if (process.platform !== 'win32') {
console.log('[bundle-git] 非 Windows,跳过')
process.exit(0)
}
const gitExe = join(DEST, 'cmd', 'git.exe')
if (existsSync(gitExe)) {
console.log(`[bundle-git] MinGit 已存在于 ${DEST},跳过`)
process.exit(0)
}
await mkdir(DEST, { recursive: true })
await mkdir(join(root, 'build'), { recursive: true })
const url = `https://github.com/git-for-windows/git/releases/download/v${GIT_VER}.windows.1/MinGit-${GIT_VER}-64-bit.zip`
const zipPath = join(root, 'build', 'mingit.zip')
console.log(`[bundle-git] 下载 MinGit ${GIT_VER}...`)
execSync(
`powershell -Command "Invoke-WebRequest -Uri '${url}' -OutFile '${zipPath}'"`,
{ stdio: 'inherit' }
)
console.log(`[bundle-git] 解压到 ${DEST}...`)
execSync(
`powershell -Command "Expand-Archive -Path '${zipPath}' -DestinationPath '${DEST}' -Force"`,
{ stdio: 'inherit' }
)
execSync(`del /f "${zipPath}"`, { shell: true })
console.log(`[bundle-git] ✓ MinGit ${GIT_VER} 就绪:${DEST}`)