Skip to content
| Marketplace
Sign in
Visual Studio Code>Other>hgenNew to Visual Studio Code? Get it now.
hgen

hgen

hezechang

|
14 installs
| (0) | Free
代码生成器
Installation
Launch VS Code Quick Open (Ctrl+P), paste the following command, and press enter.
Copied to clipboard
More Info

通过模板生成代码

配置文件

{
  // 定义模板的根目录,默认为项目根目录下的 _templates 目录
  templates: './templates',

  // 重命名文件名称 默认为:模块名(生成时输入的名称)+模版名(剔除模版后缀ejs.t)+ 文件后缀(.ts)
  rename: (name, templateName) => {
    return name + '.' + templateName.replace('.ejs.t', '.html')
  },
  // 采用prettier格式化代码,不启用则去除该节点配置,配置 参考 https://prettier.io/docs/en/options
  prettier: {
    parser: 'html', // babel、babel-flow、babel-ts、typescript、css、scss、less、html、json ...
    singleQuote: true,
    printWidth: 180,
    tabWidth: 2,
    semi: false,
    trailingComma: 'none'
  },
  // 定义帮助函数,这些函数可以在模板中使用,内置Lodash 与 axios
  helpers: {
    test1(name) {
      return name + 'test1'
    },
    test2(name) {
      return name + 'test2'
    },
    test3(name) {
      return name + 'test3'
    }
  }
}

模板说明

1. 获取生成代码时输入的名称:<%-name%>

2. 模板中可调用的函数
    一、内置 lodash 函数库 https://www.lodashjs.com/docs/lodash.camelCase
    例如:
    1、转驼峰写法 <%-_.camelCase(name)%>
    2、转大写开头 <%-_.capitalize(name)%>
    3、转下划线写法 <%-_.snakeCase(name)%>
    ...

    二、通过 config 配置文件扩展的函数
    例如:
    1、扩展函数调用 <%-this.test1(name)%>
    1、扩展函数调用 <%-this.test2(name)%>
    1、扩展函数调用 <%-this.test3(name)%>
    ...

代码仓库

  1. https://gitee.com/money-code/hgen-vscode.git
  • Contact us
  • Jobs
  • Privacy
  • Manage cookies
  • Terms of use
  • Trademarks
© 2025 Microsoft