oms/frontend/scripts/init-config.mjs
liufumingren 441659d303 feat(frontend): 新增蓝绿发布脚本与生产 API 地址
发布:
- 新增 scripts/deploy.mjs、rollback.mjs、init-config.mjs 与 scripts/remote/{deploy,rollback}.sh
  · 服务器上按 releases/<版本号> 存放,current 软链原子切换,发布/回滚都不中断服务
  · 切换前校验 index.html 与引用的 /assets 资源完整,并补齐历史版本静态资源(旧 chunk 不 404)
  · 真实配置 scripts/deploy.config.json 已加入忽略清单,模板 deploy.config.example.json 入库
- package.json 增加 deploy / rollback / deploy:init

接口地址:
- 新增 .env.production(VITE_API_BASE_URL=https://api.oms.gztbyc.com/api)与 .env.development
  (/api,继续走 vite 代理到本地 6090)
- request.ts 的 baseURL 改为读 VITE_API_BASE_URL;env.d.ts 声明 ImportMetaEnv
- 新增 utils/media.ts#mediaUrl:跨域部署时把后端返回的相对地址(/api/files/raw/…)
  补全为 API 站点绝对地址,用于 ImageUploader、商品列表图片、主体账号头像渲染

工程:
- tsconfig 去掉已弃用的 baseUrl(TS 7 将移除;paths 自 TS 4.1 起不再依赖它)
- .gitignore 增加 dist.tar.gz 与真实部署配置
2026-09-14 22:14:27 +08:00

25 lines
1.0 KiB
JavaScript
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

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
/**
* 初始化部署配置:把 scripts/deploy.config.example.json 复制为 scripts/deploy.config.json。
* deploy.config.json 含服务器/密钥信息,已被 .gitignore 排除,不要提交。
*
* 用法:npm run deploy:init
*/
import { copyFileSync, existsSync } from 'node:fs';
import path from 'node:path';
import { fileURLToPath } from 'node:url';
const __dirname = path.dirname(fileURLToPath(import.meta.url));
const EXAMPLE_PATH = path.join(__dirname, 'deploy.config.example.json');
const CONFIG_PATH = path.join(__dirname, 'deploy.config.json');
if (existsSync(CONFIG_PATH)) {
console.log('ℹ️ scripts/deploy.config.json 已存在,未覆盖。');
console.log(` 如需重新生成,请先删除该文件:${CONFIG_PATH}`);
process.exit(0);
}
copyFileSync(EXAMPLE_PATH, CONFIG_PATH);
console.log('✅ 已生成 scripts/deploy.config.json');
console.log(' 请按实际服务器信息修改其中的 user / ip / basePath / siteHost / sshKey,然后再执行 npm run deploy。');