's'
This commit is contained in:
@@ -1,143 +0,0 @@
|
||||
/**
|
||||
* 下载 Chrome for Testing(Stable / win64)完整目录到 resources/chrome-cft/chrome-win64/,
|
||||
* 与 chrome.exe 同级的 DLL 等依赖一并保留,随安装包分发,开箱即用。
|
||||
* 设置 SKIP_CHROME=1 可跳过(CI 无网环境)。
|
||||
*/
|
||||
import fs from 'fs'
|
||||
import https from 'https'
|
||||
import path from 'path'
|
||||
import { fileURLToPath } from 'url'
|
||||
import AdmZip from 'adm-zip'
|
||||
|
||||
const __dirname = path.dirname(fileURLToPath(import.meta.url))
|
||||
const root = path.resolve(__dirname, '..')
|
||||
const resDir = path.join(root, 'resources', 'chrome-cft')
|
||||
const CFT_JSON_URL =
|
||||
'https://googlechromelabs.github.io/chrome-for-testing/last-known-good-versions-with-downloads.json'
|
||||
const PLATFORM_KEY = 'win64'
|
||||
const markerName = '.chrome_cft_bundle_ok'
|
||||
|
||||
if (process.env.SKIP_CHROME === '1') {
|
||||
console.log('[chrome-cft] SKIP_CHROME=1,跳过下载')
|
||||
process.exit(0)
|
||||
}
|
||||
|
||||
function downloadBuffer(url) {
|
||||
return new Promise((resolve, reject) => {
|
||||
https
|
||||
.get(url, (res) => {
|
||||
if (res.statusCode >= 300 && res.statusCode < 400 && res.headers.location) {
|
||||
downloadBuffer(res.headers.location).then(resolve).catch(reject)
|
||||
return
|
||||
}
|
||||
if (res.statusCode !== 200) {
|
||||
reject(new Error(`HTTP ${res.statusCode} ${url}`))
|
||||
return
|
||||
}
|
||||
const chunks = []
|
||||
res.on('data', (c) => chunks.push(c))
|
||||
res.on('end', () => resolve(Buffer.concat(chunks)))
|
||||
res.on('error', reject)
|
||||
})
|
||||
.on('error', reject)
|
||||
})
|
||||
}
|
||||
|
||||
function downloadToFile(url, dest) {
|
||||
return new Promise((resolve, reject) => {
|
||||
const file = fs.createWriteStream(dest)
|
||||
https
|
||||
.get(url, (res) => {
|
||||
if (res.statusCode >= 300 && res.statusCode < 400 && res.headers.location) {
|
||||
file.close()
|
||||
try {
|
||||
fs.unlinkSync(dest)
|
||||
} catch {
|
||||
/* ignore */
|
||||
}
|
||||
downloadToFile(res.headers.location, dest).then(resolve).catch(reject)
|
||||
return
|
||||
}
|
||||
if (res.statusCode !== 200) {
|
||||
file.close()
|
||||
reject(new Error(`HTTP ${res.statusCode}`))
|
||||
return
|
||||
}
|
||||
res.pipe(file)
|
||||
file.on('finish', () => {
|
||||
file.close()
|
||||
resolve()
|
||||
})
|
||||
})
|
||||
.on('error', (e) => {
|
||||
try {
|
||||
file.close()
|
||||
} catch {
|
||||
/* ignore */
|
||||
}
|
||||
reject(e)
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
const chromeExe = path.join(resDir, 'chrome-win64', 'chrome.exe')
|
||||
const markerPath = path.join(resDir, markerName)
|
||||
|
||||
fs.mkdirSync(resDir, { recursive: true })
|
||||
|
||||
if (fs.existsSync(chromeExe) && fs.existsSync(markerPath)) {
|
||||
console.log('[chrome-cft] 已存在完整包,跳过:', chromeExe)
|
||||
process.exit(0)
|
||||
}
|
||||
|
||||
console.log('[chrome-cft] 获取元数据:', CFT_JSON_URL)
|
||||
const metaBuf = await downloadBuffer(CFT_JSON_URL)
|
||||
const doc = JSON.parse(metaBuf.toString('utf-8'))
|
||||
const stable = doc.channels?.Stable
|
||||
const list = stable?.downloads?.chrome ?? []
|
||||
const hit = list.find((x) => x.platform === PLATFORM_KEY)
|
||||
if (!hit?.url) {
|
||||
console.error('[chrome-cft] 元数据中无', PLATFORM_KEY)
|
||||
process.exit(1)
|
||||
}
|
||||
|
||||
const zipPath = path.join(resDir, '_chrome-download.zip')
|
||||
console.log('[chrome-cft] 下载(体积较大):', hit.url)
|
||||
await downloadToFile(hit.url, zipPath)
|
||||
|
||||
console.log('[chrome-cft] 解压中…')
|
||||
const zip = new AdmZip(zipPath)
|
||||
const tmp = path.join(resDir, '_extract_tmp')
|
||||
if (fs.existsSync(tmp)) fs.rmSync(tmp, { recursive: true })
|
||||
fs.mkdirSync(tmp, { recursive: true })
|
||||
zip.extractAllTo(tmp, true)
|
||||
|
||||
const inner = path.join(tmp, 'chrome-win64')
|
||||
if (!fs.existsSync(path.join(inner, 'chrome.exe'))) {
|
||||
console.error('[chrome-cft] zip 内未找到 chrome-win64/chrome.exe')
|
||||
process.exit(1)
|
||||
}
|
||||
|
||||
const destDir = path.join(resDir, 'chrome-win64')
|
||||
if (fs.existsSync(destDir)) fs.rmSync(destDir, { recursive: true })
|
||||
fs.cpSync(inner, destDir, { recursive: true })
|
||||
fs.rmSync(tmp, { recursive: true })
|
||||
|
||||
try {
|
||||
fs.unlinkSync(zipPath)
|
||||
} catch {
|
||||
/* ignore */
|
||||
}
|
||||
|
||||
fs.writeFileSync(
|
||||
path.join(resDir, 'NOTICE-ChromeForTesting.txt'),
|
||||
[
|
||||
'本目录包含 Chrome for Testing(Stable / Windows x64)。',
|
||||
'清单来源:' + CFT_JSON_URL,
|
||||
'与 chrome.exe 同目录文件均为官方 zip 原样复制,未修改二进制。',
|
||||
'',
|
||||
].join('\n'),
|
||||
'utf-8',
|
||||
)
|
||||
fs.writeFileSync(markerPath, `${stable.version}\n${new Date().toISOString()}\n`, 'utf-8')
|
||||
console.log('[chrome-cft] 完成:', chromeExe)
|
||||
@@ -1,103 +0,0 @@
|
||||
/**
|
||||
* 下载官方 EasyTier Windows x64 发行包并解压到 resources/easytier/
|
||||
* 须复制 exe 同目录下全部 DLL 等依赖,否则 easytier-core 会以 0xC0000135(3221225781)退出。
|
||||
* 设置 SKIP_EASYTIER=1 可跳过(CI 无网环境)
|
||||
*/
|
||||
import fs from 'fs'
|
||||
import path from 'path'
|
||||
import https from 'https'
|
||||
import { fileURLToPath } from 'url'
|
||||
import AdmZip from 'adm-zip'
|
||||
|
||||
const __dirname = path.dirname(fileURLToPath(import.meta.url))
|
||||
const root = path.resolve(__dirname, '..')
|
||||
const resDir = path.join(root, 'resources', 'easytier')
|
||||
const DEFAULT_URL =
|
||||
process.env.EASYTIER_DOWNLOAD_URL ||
|
||||
'https://github.com/EasyTier/EasyTier/releases/download/v2.4.5/easytier-windows-x86_64-v2.4.5.zip'
|
||||
const exeName = 'easytier-core.exe'
|
||||
const bundleMarker = '.easytier_bundle_ok'
|
||||
|
||||
if (process.env.SKIP_EASYTIER === '1') {
|
||||
console.log('[easytier] SKIP_EASYTIER=1,跳过下载')
|
||||
process.exit(0)
|
||||
}
|
||||
|
||||
function download(url) {
|
||||
return new Promise((resolve, reject) => {
|
||||
https
|
||||
.get(url, (res) => {
|
||||
if (res.statusCode >= 300 && res.statusCode < 400 && res.headers.location) {
|
||||
download(res.headers.location).then(resolve).catch(reject)
|
||||
return
|
||||
}
|
||||
if (res.statusCode !== 200) {
|
||||
reject(new Error(`HTTP ${res.statusCode} ${url}`))
|
||||
return
|
||||
}
|
||||
const chunks = []
|
||||
res.on('data', (c) => chunks.push(c))
|
||||
res.on('end', () => resolve(Buffer.concat(chunks)))
|
||||
res.on('error', reject)
|
||||
})
|
||||
.on('error', reject)
|
||||
})
|
||||
}
|
||||
|
||||
function findExe(dir, name) {
|
||||
if (!fs.existsSync(dir)) return null
|
||||
for (const f of fs.readdirSync(dir, { withFileTypes: true })) {
|
||||
const p = path.join(dir, f.name)
|
||||
if (f.isDirectory()) {
|
||||
const r = findExe(p, name)
|
||||
if (r) return r
|
||||
} else if (f.name === name) {
|
||||
return p
|
||||
}
|
||||
}
|
||||
return null
|
||||
}
|
||||
|
||||
fs.mkdirSync(resDir, { recursive: true })
|
||||
const outExe = path.join(resDir, exeName)
|
||||
const markerPath = path.join(resDir, bundleMarker)
|
||||
if (fs.existsSync(outExe) && fs.existsSync(markerPath)) {
|
||||
console.log('[easytier] 已存在完整包,跳过:', outExe)
|
||||
process.exit(0)
|
||||
}
|
||||
if (fs.existsSync(outExe) && !fs.existsSync(markerPath)) {
|
||||
console.log('[easytier] 检测到旧版仅复制了 exe,将重新下载并解压全部依赖文件…')
|
||||
}
|
||||
|
||||
console.log('[easytier] 下载:', DEFAULT_URL)
|
||||
const buf = await download(DEFAULT_URL)
|
||||
const zip = new AdmZip(buf)
|
||||
const tmp = path.join(resDir, '_extract_tmp')
|
||||
if (fs.existsSync(tmp)) fs.rmSync(tmp, { recursive: true })
|
||||
fs.mkdirSync(tmp, { recursive: true })
|
||||
zip.extractAllTo(tmp, true)
|
||||
const found = findExe(tmp, exeName)
|
||||
if (!found) {
|
||||
console.error('[easytier] zip 内未找到', exeName)
|
||||
process.exit(1)
|
||||
}
|
||||
const srcDir = path.dirname(found)
|
||||
for (const name of fs.readdirSync(srcDir)) {
|
||||
const from = path.join(srcDir, name)
|
||||
const to = path.join(resDir, name)
|
||||
if (!fs.statSync(from).isFile()) continue
|
||||
fs.copyFileSync(from, to)
|
||||
}
|
||||
fs.rmSync(tmp, { recursive: true })
|
||||
fs.writeFileSync(
|
||||
path.join(resDir, 'NOTICE-EasyTier.txt'),
|
||||
[
|
||||
'EasyTier 以 LGPL-3.0 授权发布。',
|
||||
'源码: https://github.com/EasyTier/EasyTier',
|
||||
'本程序随官方 GitHub Release 附带 easytier-core.exe 及同目录依赖,未修改二进制。',
|
||||
'',
|
||||
].join('\n'),
|
||||
'utf-8',
|
||||
)
|
||||
fs.writeFileSync(markerPath, `${new Date().toISOString()}\n`, 'utf-8')
|
||||
console.log('[easytier] 完成(已复制 zip 内同目录全部文件):', outExe)
|
||||
Reference in New Issue
Block a user