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

@yuanjinlin/gen-api

v1.0.4

Published

轻量化简易一键生成在线文档api接口,告别人力的copy

Downloads

11

Readme

gen-api

NPM Version Node Current NPM License

介绍

gen-api是一个代码生成工具,基于 puppeteerjs开发, 可以拉取在线API接口并生成js本地代码接口函数

环境要求

首先得有 Node.js,并确保其版本 >= 14.15.0。

在线API网站文档的支持:

安装

选择你常用的包管理器将 gen-api 加入项目依赖即可:


# npm
npm i gen-api

# yarn
yarn add gen-api

# pnpm
pnpm add gen-api

使用

1.使用以下命令初始化配置文件你的项目根目录会生成一个文件名为api.config.js配置文件

// 初始化一个配置文件
npx gen-api init

// 创建axios的文件
npx gen-api init --axios filePath

2.使用以下命令运行gen-api:运行该命令生成完接口之后你的项目根目录会创建一个名为api.data.json的缓存文件

npx gen-api

3.使用以下命令自定义你的配置文件,gen-api 是从你的项目根目录查找你的配置文件:

npx gen-api --c filaPath

4.使用以下命令运行你的自定义配置文件

npx gen-api --p filaPath

api.config.js 配置项

users

  • 类型:object

  • 默认值: 无

  • 必填:是

  • 说明:

    配置在线文档网站登录账户信息

     users: {
        userName: "xxx",
        passWord: "xxx",
      },
    

genApiName

  • 类型:string

  • 默认值:yapi

  • 必填:是

  • 说明:

    需要生成在线文档的网站名称

domain

  • 类型:string

  • 默认值:http://api.doc.jiyou-tech.com

  • 必填:是

  • 说明:

    生成在线文档网站域名

apiFilePath

  • 类型:string

  • 默认值: api

  • 必填:

  • 说明:

    需要生成到接口函数的文件夹

getRequestFunctionName

  • 类型:function

  • 默认值: 无

  • 必填:

  • 说明:

    定义生成的接口函数名

    
    getRequestFunctionName(apiName:string,apiInfo:object<any>,toCamelCase:() => string):string {
      return xxx+apiName
    }
    

importRequestName

  • 类型:string

  • 默认值:"import ajax from '@/utils/request'"

  • 必填:是

  • 说明:

    导入请求函数

requestOpt

  • 类型:object

  • 默认值:

  • 必填:是

  • 说明:

    请求函数配置

    {
     // 函数入参参数 可以函数配置
      paramsName:'',
     // 注释
      annotation:Function,
     // 自定义的请求函数
      requestFunc:
    }
    
    paramsName
    • 类型:string | function

    • 默认值:data

    • 必填:

    • 说明: 请求函数的入参模板

          paramsName(apiInfo:object<any>):string {
      
          }
      
    annotation
    • 类型:function

    • 默认值:

      @项目名称:
      
      @菜单名称:
    • 必填:

    • 说明: 接口函数注释模板

          annotation(apiInfo:object<any>):string {
              return
              `
              @xxx:
              @xxx:
              `
          }
      
    requestFunc
    • 类型:string|function

    • 默认值:

    • 必填:

    • 说明:

      自定义请求函数模板

         requestFunc(apiInfo:object<any>):string {
             return `ajax.get()`
         }
      

projects

  • 类型:array<object | number>

  • 默认值:

  • 必填:是

  • 说明:

    api文档项目配置项,projects如果是一个number数组类型的值,请传当前项目的项目id,将会生成当前项目下的所有接口,如果你想生成某个分类下的接口项,需要传数组对象配置好项目id和分类id即可生成你当前项目某个分类的接口

    catIds

    • 类型:array

    • 默认值:

    • 必填:是

    • 说明:

      分类ID,可以设置多个

    projectId

    • 类型:number

    • 默认值:

    • 必填:是

    • 说明:

      项目的唯一标识。支持多个项目

获取方式:打开项目 -> 点开分类 -> 获取projectId 复制浏览器地址栏project/后面的数字 分类ID获取 复制/api/cat_ 后面的数字。

yapi示例:

yapi

变更日志:

每个版本的详细变更记录在发行说明中。 发行说明

提问:

  • 使用明确、具体的标题描述问题。
  • 提供问题的详细描述,包括重现步骤、预期行为和实际行为。
  • 如果可能,附加屏幕截图或动画来说明问题。

贡献代码:

  • Fork项目到你的GitHub账户。
  • 编写代码时每个类需要继承Generator这个类,在项目src下core文件里面编写你的代码,文件名请和网站的名称一致,src/index.js 引入你的核心代码
  • 在本地开发和测试你的代码。
  • 提交Pull Request。

联系信息

如果你有任何问题或建议,请随时通过我的电子邮件([email protected])与我联系