跳到主要内容

tcb config init

交互式生成 cloudbaserc.json。不带模块参数时智能检测项目中的云函数、前端框架与静态目录,生成完整配置;带模块参数时只生成该模块的配置模板。

语法​

tcb config init [module] [options]

[module] 为可选参数:

模块说明
(无参数)智能检测项目资源,生成综合配置
fn生成云函数配置模板
integration生成集成配置模板

参数​

综合初始化:

参数必填说明默认值
--no-directory否只写配置,不生成配套目录骨架false
-o, --output <output>否输出文件路径,相对路径以当前目录为基准cloudbaserc.json

模块初始化(fn / integration):

参数必填说明默认值
[keyId]否云函数名(fn)或集成 keyId(integration),不传时交互输入—
--type <type>否集成类型,仅 integration 模块,如 weixinpaydc交互选择
-o, --output <output>否输出文件路径,相对路径以当前目录为基准cloudbaserc.json

示例​

# 智能检测项目资源,交互式生成完整配置
tcb config init

# 只生成配置文件,不创建目录骨架
tcb config init --no-directory

# 指定输出文件路径
tcb config init -o ./config/cloudbaserc.json

# 交互式创建云函数配置
tcb config init fn

# 指定函数名创建配置
tcb config init fn myFunc

# 交互式选择集成类型并创建配置
tcb config init integration

# 指定集成类型和 keyId
tcb config init integration myPayment --type weixinpaydc -o ./config/cloudbaserc.json

生成的配置示例:

{
"$schema": "https://static.cloudbase.net/cli/cloudbaserc.schema.json",
"envId": "env-xxx",
"functionRoot": "./functions",
"functions": [
{
"name": "myPythonFn",
"handler": "main.main",
"runtime": "Python3.11",
"timeout": 3,
"memorySize": 256
}
],
"hosting": [
{
"name": "web",
"root": "web",
"framework": "vite",
"outputDir": "dist",
"buildCommand": "npm run build",
"installCommand": "npm install"
}
]
}

智能检测​

不带模块参数时,CLI 检测项目中的已有资源:

  • 云函数:扫描 functions/ 目录,推测每个函数的运行时、入口函数与类型(Event / HTTP),scf_bootstrap 自动识别为 HTTP 函数
  • 框架:通过 vite.config.js、next.config.js 等配置文件加 package.json 依赖双重检测,识别 Vite、Next.js、Nuxt、Angular、Vue CLI 等
  • 静态目录:识别 dist/、build/、web/、public/ 等,优先匹配框架输出目录
  • 自动填充:已登录时填入默认环境 ID,package.json 的 scripts.build 写入 buildCommand

检测结果先展示摘要供确认,确认后写入配置并创建目录骨架。

初始化行为​

场景行为
综合初始化生成完整配置并填充 outputDir / buildCommand / installCommand;默认创建 functions/、web/ 目录骨架,--no-directory 跳过
云函数配置生成含 name、timeout、runtime、envVariables 等字段的模板
集成配置从云端拉取集成类型的字段定义,识别必填与可选字段;敏感字段用 ****** 占位,需手动填真实值

已存在的文件不会被覆盖。