# Deployment Guide

This guide covers the canonical Cloudflare Pages deployment for `word-editor`.

## Canonical Deployment

```text
Product: word-editor
Cloudflare Pages project: docx-editor
Production origin: https://docx-editor.pages.dev
Output directory: cloudflare-pages-dist
Cloudflare production branch: main
Git source branch: master
```

## Build Pipeline

```bash
npm install
npm run license:issue-root
npm run build:cloudflare
```

`npm run build:cloudflare` performs these steps:

1. Rebuilds `packages/word-editor/dist`.
2. Copies only runtime files into `cloudflare-pages-dist`.
3. Copies the root-signed runtime license and WASM gate.
4. Writes `_headers`, `_redirects`, and `word-editor-release.json`.
5. Minifies and mangles JavaScript with Terser.
6. Excludes source maps, TypeScript source files, and `.d.ts` files from the Pages artifact.

## Deploy

Create the Pages project once if it does not exist:

```bash
npm --userconfig=/dev/null exec --yes --package=wrangler@4.101.0 -- \
  wrangler pages project create docx-editor --production-branch master
```

Deploy:

```bash
npm run deploy:cloudflare
```

## Post-Deploy Verification

```bash
curl -I -L https://docx-editor.pages.dev/
curl -I https://docx-editor.pages.dev/wasm/office-parser-core.wasm
curl -sS https://docx-editor.pages.dev/word-editor-release.json
```

Expected checks:

- `/` redirects to `/examples/demo/`.
- `office-parser-core.wasm` returns `Content-Type: application/wasm`.
- `word-editor-release.json` reports `deployOrigin: https://docx-editor.pages.dev`.
- `sourceMapsPublished` is `false`.
- `sourceTypeDeclarationsPublished` is `false`.
- `javascriptObfuscation` is enabled.

## Local Release Smoke Test

```bash
npm run build:cloudflare
cd cloudflare-pages-dist
python3 -m http.server 8788
```

Open:

```text
http://127.0.0.1:8788/examples/demo/?fontGateway=0&docx=../../test-fixtures/docx/simple.docx&demoToast=1
```

The runtime license allows `127.0.0.1:*` and `localhost:*` for local verification.

---

# 部署指南

本文档说明 `word-editor` 的标准 Cloudflare Pages 部署。

## 标准部署信息

```text
产品名：word-editor
Cloudflare Pages 项目：docx-editor
生产域名：https://docx-editor.pages.dev
输出目录：cloudflare-pages-dist
Cloudflare 生产分支：main
Git 源码分支：master
```

## 构建流程

```bash
npm install
npm run license:issue-root
npm run build:cloudflare
```

`npm run build:cloudflare` 会执行：

1. 重建 `packages/word-editor/dist`。
2. 只复制运行所需文件到 `cloudflare-pages-dist`。
3. 复制根签发运行授权和 WASM 门禁。
4. 写入 `_headers`、`_redirects` 和 `word-editor-release.json`。
5. 使用 Terser 压缩混淆 JavaScript。
6. 发布目录不包含 source map、TypeScript 源码或 `.d.ts` 文件。

## 发布

如果 Pages 项目不存在，先创建一次：

```bash
npm --userconfig=/dev/null exec --yes --package=wrangler@4.101.0 -- \
  wrangler pages project create docx-editor --production-branch master
```

发布：

```bash
npm run deploy:cloudflare
```

## 发布后验证

```bash
curl -I -L https://docx-editor.pages.dev/
curl -I https://docx-editor.pages.dev/wasm/office-parser-core.wasm
curl -sS https://docx-editor.pages.dev/word-editor-release.json
```

预期：

- `/` 跳转到 `/examples/demo/`。
- `office-parser-core.wasm` 返回 `Content-Type: application/wasm`。
- `word-editor-release.json` 中 `deployOrigin` 为 `https://docx-editor.pages.dev`。
- `sourceMapsPublished` 为 `false`。
- `sourceTypeDeclarationsPublished` 为 `false`。
- `javascriptObfuscation` 已启用。

## 本地发布包烟测

```bash
npm run build:cloudflare
cd cloudflare-pages-dist
python3 -m http.server 8788
```

打开：

```text
http://127.0.0.1:8788/examples/demo/?fontGateway=0&docx=../../test-fixtures/docx/simple.docx&demoToast=1
```

运行授权包含 `127.0.0.1:*` 和 `localhost:*`，可用于本地验证。
