Giter Site home page Giter Site logo

yapi-to-config's Introduction

yapi-to-config

利用 yapi 提供的接口,生成一份 .js 导出一个数组。

这样做的目的是:通用性。

uni-appjs 等项目都可以使用导出的对象,再处理。

export default [
  /**
   * ==================================================
   *  公共分类
   *  公共分类
   * ==================================================
   */

  // 定位保存
  // doc: http://192.168.2.18:3000/project/141/interface/api/13715
  {
    funcName: "location_saveGpsLocation",
    method: "POST",
    url: "/v1/location/saveGpsLocation",
  }
]

安装

使用 npm:

$ npm install -D yapi-to-config

使用 yarn:

$ yarn add -D yapi-to-config

更新:

$ yarn upgrade yapi-to-config --latest

配置

// package.json
{
    // ...,
    "yapi": {
        // 必填:yapi 服务器地址
        "host": "YAPI_HOST",
        // 必填:yapi 接口 token
        "token": "YAPI_TOKEN",

        // 直接使用数据文件。如果有该字段,会直接使用, 不再请求 yapi 接口。
        // 数据文件地址, 相对于 package.json
        "localFilePath": "",

  		// 相对于 package.json,默认生成到 pkg 同级目录下
        "outputDir": "./",
        // 默认文件名
        "fileName": "apiConfig"
    }
}

跑命令

$ yarn yapi

or

$ npm run yapi

TODO

  • 单元测试——jest
  • 增加 ts 智能提示
  • 现在我的做法是导出数组,再循环一一适配好 http 后导出。 这样会有一个问题:适配 http 的部分是运行时执行的。
    • 适配 http 的部分改成动态适配
    • 配置导出成 JSON , 函数名做 key
    • 缺点: 函数名只能当成参数传入

更新日志

v2.3.0

v2.2.1

  • 支持根据本地文件生成, 目录结构暂时仅支持类似 /mock/listMenu.json

  • 增加示例

  • 现在路径指向都以 package.json 为基准

v2.0.0

为了减少约束,甚至在没有约束下,避免命名冲突。

所以,平铺了所有接口,拼接了域名下第二(可配置)个起的所有单词。

yapi-to-config's People

Contributors

lcysgsg avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.