Files
Arcrun/console-ui/scripts/deploy.mjs
T
uncle6me-web ad367e450d console-ui: 修好壞了一個月的 build + 具名部署目標(個人版/企業版)
🔴 根因:5a16484 把 UI 搬 CF Pages 時「移出 → console-ui/」實際上只搬了
build 產物(HTML),三支 renderer 原始檔被刪且沒搬 →
`npm run build` 從那天起 ENOENT 死掉,線上 HTML 是刪檔前烤好的,
一個月來無法重建(CONSOLE_PROFILE 改了也不會生效,因為 build 跑不起來)。

修法:
- 從 git 撈回 console.ts(1623)/portal-ui.ts(1390)/console-dashboard.ts(822)
  放進 console-ui/src/——UI 原始碼跟著 UI 專案走,才是那一刀的原意
- build.mjs 加 resolveSource():本地 src/ 優先,找不到才回退 cypher-executor

新增具名部署目標(deploy.targets.json + scripts/deploy.mjs):
一個目標=帳號+profile+apiBase 綁在一起,解決三次帶漏參數:
- demo 站漏 CONSOLE_PROFILE=rag → 顯示個人版 7 頁駕駛艙(leo「進去是 Mira 介面」的真因)
- 兩站漏 ARCRUN_API_BASE → apiBase 空 → 前端打自己 405 → 登不進去
- 兩帳號都有同名 arcrun-console-ui 專案且 wrangler OAuth 登入在 uncle6
  → 不指定帳號 deploy 會部到 demo 站(差點蓋掉,改用 API token 鎖帳號)

  npm run deploy:personal    → leo21c, profile=full(7頁), apiBase 指 leo21c worker
  npm run deploy:enterprise  → uncle6, profile=rag(4頁落地搜尋), apiBase 指 cypher.arcrun.dev

實測(用戶真的會走的路):
- mira.uncle6.me/console/ 200,VIEWS 7 頁,apiBase 對,CORS ACAO 通
- rag-demo.arcrun.dev 4 頁落地搜尋;登入 OK、搜「藍鯨導航儀」5 筆(未受部署影響)

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-07-22 19:09:29 +08:00

52 lines
2.3 KiB
JavaScript
Raw 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.
/**
* deploy.mjs — 依具名目標部署 console-ui 到 Cloudflare Pages
*
* 用法:npm run deploy:personal / npm run deploy:enterprise
*
* 為什麼不直接用 `wrangler pages deploy`2026-07-22 leo 立,實際踩到才補):
* **兩個帳號都有名為 arcrun-console-ui 的 Pages 專案**
* · leo21c → arcrun-console-ui.pages.dev(個人版 console
* · uncle6 → 綁 rag-demo.arcrun.dev(企業版 demo 站)
* wrangler 若 OAuth 登入在 uncle6`--project-name arcrun-console-ui` 會部到 demo 站上。
* 本腳本強制帶目標的 accountId,並在部署前印出目標,避免部錯帳號。
*
* 同時把 profile/apiBase 綁進目標(deploy.targets.json),不再靠部署者記得帶環境變數——
* 帶漏過三次:demo 站漏 profile=rag 顯示成個人版、兩站漏 apiBase 導致登入 405。
*/
import { readFileSync } from 'node:fs';
import { spawnSync } from 'node:child_process';
import { dirname, join } from 'node:path';
import { fileURLToPath } from 'node:url';
const ROOT = join(dirname(fileURLToPath(import.meta.url)), '..');
const targets = JSON.parse(readFileSync(join(ROOT, 'deploy.targets.json'), 'utf8'));
const names = Object.keys(targets).filter((k) => !k.startsWith('_'));
const name = process.argv[2];
if (!name || !targets[name]) {
console.error(`用法:npm run deploy:<target>\n可用目標:${names.join(' / ')}`);
if (name) console.error(`(收到未知目標:"${name}"`);
process.exit(1);
}
const t = targets[name];
console.log(`\n部署目標:${name}`);
console.log(` 說明 ${t.description}`);
console.log(` 帳號 ${t.accountId}`);
console.log(` 專案 ${t.projectName}`);
console.log(` profile ${t.profile}`);
console.log(` apiBase ${t.apiBase}\n`);
const env = { ...process.env, DEPLOY_TARGET: name, CLOUDFLARE_ACCOUNT_ID: t.accountId };
const build = spawnSync('node', [join(ROOT, 'scripts', 'build.mjs')], { stdio: 'inherit', env });
if (build.status !== 0) process.exit(build.status ?? 1);
// --commit-dirty:本地部署常有未提交變更,不因此中斷
const deploy = spawnSync(
'npx',
['wrangler', 'pages', 'deploy', 'public', '--project-name', t.projectName, '--commit-dirty=true'],
{ stdio: 'inherit', cwd: ROOT, env },
);
process.exit(deploy.status ?? 1);