配置文件完整说明
在项目首次生成代码时, 会生成 niuhe/.config.json5
配置文件, 配置文件内包含了常用的配置项, 少部分个性化的配置项并没有包含其中。这里介绍完整配置项和配置项目说明
配置项 | 类型 | 默认值 | 说明 |
---|---|---|---|
app | string | "" | 应用名, 定时时将覆盖 #app=xxx 定义的值。 示例值: "admin" |
gomod | string | "" | 为空或未定义时同 app , 也可定义为其他名字, 如在 admin-core 项目中为 github.com/ma-guo/admin-core |
langs | string[] | [] | 语言类型, "go" 内定支持, 这里支持 "ts" ,"docs" ,"route" ,"protocol" , "vite" , "openapi" , "template" 。示例值: ["ts", "docs"] 。 参考插件支持的语言 |
tstypes | string[] | ["./typings/types.d.ts"] | 已废弃, langs 中支持 "ts" 时有效, 为生成的 ts 接口文件路径, 可定义多个, 如: tstypes:["full_types_path1", relative_types_path2"], 支持绝对路径和相对路径 |
tsapi | string[] | ["./typings/api.ts"] | 已废弃, langs 中支持 "ts" 时有效, 为生成的 ts 接口文件路径, 可定义多个, 如: tsapi:`["full_api_path1", relative_api_path2"], 支持绝对路径和相对路径 |
typescript | TsConfig[] | [] | langs 中支持 ts 时有效, ts生成相关的配置文件, 参考生成 typescript api 定义 |
typescript.app | string | "admin" | ts中的 namespace 名字, 不定义时同应用名, 在需要将 namespcace 定义为其他值时使用。示例值: "admin" |
typescript.modes | string[] | [] | 限定生成的 ts 中包含的 mode, 在大型项目中需要选择性生成最小化相关代码时使用。 示例值: ["api"] |
typescript.types | string[] | [./typings/types.d.ts] | 生成的 ts 接口文件路径, 可定义多个, 如: types:["full_types_path1", "relative_types_path2"], 支持绝对路径和相对路径 |
typescript.api | string[] | ["./typings/api.ts"] | 生成的 ts 接口文件路径, 可定义多个, 如: api:["full_api_path1", "relative_api_path2"], 支持绝对路径和相对路径 |
typescript.enumjs | string[] | [] | 生成的 js 枚举信息 文件路径, 可定义多个, 如: api:["full_enums_path1", "relative_enum2_path2"], 支持绝对路径和相对路径 |
typescript.tsenum | bool | false | niuhe中定义的字段 type 为 Enum/StringEnum 时在 types 中是生成为对应的 group 定义, 为 false 时转换为 int/string ,示例值:false |
typescript.optional | bool | false | niuhe中定义的字段 label 为 optional 时在 types 中是否要添加 ?,示例值:false |
vite | ViteConfig[] | [] | langs 中支持 vite 时有效, 前端页面生成相关的配置文件, 建议保持同 typescript 中同名配置保持一致。 参考 xorm 代码生成 |
vite.app | string | "" | ts代码中的引用的 namespace 名字, 不定义时同应用名。 建议同 typescript.app 保持一致。示例值:"admin" |
vite.tsenum | bool | false niuhe中定义的字段 type 为 Enum/StringEnum 时在 types 中是生成为对应的 group 定义, 为 false 时转换为 int/string | |
showlog | bool | false | 生成代码时是否生成日志, 打开时,日志在项目目录下 niuhe.log 中, 生成错误时可进行排查,示例值:"false" |
endcmd | string[] | [] | 生成代码后执行的命令, 默认为空, 一般第一个为命令名, 后续为参数, 如: go mod tidy 则定义为 ["go","mod","tidy"] |
fire | bool | false | 烟花效果,示例值:false |
templates | TplConfig[] | [] | langs 中支持template 时有效,使用模板方式生成其他语言时自定义配置, 参考 用 template 生成其他语言协议 |
templates.type | string | "" | 可选值为"message" ,"enum" 和"route" , 分别对应消息,枚举和 api。示例值:"message" |
templates.modes | string[] | [] | 限定生成的模板中包含的 mode , 在大型项目中需要选择性生成最小化相关代码时使用。示例值:["api"] |
templates.template | string | "" | 模板文件地址, 支持绝对和相对路径。示例值:"./templates/kt_enum.tpl" |
templates.output | string | "" | 模板生成代码后的保存地址, 支持绝对和相对路径。示例值:"./output/Enums.kt" |
escape | bool | false | 生成 templates 时是否转义, 默认不转义,示例值:false |
timer | bool | false | 打印本次生成代码各部分耗时日志, showlog 为 true 时打印在日志最后, 同时可在 帮助 ->切换开发人员工具 ->控制台 中查看。示例值:false |
viewprefix | string | "" | 生成的文件前缀, 同一个 view 会生成 ${view}_views.go 和 gen_${view}_views.go 两个文件, 存在多个 view 时会排序杂乱, 统一添加前缀便于将${view}_views.go 同gen_* 文件分离出来。特别地, 当 viewprefix 为 true /"true" 时, 其值同 mode |
配置项定义
// 生成 typescript 相关配置
interface TsConfig {
app: string
modes: string[]
types: string[]
api: string[]
/** 枚举的 js 文件名 */
enumjs: string[]
tsenum: boolean
optional: boolean
}
// 通过 .model.niuhe 生成前端代码配置
interface ViteConfig {
app: string
/** field 为 enum 的是否需要转换类型 */
tsenum: boolean
}
// templates 相关配置
interface TplConfig {
/** 模板类型, 可选为 message, enum, route */
type: 'message' | 'enum' | 'route'
modes: string[]
/** template 文件地址 */
template: string
/** 存放的目标地址 */
output: string
// 配置文件定义
interface EntryInfo {
/** 项目名, 定义时覆盖: `#app=admin` */
app: string //
/** go module 名字, 默认同 app 保持一直 */
gomod: string
/** 支持的语言, 默认支持 `go`, 可选为 `ts`, `docs`, `openapi`, `route`, 'protocol', 'vite, 以 逗号分割 */
langs: string[] //
/** @deprecated ts types.d.ts 自定义的地址 */
tstypes: string[]
/** @deprecated ts api.ts 自定义的地址 */
tsapi: string[]
typescript: TsConfig[]
vite: ViteConfig
/** 是否支持生成日志, 默认为 false */
showlog: boolean
/** 结束后执行的命令, 可选 */
endcmd: string[]
/** 是否显示烟花效果 */
fire?: boolean
/** render 模板 */
templates?: TplConfig[]
/** 生成 template 时是否转义, 默认不转义 */
escape?: boolean
/** 打印耗时 */
timer?: boolean
/** ${view}_views.go 文件前缀 */
viewprefix?: string
}