npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

gencode-cli

v1.0.1

Published

代码生成cli

Downloads

14

Readme

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; %>