[ PROMPT_NODE_24016 ]
C3 API 参考
[ SKILL_DOCUMENTATION ]
# C3 CLI 参考
## 调用方式
bash
npm create cloudflare@latest [name] [-- flags] # NPM 需要 --
yarn create cloudflare [name] [flags]
pnpm create cloudflare@latest [name] [-- flags]
## 核心标志
| 标志 | 值 | 描述 |
|------|--------|-------------|
| `--type` | `hello-world`, `web-app`, `demo`, `pre-existing`, `remote-template` | 应用类型 |
| `--platform` | `workers` (默认), `pages` | 目标平台 |
| `--framework` | `next`, `remix`, `astro`, `react-router`, `solid`, `svelte`, `qwik`, `vue`, `angular`, `hono` | Web 框架 (需要 `--type=web-app`) |
| `--lang` | `ts`, `js`, `python` | 语言 (用于 `--type=hello-world`) |
| `--ts` / `--no-ts` | - | Web 应用的 TypeScript 设置 |
## 部署标志
| 标志 | 描述 |
|------|-------------|
| `--deploy` / `--no-deploy` | 立即部署(交互式提示,CI 中跳过) |
| `--git` / `--no-git` | 初始化 git (默认: yes) |
| `--open` | 部署后打开浏览器 |
## 高级标志
| 标志 | 描述 |
|------|-------------|
| `--template=user/repo` | GitHub 模板或本地路径 |
| `--existing-script=./src/worker.ts` | 现有脚本 (需要 `--type=pre-existing`) |
| `--category=ai|database|realtime` | 演示过滤 (需要 `--type=demo`) |
| `--experimental` | 启用实验性功能 |
| `--wrangler-defaults` | 跳过 wrangler 提示 |
## 环境变量
bash
CLOUDFLARE_API_TOKEN=xxx # 用于部署
CLOUDFLARE_ACCOUNT_ID=xxx # 账户 ID
CF_TELEMETRY_DISABLED=1 # 禁用遥测 |
## 退出代码
`0` 成功, `1` 用户中止, `2` 错误
## 示例
bash
# TypeScript Worker
npm create cloudflare@latest my-api -- --type=hello-world --lang=ts --no-deploy
# Next.js on Pages
npm create cloudflare@latest my-app -- --type=web-app --framework=next --platform=pages --ts
# Astro 博客
npm create cloudflare@latest my-blog -- --type=web-app --framework=astro --ts --deploy
# CI: 非交互式
npm create cloudflare@latest my-app -- --type=web-app --framework=next --ts --no-git --no-deploy
# GitHub 模板
npm create cloudflare@latest -- --template=cloudflare/templates/worker-openapi
# 转换现有项目
npm create cloudflare@latest . -- --type=pre-existing --existing-script=./build/worker.js