Files
twenty/packages/twenty-docs/l/zh/developers/extend/apps/publishing.mdx
T
github-actions[bot] 6af7e32c54 i18n - docs translations (#19113)
Created by Github action

Co-authored-by: github-actions <github-actions@twenty.com>
2026-03-30 12:45:45 +02:00

250 lines
9.8 KiB
Plaintext
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.
---
title: 发布
description: 将你的 Twenty 应用分发到应用市场,或进行内部部署。
---
<Warning>
应用目前处于 Alpha 测试阶段。 该功能可用,但仍在演进中。
</Warning>
## 概览
一旦你的应用已[在本地构建并完成测试](/l/zh/developers/extend/apps/building),你可以通过两种方式进行分发:
* **发布到 npm** — 将你的应用在 Twenty 应用市场上架,供任何工作区发现并安装。
* **部署 tar 包** — 直接将你的应用上传到特定的 Twenty 服务器,以供内部或私有使用。
两种路径都从同一个**构建**步骤开始。
## 构建你的应用
`build` 命令会编译你的 TypeScript 源码,转译逻辑函数和前端组件,并生成一个描述你应用内容的 `manifest.json`
```bash filename="Terminal"
yarn twenty build
```
输出将写入 `.twenty/output/`。 This directory contains everything needed for distribution: compiled code, assets, the manifest, and a copy of your `package.json`.
To also create a `.tgz` tarball (used by the deploy command internally, or for manual distribution):
```bash filename="Terminal"
yarn twenty build --tarball
```
## 发布到 npm
发布到 npm 可让你的应用在 Twenty 应用市场中被发现。 任何 Twenty 工作区都可以直接通过 UI 浏览、安装和升级应用市场中的应用。
### 要求
* 一个 [npm](https://www.npmjs.com) 账户
* The `twenty-app` keyword **must** be listed in your `package.json` `keywords` array
### Adding the required keyword
The Twenty marketplace discovers apps by searching the npm registry for packages with the `twenty-app` keyword. Add it to your `package.json`:
```json filename="package.json"
{
"name": "twenty-app-postcard-sender",
"version": "1.0.0",
"keywords": ["twenty-app"],
...
}
```
<Note>
The marketplace searches for `keywords:twenty-app` on the npm registry. Without this keyword, your package won't appear in the marketplace even if it has the `twenty-app-` name prefix.
</Note>
### 步骤
1. **Build your app:**
```bash filename="Terminal"
yarn twenty build
```
2. **Publish to npm:**
```bash filename="Terminal"
yarn twenty publish
```
This runs `npm publish` from the `.twenty/output/` directory.
To publish under a specific dist-tag (e.g., `beta` or `next`):
```bash filename="Terminal"
yarn twenty publish --tag beta
```
### How marketplace discovery works
The Twenty server syncs its marketplace catalog from the npm registry **every hour**:
1. It searches for all npm packages with the `keywords:twenty-app` keyword
2. For each package, it fetches the `manifest.json` from the npm CDN
3. The app's metadata (name, description, author, logo, screenshots, category) is extracted from the manifest and displayed in the marketplace
After publishing, your app can take up to one hour to appear in the marketplace. To trigger the sync immediately instead of waiting for the next hourly run:
```bash filename="Terminal"
yarn twenty catalog-sync
```
To target a specific remote:
```bash filename="Terminal"
yarn twenty catalog-sync -r production
```
The metadata shown in the marketplace comes from your `defineApplication()` call in your app source code — fields like `displayName`, `description`, `author`, `category`, `logoUrl`, `screenshots`, `aboutDescription`, `websiteUrl`, and `termsUrl`.
### CI 发布
The scaffolded project includes a GitHub Actions workflow that publishes on every release:
```yaml filename=".github/workflows/publish.yml"
name: Publish
on:
release:
types: [published]
permissions:
contents: read
id-token: write
jobs:
publish:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: "24"
registry-url: https://registry.npmjs.org
- run: yarn install --immutable
- run: npx twenty build
- run: npm publish --provenance --access public
working-directory: .twenty/output
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
```
For other CI systems (GitLab CI, CircleCI, etc.), the same three commands apply: `yarn install`, `yarn twenty build`, then `npm publish` from `.twenty/output`.
<Tip>
**npm provenance** 可选,但建议启用。 使用 `--provenance` 发布会在你的 npm 列表中添加可信徽章,使用户可以验证该包是由公共 CI 流水线中的特定提交构建的。 有关设置说明,请参见 [npm provenance 文档](https://docs.npmjs.com/generating-provenance-statements)。
</Tip>
## Deploying to a server (tarball)
For apps you don't want publicly available — proprietary tools, enterprise-only integrations, or experimental builds — you can deploy a tarball directly to a Twenty server.
### 先决条件
Before deploying, you need a configured remote pointing to the target server. Remotes store the server URL and authentication credentials locally in `~/.twenty/config.json`.
Add a remote:
```bash filename="Terminal"
yarn twenty remote add --url https://your-twenty-server.com --as production
```
For a local development server:
```bash filename="Terminal"
yarn twenty remote add --local --as local
```
You can also authenticate with an API key for non-interactive environments:
```bash filename="Terminal"
yarn twenty remote add --url https://your-twenty-server.com --token <api-key> --as production
```
Manage your remotes:
```bash filename="Terminal"
yarn twenty remote list # List all configured remotes
yarn twenty remote switch prod # Set the default remote
yarn twenty remote status # Show active remote and auth status
yarn twenty remote remove old # Remove a remote
```
### Deploying
Build and upload your app to the server in one step:
```bash filename="Terminal"
yarn twenty deploy
```
This builds the app with `--tarball`, then uploads the tarball to the default remote via a GraphQL multipart upload.
To deploy to a specific remote:
```bash filename="Terminal"
yarn twenty deploy -r production
```
### Sharing a deployed app
Tarball apps are not listed in the public marketplace, so other workspaces on the same server won't discover them by browsing. To share a deployed app:
1. Go to **Settings > Applications > Registrations** and open your app
2. In the **Distribution** tab, click **Copy share link**
3. Share this link with users on other workspaces — it takes them directly to the app's install page
The share link uses the server's base URL (without any workspace subdomain) so it works for any workspace on the server.
### 版本管理
要发布更新:
1. 更新 `package.json` 中的 `version` 字段
2. Run `yarn twenty deploy` (or `yarn twenty deploy -r production`)
3. Workspaces that have the app installed will see the upgrade available in their settings
## Installing apps
Once an app is published (npm) or deployed (tarball), workspaces install it through the UI:
```bash filename="Terminal"
yarn twenty install
```
Or from the **Settings > Applications** page in the Twenty UI, where both marketplace and tarball-deployed apps can be browsed and installed.
## App distribution categories
Twenty 会根据分发方式将应用归为三类:
| 类别 | 工作原理 | 在应用市场中可见? |
| ---------------------- | ---------------------------------------------------------------------------------- | --------- |
| **开发** | 通过 `yarn twenty dev` 运行的本地开发模式应用。 用于构建和测试。 | 否 |
| **Published (npm)** | Apps published to npm with the `twenty-app` keyword. 在应用市场上架,供任何工作区安装。 | 是 |
| **Internal (tarball)** | 通过 tar 包部署到特定服务器的应用。 Available only to workspaces on that server via a share link. | 否 |
<Tip>
在构建你的应用时,从**开发**模式开始。 准备就绪后,选择用于广泛分发的**已发布**(npm),或用于私有部署的**内部**(tar 包)。
</Tip>
## CLI reference
| 命令 | 描述 | Key flags |
| --------------------------- | ---------------------------------------------- | --------------------------------------------------- |
| `yarn twenty build` | Compile app and generate manifest | `--tarball` — also create a `.tgz` package |
| `yarn twenty publish` | Build and publish to npm | `--tag <tag>` — npm dist-tag (e.g., `beta`, `next`) |
| `yarn twenty deploy` | Build and upload tarball to a server | `-r, --remote <name>` — target remote |
| `yarn twenty catalog-sync` | Trigger marketplace catalog sync on the server | `-r, --remote <name>` — target remote |
| `yarn twenty install` | Install a deployed app on a workspace | `-r, --remote <name>` — target remote |
| `yarn twenty dev` | Watch and sync local changes | Uses default remote |
| `yarn twenty remote add` | Add a server connection | `--url`, `--token`, `--as`, `--local`, `--port` |
| `yarn twenty remote list` | List configured remotes | — |
| `yarn twenty remote switch` | Set default remote | — |
| `yarn twenty remote status` | Show connection status | — |
| `yarn twenty remote remove` | Remove a remote | — |