Skip to content

deploy-pages

将本地目录部署到 OA Pages 静态网站托管平台。

引入

ts
import { deployPages } from 't-comm';

// 不支持 tree-shaking 的项目
import { deployPages } from 't-comm/lib/deploy-pages';

CLI 用法

bash
npx t-comm deploy:pages <cname> <directory> [options]

参数

参数说明
cname域名,如 t-comm.pages.woa.com 或简写 t-comm
directory要部署的本地目录路径

选项

选项说明
-k, --api-key <key>OA Pages API Key(不传则从环境变量 OA_PAGES_API_KEY 获取)
-v, --visibility <type>访问权限:public(免登录)| tof(需登录)| whitelist(白名单)
-d, --description <text>网站描述(最多 100 个字)
--dry-run仅预览,不实际上传

示例

bash
# 基本部署
npx t-comm deploy:pages t-comm.pages.woa.com docs/.vitepress/dist --visibility public

# 简写域名(自动补全为 my-site.pages.woa.com)
npx t-comm deploy:pages my-site ./dist

# 传入 API Key
npx t-comm deploy:pages my-site ./dist --api-key oa-pages-key-xxx

# 预览模式
npx t-comm deploy:pages my-site ./dist --dry-run

编程调用

deployPages(options)

描述:部署本地目录到 OA Pages

参数

参数名类型必填说明
options.cnamestring域名,如 t-comm.pages.woa.com 或简写 t-comm
options.directorystring要部署的本地目录路径
options.apiKeystringAPI Key,不传则从环境变量 OA_PAGES_API_KEY 获取
options.visibility'public' | 'tof' | 'whitelist'访问权限
options.descriptionstring网站描述(最多 100 个字)
options.dryRunboolean仅预览,不实际上传

返回值Promise<DeployPagesResult>

字段类型说明
successboolean是否成功
urlstring网站 URL
adminUrlstring管理页面 URL
cnamestring完整域名
totalFilesnumber文件总数
totalBatchesnumber批次数
errorstring错误信息(失败时)

示例

ts
import { deployPages } from 't-comm';

// 基本用法
const result = await deployPages({
  cname: 't-comm.pages.woa.com',
  directory: 'docs/.vitepress/dist',
  visibility: 'public',
});

console.log(result.url); // https://novlan1.github.io/docs/t-comm

// 传入 API Key(不依赖环境变量)
const result2 = await deployPages({
  cname: 't-comm',
  directory: './dist',
  apiKey: 'oa-pages-key-xxxxxxxx',
  visibility: 'tof',
  description: '我的网站',
});

环境变量

变量名说明
OA_PAGES_API_KEYOA Pages API Key,从 管理后台 获取

注意事项

  1. API Key 获取方式:访问 https://pages.woa.com/admin 申请
  2. 域名支持简写,如 t-comm 会自动补全为 t-comm.pages.woa.com
  3. 文件上传自动分批(每批不超过 4MB),支持大型项目部署
  4. 二进制文件(图片、字体、视频等)会自动进行 base64 编码
  5. 如果网站已存在则更新文件,不存在则自动创建