Skip to main content

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 (fn module): creates an SCF configuration template.
  • Integration initialization (integration module): creates an integration configuration template.

Command Format

tcb config init [module] [options]

Where [module] is an optional parameter indicating the module to initialize:

ModuleDescription
(none)Smart detection of project resources, generating comprehensive configuration
fnInitialize SCF configuration template
integrationInitialize integration configuration template

Parameters (Comprehensive Initialization)

ParameterDescriptionRequired
--no-directorySkip generating directory skeleton (config only)No
-o, --output <output>Output file path, defaults to cloudbaserc.json in the current directoryNo

Parameters (Module Initialization)

ParameterDescriptionRequired
[keyId]Function name for SCF, or keyId for integrationNo (fn module)
--type <type>Integration type (integration module only), e.g., weixinpaydcNo (interactive selection)
-o, --output <output>Output file path, defaults to cloudbaserc.json in the current directoryNo

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 uses inferFunctionConfig to infer each function's runtime (Node.js/Python/PHP, etc.), handler, and type (Event/HTTP). The presence of a scf_bootstrap file is automatically recognized as an HTTP function.
  • Framework Detection: Uses the same detectFramework logic as tcb deploy, identifying Vite/Next.js/Nuxt/Angular/Vue CLI frameworks (via config files like vite.config.js, next.config.js plus package.json dependency 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.json scripts.build for buildCommand.

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, and installCommand.
  • Creates functions/ and web/ directory skeletons by default (--no-directory to skip).
  • Existing files are not overwritten.

SCF Configuration:

  • Generates a function configuration template containing basic fields (name, timeout, runtime, envVariables, etc.)
  • The envVariables field 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, and envVariables
Use Cases
  • 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
How to deploy after configuration?
  • 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 deploy or tcb deploy --only=<module>