chore(cli): acr update 下載/解壓進度提示(chalk gray)
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
@@ -12,6 +12,7 @@ import { execFileSync } from 'node:child_process';
|
|||||||
import { mkdtempSync, readFileSync, writeFileSync, existsSync, readdirSync, statSync } from 'node:fs';
|
import { mkdtempSync, readFileSync, writeFileSync, existsSync, readdirSync, statSync } from 'node:fs';
|
||||||
import { tmpdir } from 'node:os';
|
import { tmpdir } from 'node:os';
|
||||||
import { join } from 'node:path';
|
import { join } from 'node:path';
|
||||||
|
import chalk from 'chalk';
|
||||||
|
|
||||||
/** GitHub repo(codeload tarball 來源)。fork 者改這裡或用 ARCRUN_REPO env。
|
/** GitHub repo(codeload tarball 來源)。fork 者改這裡或用 ARCRUN_REPO env。
|
||||||
* 注意:repo 名大小寫敏感(codeload 路徑需完全一致)。*/
|
* 注意:repo 名大小寫敏感(codeload 路徑需完全一致)。*/
|
||||||
@@ -185,10 +186,13 @@ async function applyD1Migration(ctx: DeployContext, sql: string): Promise<void>
|
|||||||
/** 下載 codeload tarball 解壓到暫存目錄,回傳解壓出的 repo root 路徑。*/
|
/** 下載 codeload tarball 解壓到暫存目錄,回傳解壓出的 repo root 路徑。*/
|
||||||
async function downloadRepoTarball(ref: string): Promise<string> {
|
async function downloadRepoTarball(ref: string): Promise<string> {
|
||||||
const url = `https://codeload.github.com/${ARCRUN_REPO}/tar.gz/${ref}`;
|
const url = `https://codeload.github.com/${ARCRUN_REPO}/tar.gz/${ref}`;
|
||||||
|
console.log(chalk.gray(` → 從 GitHub 下載最新版本(${ARCRUN_REPO}@${ref},約 10–30 秒,視網速)...`));
|
||||||
const res = await fetch(url, { signal: AbortSignal.timeout(120_000) });
|
const res = await fetch(url, { signal: AbortSignal.timeout(120_000) });
|
||||||
if (!res.ok) throw new Error(`codeload HTTP ${res.status}(${url})`);
|
if (!res.ok) throw new Error(`codeload HTTP ${res.status}(${url})`);
|
||||||
|
|
||||||
const buf = Buffer.from(await res.arrayBuffer());
|
const buf = Buffer.from(await res.arrayBuffer());
|
||||||
|
const sizeMB = (buf.length / 1024 / 1024).toFixed(1);
|
||||||
|
console.log(chalk.gray(` → 下載完成(${sizeMB} MB),解壓中...`));
|
||||||
const dir = mkdtempSync(join(tmpdir(), 'arcrun-deploy-'));
|
const dir = mkdtempSync(join(tmpdir(), 'arcrun-deploy-'));
|
||||||
const tarPath = join(dir, 'repo.tar.gz');
|
const tarPath = join(dir, 'repo.tar.gz');
|
||||||
writeFileSync(tarPath, buf);
|
writeFileSync(tarPath, buf);
|
||||||
|
|||||||
Reference in New Issue
Block a user