Initialize Configuration
The cloudbaserc.json file is the core configuration file for TCB projects. You can initialize it interactively using the tcb config init command.
tcb config init
The tcb config init command is used to quickly initialize the cloudbaserc.json configuration file. It supports three modes:
- Comprehensive initialization (no module argument): intelligently detects project resources and interactively generates a complete configuration with SCF, static hosting, and gateway.
- SCF initialization (
fnmodule): creates an SCF configuration template. - Integration initialization (
integrationmodule): creates an integration configuration template.
Command Format
tcb config init [module] [options]
Where [module] is an optional parameter indicating the module to initialize:
| Module | Description |
|---|---|
| (none) | Smart detection of project resources, generating comprehensive configuration |
fn | Initialize SCF configuration template |
integration | Initialize integration configuration template |
Parameters (Comprehensive Initialization)
| Parameter | Description | Required |
|---|---|---|
--no-directory | Skip generating directory skeleton (config only) | No |
-o, --output <output> | Output file path, defaults to cloudbaserc.json in the current directory | No |
Parameters (Module Initialization)
| Parameter | Description | Required |
|---|---|---|
[keyId] | Function name for SCF, or keyId for integration | No (fn module) |
--type <type> | Integration type (integration module only), e.g., weixinpaydc | No (interactive selection) |
-o, --output <output> | Output file path, defaults to cloudbaserc.json in the current directory | No |
Smart Detection (No Module Argument)
When running tcb config init without module arguments, the CLI automatically detects existing project resources:
- SCF Detection: Scans the
functions/directory and usesinferFunctionConfigto infer each function's runtime (Node.js/Python/PHP, etc.), handler, and type (Event/HTTP). The presence of ascf_bootstrapfile is automatically recognized as an HTTP function. - Framework Detection: Uses the same
detectFrameworklogic astcb deploy, identifying Vite/Next.js/Nuxt/Angular/Vue CLI frameworks (via config files likevite.config.js,next.config.jspluspackage.jsondependency analysis). - Hosting Detection: Intelligently recognizes directories like
dist/,build/,web/,public/, prioritizing framework output directories. - Auto-fill: Fills in the default environment ID when logged in; detects
package.jsonscripts.buildforbuildCommand.
After detection, a summary is displayed asking the user to confirm generating the configuration based on the results. Upon confirmation, it generates cloudbaserc.json and creates the directory skeleton.
Usage Examples
Comprehensive initialization (recommended):
# Smart detection of project resources, interactively generating full configuration
tcb config init
# Generate config only, skip directory skeleton
tcb config init --no-directory
# Specify output file path
tcb config init -o ./config/cloudbaserc.json
Example generated configuration:
{
"$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"
}
]
}
Initialize SCF configuration:
# Interactively create SCF configuration
tcb config init fn
# Create configuration with specified function name
tcb config init fn myFunc
# Specify output file
tcb config init fn myFunc -o ./config/cloudbaserc.json
Initialize integration configuration:
# Interactively select integration type and create configuration
tcb config init integration
# Specify integration type and keyId
tcb config init integration myPayment --type weixinpaydc
# Specify output file
tcb config init integration myPayment --type weixinpaydc -o ./config/cloudbaserc.json
Initialization Behavior
Comprehensive Initialization:
- After smart detection of functions and frameworks, generates complete configuration with auto-filled
outputDir,buildCommand, andinstallCommand. - Creates
functions/andweb/directory skeletons by default (--no-directoryto skip). - Existing files are not overwritten.
SCF Configuration:
- Generates a function configuration template containing basic fields (name, timeout, runtime, envVariables, etc.)
- The
envVariablesfield will be automatically populated with placeholders based on the integration type, indicating required/optional fields
Integration Configuration:
- Pulls the template field definitions for the integration type from the cloud
- Automatically identifies required and optional fields
- Uses placeholder
******for sensitive fields (e.g., keys, certificates), prompting the user to fill in real values - Generates a complete configuration containing
authTypeCode,name, andenvVariables
- Quick Start: Quickly create standardized configuration files through smart detection or templates
- Configuration Learning: Understand which fields need to be configured for SCF or integrations
- Team Collaboration: Generate standardized configuration templates, team members only need to fill in specific values
- Fine-grained SCF control (single function deployment, code updates, log viewing, trigger management) → Use
tcb fn deploy [name] - Overall deployment (SCF + Static Hosting + Gateway together) → Use
tcb deployortcb deploy --only=<module>