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

ys-codegen-cli

v0.2.6

Published

交互式方式生成代码文件

Downloads

9

Readme

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

依赖