> For the complete documentation index, see [llms.txt](https://docs.decentraland.org/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.decentraland.org/creator/content-creator-zh/chang-jing-sdk7/ru-men/using-the-cli.md).

# 使用 CLI

使用 Decentraland CLI 运行和部署场景。对于大多数创作者来说，Creator Hub 是推荐工具；CLI 更适合高级和自动化工作流。

{% hint style="info" %}
**💡 提示**：如果你正在使用 AI 编码助手（例如 Claude Code、Cursor 或 Copilot），请在它编写任何代码之前安装官方 Decentraland SDK Skills，让它了解经过验证的 SDK7 模式：

```bash
npx skills add decentraland/sdk-skills
```

请参阅 [使用 AI 进行氛围编程](https://docs.decentraland.org/creator/content-creator-zh/chang-jing-sdk7/ru-men/vibe-coding.md) 适用于完整的 AI 辅助工作流。
{% endhint %}

要为 Decentraland 构建场景，您可以使用：

* 该 [创作者中心](https://docs.decentraland.org/creator/content-creator-zh/chang-jing-bian-ji-qi/ru-men/editor-installation.md)
* 命令行界面（CLI）

这两种工具都允许你在“链下”开发环境中编译并预览场景。在本地测试场景后，你可以将内容上传到内容服务器，并将其关联到你的 LAND 或 WORLD。

虽然 Creator Hub 中的场景编辑器更易于使用，但 CLI 为你提供了更大的灵活性，也可以轻松用于自动化流程。

{% hint style="warning" %}
**📔 注意**：场景编辑器在幕后运行的是相同的命令行操作。
{% endhint %}

{% hint style="info" %}
**💡 提示**：请参阅 [安装指南](https://docs.decentraland.org/creator/content-creator-zh/chang-jing-bian-ji-qi/ru-men/editor-installation.md) ，了解如何安装 Creator Hub。
{% endhint %}

## 开始之前

要通过命令行处理场景，请在运行场景的 CLI 命令之前安装以下依赖项：

* [Node.js](https://nodejs.org) （版本 20 或更高版本）

## 初始化新项目

运行 `npx @dcl/sdk-commands init` 在空文件夹中运行此命令，即可将 Decentraland 的默认文件填充到该文件夹中 [场景](https://docs.decentraland.org/creator/content-creator-zh/chang-jing-sdk7/xiang-mu-lei-xing/scene-metadata.md) 项目。你也可以使用 Creator Hub 中的 **新建场景** 按钮创建新场景，该按钮会生成相同的项目结构。

要从其他类型的项目开始，请使用 `--project` 标志。例如，要创建一个 [智能穿戴设备](https://docs.decentraland.org/creator/content-creator-zh/chang-jing-sdk7/xiang-mu-lei-xing/smart-wearables.md) 项目：

```bash
npx @dcl/sdk-commands init --project smart-wearable
```

\--project 的可用选项 `--project` 包括 `scene-template` （默认值）， `px-template`, `smart-wearable`，以及 `library`.

## 更新场景的 SDK 版本

在场景文件夹中运行以下命令：

```bash
npm i @dcl/sdk@latest
```

你可以检查 `package.json` 场景文件，并查找 `@dcl/sdk` 版本。

## 运行预览

在场景、工作区或智能穿戴设备项目的根目录下运行 `npm run start` ，即可在 Decentraland Desktop 客户端中打开预览。

```bash
npm run start
```

如果要改用 [Decentraland 移动应用](https://docs.decentraland.org/creator/content-creator-zh/mian-xiang-yi-dong-duan-gou-jian/yi-dong-ke-hu-duan/overview.md) 预览场景，请运行 `npm run start -- --mobile` （别名为 `-- -m`）。CLI 会输出一个二维码，使用与电脑连接到同一 Wi-Fi 网络的手机扫描即可打开场景。完整指南请参阅 [在移动设备上预览](https://docs.decentraland.org/creator/content-creator-zh/mian-xiang-yi-dong-duan-gou-jian/kai-fa/preview-on-mobile.md) 。

```bash
npm run start -- --mobile
```

Desktop Explorer 会在预览 3D 模型时将其转换为经过优化的资源包，因此模型的显示效果与发布后的效果完全一致。如果要改为加载原始模型，请在独立的 `--lsd-raw-gltf` 命令后添加此参数。请参阅 `--`。 [使用优化资源进行预览](https://docs.decentraland.org/creator/content-creator-zh/chang-jing-sdk7/ru-men/preview-scene.md#preview-with-optimized-assets).

```bash
npx sdk-commands start -- --lsd-raw-gltf
```

有关运行预览的详细信息和特殊选项，请参阅 [预览场景](https://docs.decentraland.org/creator/content-creator-zh/chang-jing-sdk7/ru-men/preview-scene.md) 。

## 构建

运行 `npm run build` 以构建项目。Decentraland 场景使用 TypeScript 编写，但发布时会构建为经过压缩的 JavaScript。更多详情请参阅 [编写场景代码](https://github.com/decentraland/docs/blob/main/creator/sdk7/getting-started/coding-scenes.md) 。

构建命令是可选的，因为部署前也会在后台运行构建（不过，你可以添加一个标志来跳过构建）。

构建命令执行的类型检查比 `npm run start`更严格，因此运行该命令有时有助于调试场景。

## 部署场景

运行 `npm run deploy` 即可将场景发布到 Decentraland。此命令会打开一个浏览器窗口，你可以在其中使用钱包签名以授权部署。

有关发布场景的详细信息和特殊选项，请参阅 [发布](https://docs.decentraland.org/creator/content-creator-zh/chang-jing-sdk7/fa-bu/publishing.md) 。

## 故障排除

如果遇到问题，请参阅 [故障排除](https://docs.decentraland.org/creator/content-creator-zh/chang-jing-sdk7/tiao-shi/troubleshooting.md) 部分。


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://docs.decentraland.org/creator/content-creator-zh/chang-jing-sdk7/ru-men/using-the-cli.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
