gencode-cli

1.0.1 • Public • Published

gencode-cli

这是一个前端代码生成工具

Build Setup

# 克隆项目
git clone xxx

# 进入项目目录
cd gencode-cli

# 安装依赖
npm install

# 建议不要直接使用 cnpm 安装以来,会有各种诡异的 bug。可以通过如下操作解决 npm 下载速度慢的问题
npm install --registry=https://registry.npm.taobao.org

# 全局安装(类似npm install -g gencode-cli),不过使用的是本地库 链接命令 gencode
npm link

模型数据样例

{
    "moduleName": "dev",
    "tableName": "dev_single_table",
    "tableCamelName": "singleTable",
    "className": "SingleTable",
    "remark": "单表",
    "columns": [
        {
            "fieldName": "id",
            "fieldCamelName": "id",
            "dataType": "Long",
            "fieldSize": 20,
            "remark": "主键",
            "isPrimary": 1,
            "listHide": 1,
            "nullable": 0,
            "component": "None"
        },
        {
            "fieldName": "name",
            "fieldCamelName": "name",
            "dataType": "String",
            "fieldSize": 64,
            "remark": "名称",
            "isPrimary": 0,
            "nullable": 0,
            "component": "Input",
            "search": 1,
            "searchType": "LIKE"
        },
        {
            "fieldName": "dict_type",
            "fieldCamelName": "dictType",
            "dataType": "Integer",
            "fieldSize": 11,
            "remark": "字段类型",
            "isPrimary": 0,
            "nullable": 0,
            "component": "Dict",
            "componentProps": {
                "code": "dev_single_table_dict_type"
            }
        }
    ]
}

关于代码生成器

运行说明

全局安装后,可以任意目录中使用

查看帮助

覆盖所有文件

gencode -t biz_demo -co 1

覆盖数据文件

gencode -t biz_demo -data 1

gencode -h
Usage: index [options] [command]

Options:
  -V, --version                output the version number
  -t, --tableName <type>       数据文件
  -d, --debug <type>           开启调试模式 (default: 1)
  -c, --config <type>          配置文件 (default: "config.json")
  -co, --covered <type>        是否全部覆盖(1->覆盖,0->不覆盖) (default: 0)
  -data, --coveredData <type>  覆盖data源数据,不覆盖模板页面(1->覆盖,0->不覆盖) (default: 0)
  -a, --action <type>          操作类型(gen->生成代码,sync->同步数据库元数据) (default: "gen")
  -h, --help                   display help for command

初始化(在前端任意工程)

gencode init

指定某个元数据生成代码

gencode -t sys_role

指定某个元数据生成代码-覆盖式

gencode -t sys_role -co 1

指定某个元数据生成代码-覆盖data源数据,不覆盖模板页面

gencode -t sys_role -data 1

同步本地数据库元数据到平台

gencode -t sys_role -a sync

模板语法

输出

标准语法
<{value}>
<{data.key}>
<{data['key']}>
<{a ? b : c}>
<{a || b}>
<{a + b}>
原始语法
<%= value %>
<%= data.key %>
<%= data['key'] %>
<%= a ? b : c %>
<%= a || b %>
<%= a + b %>

原文输出,不转义

标准语法
<{@ value }>
原始语法
<%- value %>

条件

标准语法
<{if value}> ... <{/if}>
<{if value}> ... <{else}> ... <{/if}>
<{if v1}> ... <{else if v2}> ... <{/if>}
<{if v1}> ... <{else if v2}> ... <{else}> ... <{/if}>
原始语法
<% if (value) { %> ... <% } %>
<% if (value) { %> ... <% } else { %>... <% } %>
<% if (v1) { %> ... <% } else if (v2) { %> ... <% } %>
<% if (v1) { %> ... <% } else if (v2) { %> ... <% }  else { %>... <% } %>

循环

标准语法
隐式定义,默认$value/$index
<{each target}>
    <{$index}> <{$value}>
<{/each}>
显示定义
<{each target val index}>
    <{index}> <{val>}>
<{/each}>
原始语法
<% for(var i = 0; i < target.length; i++){ %>
    <%= i %> <%= target[i] %>
<% } %>

变量

标准语法
<{set temp = data.sub.content}>
原始语法
<% var temp = data.sub.content; %>

Package Sidebar

Install

npm i gencode-cli

Weekly Downloads

0

Version

1.0.1

License

MIT

Unpacked Size

20.7 kB

Total Files

7

Last publish

Collaborators

  • mldong