> ## Documentation Index
> Fetch the complete documentation index at: https://docs.twenty.com/llms.txt
> Use this file to discover all available pages before exploring further.

# CLI

> yarn twenty 命令可用于执行函数、流式传输日志、管理应用安装以及切换远程。

`yarn twenty` CLI 是与你的所有应用相关内容进行交互的接口。 完整命令列表：

| 命令                                              | 作用                                         | 记录于                                                                                        |
| ----------------------------------------------- | ------------------------------------------ | ------------------------------------------------------------------------------------------ |
| `dev`                                           | 监视源文件并实时同步更改                               | [快速开始](/l/zh/developers/extend/apps/getting-started/quick-start)                           |
| `计划`                                            | 在不应用变更的情况下预览元数据更改                          | [同步与恢复](/l/zh/developers/extend/apps/operations/sync-and-recovery#previewing-changes-plan) |
| `应用`                                            | 在显示计划后应用元数据更改                              | [同步与恢复](/l/zh/developers/extend/apps/operations/sync-and-recovery)                         |
| `dev:build`                                     | 编译应用并生成 API 客户端（使用 `--tarball` 打包为 `.tgz`） | [发布](/l/zh/developers/extend/apps/operations/publishing)                                   |
| `dev:typecheck`                                 | 运行 TypeScript 类型检查                         | [测试](/l/zh/developers/extend/apps/operations/testing)                                      |
| `dev:add`                                       | 搭建一个新的实体脚手架                                | [脚手架](/l/zh/developers/extend/apps/getting-started/scaffolding)                            |
| `dev:generate-client`                           | 重新生成类型化 API 客户端                            | 本页面                                                                                        |
| `dev:function:exec` / `dev:function:logs`       | 执行函数并流式输出其日志                               | 本页面                                                                                        |
| `dev:translations-extract`                      | 将可翻译字符串提取到 `locales/` 目录下的目录文件中            | [翻译](/l/zh/developers/extend/apps/translations/overview)                                   |
| `dev:catalog-sync`                              | 触发一次市场目录同步                                 | [发布](/l/zh/developers/extend/apps/operations/publishing#how-marketplace-discovery-works)   |
| `app:publish` / `app:install` / `app:uninstall` | 发布生命周期                                     | [发布](/l/zh/developers/extend/apps/operations/publishing) 和本页面                              |
| `docker:*`                                      | 管理本地 Twenty 服务器容器                          | [本地服务器](/l/zh/developers/extend/apps/getting-started/local-server)                         |
| `remote:*`                                      | 管理服务器连接                                    | 本页面                                                                                        |

每个命令都接受 `-r, --remote \<name>` 参数，以便针对特定远程目标而不是默认远程。

## 执行函数（`yarn twenty dev:function:exec`）

手动运行逻辑函数，而无需通过 HTTP、定时任务或数据库事件来触发：

```bash filename="Terminal" theme={null}
# Execute by function name
yarn twenty dev:function:exec -n create-new-post-card

# Execute by universalIdentifier
yarn twenty dev:function:exec -u e56d363b-0bdc-4d8a-a393-6f0d1c75bdcf

# Pass a JSON payload
yarn twenty dev:function:exec -n create-new-post-card -p '{"name": "Hello"}'

# Execute the install and uninstall hooks
yarn twenty dev:function:exec --postInstall
yarn twenty dev:function:exec --preInstall
yarn twenty dev:function:exec --uninstall
```

## 查看函数日志（`yarn twenty dev:function:logs`）

实时流式查看你的应用逻辑函数的执行日志：

```bash filename="Terminal" theme={null}
# Stream all function logs
yarn twenty dev:function:logs

# Filter by function name
yarn twenty dev:function:logs -n create-new-post-card

# Filter by universalIdentifier
yarn twenty dev:function:logs -u e56d363b-0bdc-4d8a-a393-6f0d1c75bdcf
```

<Note>
  这与 `yarn twenty docker:logs` 不同，后者显示的是 Docker 容器日志。 `yarn twenty dev:function:logs` 会显示来自 Twenty 服务器的应用函数执行日志。
</Note>

## 生成类型化客户端（`yarn twenty dev:generate-client`）

根据当前远程的 schema 重新生成类型化 API 客户端（`twenty-client-sdk`），无需构建或同步应用。 在任何项目中使用它来获取一个类型化客户端——例如位于单独代码库中的后端服务——用于与您的 Twenty 实例通信：

```bash filename="Terminal" theme={null}
# In your project (no Twenty app definition required)
yarn add twenty-sdk twenty-client-sdk

# Connect to the Twenty instance to generate the client from
yarn twenty remote:add

# Generate the typed client into node_modules/twenty-client-sdk
yarn twenty dev:generate-client
```

然后在代码中导入该客户端：

```typescript theme={null}
import { CoreApiClient } from 'twenty-client-sdk/core';
```

每当数据模型发生更改时，请重新运行该命令，以刷新生成的类型。

<Note>
  客户端是在 `node_modules` 中生成的，因此不会随代码一起提交。 每次安装后运行 `yarn twenty dev:generate-client`（例如在 `postinstall` 脚本或 CI 中）。
</Note>

## 卸载应用（`yarn twenty app:uninstall`）

将你的应用从活动工作区中移除：

```bash filename="Terminal" theme={null}
yarn twenty app:uninstall

# Skip the confirmation prompt
yarn twenty app:uninstall --yes
```

## 管理远程

“远程”是指你的应用连接到的 Twenty 服务器。 在设置期间，脚手架工具会为你自动创建一个。 你可以随时添加更多远程或在它们之间切换。

```bash filename="Terminal" theme={null}
# Add a new remote (opens a browser for OAuth login)
yarn twenty remote:add

# Connect to a local Twenty server (auto-detects port 2020 or 3000)
yarn twenty remote:add --local

# Add a remote non-interactively (useful for CI)
yarn twenty remote:add --url https://your-twenty-server.com --api-key $TWENTY_API_KEY --as my-remote

# List all configured remotes
yarn twenty remote:list

# Set the active remote
yarn twenty remote:use <name>

# Check that the active remote's authentication is still valid
yarn twenty remote:status

# Remove a remote
yarn twenty remote:remove <name>
```

你的凭据存储在 `~/.twenty/config.json` 中。
