变量参考
AgileBuilder 变量类型完整参考
概述
本文档包含 AgileBuilder 支持的所有变量类型的完整参考。
变量类型
string
字符串变量,用于项目名称、包名、端口等。
{
"name": "projectName",
"type": "string",
"description": "项目名称",
"required": true,
"default": "my-app",
"pattern": "^[a-z][a-z0-9-]*$",
"patternMessage": "项目名称必须以字母开头,只包含小写字母、数字和连字符"
}
| 属性 | 类型 | 说明 |
|---|---|---|
name | string | 变量名,必填 |
type | string | 固定为 "string" |
description | string | 变量描述 |
required | boolean | 是否必填,默认 false |
default | string | 默认值 |
pattern | string | 正则校验规则 |
patternMessage | string | 校验失败提示 |
boolean
布尔变量,用于启用或禁用某些功能。
{
"name": "useTypeScript",
"type": "boolean",
"description": "是否使用 TypeScript",
"default": true
}
| 属性 | 类型 | 说明 |
|---|---|---|
name | string | 变量名,必填 |
type | string | 固定为 "boolean" |
description | string | 变量描述 |
default | boolean | 默认值 |
select
单选变量,从预定义选项中选择一个。
{
"name": "framework",
"type": "select",
"description": "选择前端框架",
"options": ["react", "vue", "svelte"],
"default": "react"
}
| 属性 | 类型 | 说明 |
|---|---|---|
name | string | 变量名,必填 |
type | string | 固定为 "select" |
description | string | 变量描述 |
options | string[] | 选项列表,必填 |
default | string | 默认选项 |
required | boolean | 是否必填,默认 false |
multiselect
多选变量,从预定义选项中选择多个。
{
"name": "features",
"type": "multiselect",
"description": "选择功能模块",
"options": ["eslint", "prettier", "husky", "jest", "cypress"],
"default": ["eslint", "prettier"]
}
| 属性 | 类型 | 说明 |
|---|---|---|
name | string | 变量名,必填 |
type | string | 固定为 "multiselect" |
description | string | 变量描述 |
options | string[] | 选项列表,必填 |
default | string[] | 默认选项列表 |
min | number | 最少选择数量 |
max | number | 最多选择数量 |
JSON Schema
完整的变量定义 JSON Schema:
{
"$schema": "http://json-schema.org/draft-07/schema#",
"type": "object",
"definitions": {
"baseVariable": {
"type": "object",
"properties": {
"name": { "type": "string" },
"description": { "type": "string" },
"required": { "type": "boolean" }
},
"required": ["name"]
},
"stringVariable": {
"allOf": [
{ "$ref": "#/definitions/baseVariable" },
{
"type": "object",
"properties": {
"type": { "const": "string" },
"default": { "type": "string" },
"pattern": { "type": "string" },
"patternMessage": { "type": "string" }
}
}
]
},
"booleanVariable": {
"allOf": [
{ "$ref": "#/definitions/baseVariable" },
{
"type": "object",
"properties": {
"type": { "const": "boolean" },
"default": { "type": "boolean" }
}
}
]
},
"selectVariable": {
"allOf": [
{ "$ref": "#/definitions/baseVariable" },
{
"type": "object",
"properties": {
"type": { "const": "select" },
"options": {
"type": "array",
"items": { "type": "string" }
},
"default": { "type": "string" }
},
"required": ["options"]
}
]
},
"multiselectVariable": {
"allOf": [
{ "$ref": "#/definitions/baseVariable" },
{
"type": "object",
"properties": {
"type": { "const": "multiselect" },
"options": {
"type": "array",
"items": { "type": "string" }
},
"default": {
"type": "array",
"items": { "type": "string" }
},
"min": { "type": "number" },
"max": { "type": "number" }
},
"required": ["options"]
}
]
}
}
}
使用示例
完整配置示例
{
"variables": [
{
"name": "projectName",
"type": "string",
"description": "项目名称(用于目录名、包名)",
"required": true,
"pattern": "^[a-z][a-z0-9-]*$",
"patternMessage": "只能包含小写字母、数字和连字符"
},
{
"name": "framework",
"type": "select",
"description": "选择前端框架",
"options": ["react", "vue", "svelte"],
"default": "react"
},
{
"name": "useTypeScript",
"type": "boolean",
"description": "启用 TypeScript",
"default": true
},
{
"name": "extraFeatures",
"type": "multiselect",
"description": "额外功能",
"options": ["eslint", "prettier", "husky", "jest"],
"default": ["eslint", "prettier"]
}
]
}
下一步
- Handlebars 语法 - 了解如何在模板中使用变量
- 模板制作入门 - 学习创建模板