0.2.6 • Published 3 years ago

ys-codegen-cli v0.2.6

Weekly downloads
48
License
ISC
Repository
-
Last release
3 years ago

codegen cli

交互式生成代码文件

安装

使用 npm:

$ npm install -D ys-codegen-cli

使用 yarn:

$ yarn add -D ys-codegen-cli

更新:

$ yarn upgrade ys-codegen-cli --latest

使用

  1. 单个文件生成命令
    yarn make create [-c 配置路径]
  2. 一组文件生成命令
    yarn make curd [-c 配置路径]
  3. 修改配置后,重新生成文件命令,调用命令配置文件读取出模板路径、配置路径、输出路径
    yarn make run xxxx.run.json
  4. 配置文件格式转换
    yarn make transConfigFile 文件路径 [-t 格式(json、js)] [-f 输出路径,不含后缀]

配置路径可选,支持.js文件(导出json数据)、支持json文件

在项目package.json配置,如果命令行-c参数有传入则package.json配置不生效

// package.json
{
    // ...,
    "ysCodegenCli":{
        "yApi": { // YApi 的配置
            "token:": "xxxxx",  // YApi项目token
            "baseURL": "http://192.168.2.18:3000/" // YApi 服务地址
        },
        "template": [ // 模板库配置
            {
                "title": "AntDVProEdit", // 模板名称
                "file":  "@/template/AntDVProEdit/EditModal.vue", // 模板路径 @/表示命令行所在目录
                "config": "@/template/AntDVProEdit/default.json", // 配置路径
                "type": "form", // 模板数据类型 用于判断调用不同的回调
                "trans": function(data){ return data} // 回调函数用于转化数据结构 如果没有则不进行转化,如果自定义库的话推荐使用.js写配置文件
                "category": "AntDvProModal", // curd命令行用来分组
                "remark": "唤醒模态框编辑页模板" // 备注
            }
        ],
        "format": "", // 默认调用命令行目录下的.prettierrc文件 json格式
        "configType":"js",
        "script": {
            "lintFile": "vue-cli-service lint {{file}}" // 推荐 速度快
            "format": ""  // 不推荐使用
        }
  }
}

template 参数支持数组,@/_template.js(导出模板数组,@/表示当前命令行路径),/绝对路径/_template.js

"template":"@/_template.js"

_template.js示例

const path = require('path')
const { database } = require('ys-codegen')
const newTpl = [
    {
        'title': 'czw',
        'file': path.resolve(__dirname, 'template/AntDVProList/Index.vue'),
        'config': path.resolve(__dirname, 'template/AntDVProList/default.json'),
        'type': 'index',
        'category': 'AntDvProModal',
        'remark': 'czw'
    }
]
database.push.apply(database, newTpl)

const {
    IndexParams,
    FormParams
} = require('ys-codegen-trans-param')
for (let index = 0; index < database.length; index++) {
    const element = database[index]
    switch (element.type) {
        case 'form':
            database[index].trans = (data) => {
                let config = {}
                if(element.configTpl) {
                    config.tpl = element.configTpl
                }
                return (new FormParams()).trans(data)
            }
            break
        case 'index':
            database[index].trans = (data) => {
                let config = {}
                if(element.configTpl) {
                    config.tpl = element.configTpl
                }
                return (new IndexParams()).trans(data)
            }
            break
    }
}
module.exports = database

依赖

0.2.6

3 years ago

0.2.3

3 years ago

0.2.5

3 years ago

0.2.4

3 years ago

0.2.2

3 years ago

0.2.1

3 years ago

0.1.1

3 years ago

0.0.11

3 years ago

0.0.12

3 years ago

0.0.10

3 years ago

0.0.9

3 years ago

0.0.8

3 years ago

0.0.5

3 years ago

0.0.7

3 years ago

0.0.6

3 years ago

0.0.4

3 years ago

0.0.3

3 years ago

0.0.2

3 years ago

0.0.1

3 years ago