{"_id":"ywapi2ts","_rev":"906443","name":"ywapi2ts","description":"yapi 输出到前端项目中api ts & js","dist-tags":{"latest":"1.0.1"},"maintainers":[{"name":"venus_jin","email":"bboyking1st@163.com"}],"time":{"modified":"2024-07-24T07:23:38.000Z","created":"2019-04-29T06:42:02.299Z","1.0.1":"2019-04-30T08:50:11.240Z","1.0.0":"2019-04-29T06:42:02.299Z"},"users":{},"author":{"name":"venus_jin"},"versions":{"1.0.1":{"name":"ywapi2ts","version":"1.0.1","description":"yapi 输出到前端项目中api ts & js","main":"client/index.js","module":"client/index.mjs","typing":"client/index.d.ts","author":{"name":"venus_jin"},"bin":{"ywapi2ts":"lib/cli.js"},"license":"MIT","keywords":["ywapi2ts","yapi","typescript","typing"],"scripts":{"lint":"eslint --fix --ext .ts src/","testApi":"ts-node --transpile-only src/cli.ts","testOnly":"jest","test":"jest --coverage","build":"yarn buildCli && yarn buildClient","buildCli":"tsc","buildClient":"bili","release":"yarn lint && yarn build && npm publish","view":"serve -p 9999 src/index.html"},"eslintConfig":{"root":true,"extends":"io"},"eslintIgnore":["lib","client","__snapshots__","api"],"jest":{"transform":{"^.+\\.ts$":"ts-jest"},"collectCoverageFrom":["<rootDir>/src/**/*.ts","!<rootDir>/src/index.ts","!<rootDir>/src/api/**/*"],"testRegex":"(/__tests__/.*|(\\.|/)(test|spec))\\.(jsx?|tsx?)$","moduleFileExtensions":["ts","js","json"]},"devDependencies":{"@types/fs-extra":"^5.0.4","@types/jest":"^23.3.9","@types/json-schema":"^7.0.1","@types/json5":"^0.0.30","@types/mockjs":"^1.0.2","@types/node":"^10.12.10","@types/prompts":"^1.2.0","@types/request-promise-native":"^1.0.15","bili":"^4.7.1","codecov":"^3.1.0","eslint":"^5.9.0","eslint-config-io":"^0.5.0","jest":"^23.6.0","rollup-plugin-typescript2":"^0.20.1","standard-version":"^4.4.0","ts-jest":"^23.10.5","typescript":"^3.3.3333"},"dependencies":{"@types/express":"^4.16.1","@types/open":"^6.1.0","@types/opn":"^5.5.0","anywhere":"^1.5.0","change-case":"^3.0.2","commander":"^2.19.0","consola":"^2.3.0","express":"^4.16.4","fs-extra":"^7.0.1","json-schema-generator":"^2.0.6","json-schema-to-typescript":"^6.1.0","json-ts":"^1.6.4","json5":"^2.1.0","mockjs":"^1.0.1-beta3","open":"^6.2.0","opn":"^6.0.0","ora":"^3.4.0","prompts":"^2.0.4","request":"^2.88.0","request-promise-native":"^1.0.5","ts-node":"^8.0.2","tslib":"^1.9.3","vtils":"^0.76.1","yapi-to-typescript":"^1.4.0"},"gitHead":"ba7e4e14e82407a461b9f2636632b60776dfd764","_id":"ywapi2ts@1.0.1","_npmVersion":"5.6.0","_nodeVersion":"8.11.3","_npmUser":{"name":"venus_jin","email":"bboyking1st@163.com"},"dist":{"integrity":"sha512-wObB3i++9Q4M0YxdQ42grobFKu9wcJpMXOFV1nCaP1eJImw4kkYsymVphGBbdjwoXfXTOLI0hiSbYX0ugwW6zA==","shasum":"941e65cb3dd3dc8baaf227b34498082a3a323922","tarball":"http://registry-npm.ywwl.com/ywapi2ts/download/ywapi2ts-1.0.1.tgz","fileCount":27,"unpackedSize":85361,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.4\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJcyAxDCRA9TVsSAnZWagAAvx4QAJNxSwSj9n+YwjftYGon\nTDHz+DSAg1cI+9uh/+6Tbt/tXL0/3vSpadAgd59N+M+a4LXYgkrPtqExFVSm\n5pF7yF56TkAprJEM7BwV4F1GRJozMh4pGTmHO2HH/kGxzmzbtMjOZPOS6D9H\n/yunshoOfUeJOueaaXWsV4vHMINckcwZ4IXVhtZ0XdqUR87gUgyNk0TntOda\nrPW8NL7lkkIhfZti0izVBxooyL79AiH7AX3cGiNiaxNuYzEfRdSLwbWqUuxa\nZISxNtyMFWx52R8L97ELzemYJLW30GiU4dnEQ5ZvyDospPkgpre4djz+PDHy\n2YQPb3BnlhaQD9l0PZZQDNJemgBUQuuXYB2zGHc9VAc2pURTU3L0peTmCRmS\n8PYFlstCuVl45kVbF/EtKsN6GPfziNXcv0B3agFuch0pPanIvvurY61V4M1f\nf/Wl63DK+gPax99H6kOQUQY7JiKSpFr3fHfrzyjOp5/pCCu942zH4FEZpOjk\nLirez1hqI00iOfhWlNFgPrjPHDEpOSN0bNuR1nu04b6Uvno5t9kfpRZmRCmm\ncoArPARuqVzxgWiZVOss+iVpgGTyBKE570wy9jw1wDG72S6RZ664AHMpbXSE\nKnRztgBIGNwSapoOQnZ039fVjSm8rd67heCPBWJ7kgSaaLq7E4RMhJK/lzIT\nDi30\r\n=C5DV\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEYCIQCK6HM2JxGya2tlfUJ87KIJv7tqa9MJK/3kp1fc59QiCwIhALno+NL04gmW/7jFFaUskywGef9/n40kRfp3RrJttN4K"}],"size":22343,"noattachment":false,"key":"/ywapi2ts/-/ywapi2ts-1.0.1.tgz"},"maintainers":[{"name":"venus_jin","email":"bboyking1st@163.com"}],"directories":{},"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/ywapi2ts_1.0.1_1556614211142_0.46805851391434716"},"_hasShrinkwrap":false,"publish_time":1556614211240,"_cnpm_publish_time":1556614211240},"1.0.0":{"name":"ywapi2ts","version":"1.0.0","description":"yapi 输出到前端项目中api ts & js","main":"client/index.js","module":"client/index.mjs","typing":"client/index.d.ts","author":{"name":"venus_jin"},"bin":{"ywapi2ts":"lib/cli.js"},"license":"MIT","keywords":["ywapi2ts","yapi","typescript","typing"],"scripts":{"lint":"eslint --fix --ext .ts src/","testApi":"ts-node --transpile-only src/cli.ts","testOnly":"jest","test":"jest --coverage","build":"yarn buildCli && yarn buildClient","buildCli":"tsc","buildClient":"bili","release":"yarn lint && yarn build && npm publish"},"eslintConfig":{"root":true,"extends":"io"},"eslintIgnore":["lib","client","__snapshots__","api"],"jest":{"transform":{"^.+\\.ts$":"ts-jest"},"collectCoverageFrom":["<rootDir>/src/**/*.ts","!<rootDir>/src/index.ts","!<rootDir>/src/api/**/*"],"testRegex":"(/__tests__/.*|(\\.|/)(test|spec))\\.(jsx?|tsx?)$","moduleFileExtensions":["ts","js","json"]},"devDependencies":{"@types/fs-extra":"^5.0.4","@types/jest":"^23.3.9","@types/json-schema":"^7.0.1","@types/json5":"^0.0.30","@types/mockjs":"^1.0.2","@types/node":"^10.12.10","@types/prompts":"^1.2.0","@types/request-promise-native":"^1.0.15","bili":"^4.7.1","codecov":"^3.1.0","eslint":"^5.9.0","eslint-config-io":"^0.5.0","jest":"^23.6.0","rollup-plugin-typescript2":"^0.20.1","standard-version":"^4.4.0","ts-jest":"^23.10.5","typescript":"^3.3.3333"},"dependencies":{"change-case":"^3.0.2","commander":"^2.19.0","consola":"^2.3.0","fs-extra":"^7.0.1","json-schema-generator":"^2.0.6","json-schema-to-typescript":"^6.1.0","json-ts":"^1.6.4","json5":"^2.1.0","mockjs":"^1.0.1-beta3","ora":"^3.4.0","prompts":"^2.0.4","request":"^2.88.0","request-promise-native":"^1.0.5","ts-node":"^8.0.2","tslib":"^1.9.3","vtils":"^0.76.1","yapi-to-typescript":"^1.4.0"},"gitHead":"d5e517a4611e2ee08b964e04479a1d123c91a9e6","_id":"ywapi2ts@1.0.0","_npmVersion":"5.6.0","_nodeVersion":"8.11.3","_npmUser":{"name":"venus_jin","email":"bboyking1st@163.com"},"dist":{"integrity":"sha512-jazj2PE63cHdvk6ownRdtD0US64tJxmUyYW+SzuyCWZgsNl6/cIAl6HdwlviBbvfzsXAX5jRlPVgRjGb0Zju4g==","shasum":"711483a595f50ec2e6e1edf474be939e1a48f93f","tarball":"http://registry-npm.ywwl.com/ywapi2ts/download/ywapi2ts-1.0.0.tgz","fileCount":24,"unpackedSize":64533,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.4\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJcxpy6CRA9TVsSAnZWagAAYNsP/0qQ5EF4QMXWnhyYwY8K\nIaAb9LqpVw2m+UoGJpCyYNI4DNn3/ejzNBlH8pyte2H5OPSF9XWJBhr+sh2r\nE+hDLs3zv3mNMph4ZT0U4ofif61PEucv2i4ojpESq8P6JjSgoGLCakyEB+Wm\n8SB7m7v91TPaZgTvQDJKTOkEXVKTbdVzySBhol6Ikri/F838NqqEWaiq5omN\n+z8189UZXwkak4iG55+gT/puNKVOBgffPEpO76dTR72yIFKV9seFLUwPKhEm\nQfOYFHJScrSklNcDzkEC77+AtIhy0G/lcPujGjrzJLCfgKeaIsd3Wm05opLn\no4lFEvC70Bjkhd94yQz77HlNTjBAg3m6ths0cHIubFEUDIGgzmp6Tz0iRAvi\nuXEMEW/d/suPmPcgh5Yzkwbmz2D85q1DESGxUsgb5Hl4prjf7PpxgryYE296\nkUW9i8+znoYADdaWPWAp4g8Ol+VcA27De/pWzlt+odMCTyt5bVtq7+WRDqEt\n/ejlXVnkOqKJYTgyu2SF9Q0mx/IueeOQayDd/Jm9YQRCemV6mmQTJPrdb3nN\nUoKO2Yi+JSzecrDmXAvcW6aBXXf2t/naR6OvuGGGlqkHt93kpomhNyDTqmQL\nHs4wZZmMkY9UsA0zM/h5tox78dcpYkLxSVzq81raxX55l/n6Ltpp4XuB8MHZ\n9YIT\r\n=bkIQ\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEQCIGUUKlzBLV6fdlC2ECJhJDKDk5aZb8tCYZaJbBVd+KqeAiBKl2D+M/9M8c2YPMm4linWY1cNTEim1B2JAJvY12utmg=="}],"size":14748,"noattachment":false,"key":"/ywapi2ts/-/ywapi2ts-1.0.0.tgz"},"maintainers":[{"name":"venus_jin","email":"bboyking1st@163.com"}],"directories":{},"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/ywapi2ts_1.0.0_1556520122168_0.47460199667689906"},"_hasShrinkwrap":false,"publish_time":1556520122299,"_cnpm_publish_time":1556520122299}},"readme":"# ywapi2ts\r\n\r\n##### 一个根据yapi文档自动生成前端api接口代码的工具，提升效率\r\n\r\n### 解决痛点\r\n  * 后端基于yapi写出的mock 前端几乎人肉copy，加大工作量，特别在ts这种强类型项目中，需要手写所有接口的入参出参类型，耗时长\r\n  * 对接口规范要求高，因为代码是自动生成的，所以更要注意接口文档的严谨性\r\n\r\n## 使用方法\r\n - 1、 全局安装 ywapi2ts 到本机\r\n\r\n  `npm i ywapi2ts -g`\r\n\r\n - 2、 生成 ywapi2ts.config.ts 文件配置到项目\r\n\r\n  `ywapi2ts init`\r\n  到当前开发的项目根目录（与package.json平级）运行该命令，如果当前目录已存在`ywapi2ts.config.ts` 则会提示是否覆盖，没有则会创建，具体配置说明:\r\n  ```\r\n  export interface ServerConfig {\r\n   /**\r\n   * 构建ts 、js版本\r\n   *\r\n   * @example 'ts'\r\n   */\r\n  target: 'ts' | 'js',\r\n  /**\r\n   * YApi 服务地址。\r\n   *\r\n   * @example 'http://yapi.foo.bar'\r\n   */\r\n  serverUrl: string,\r\n  /**\r\n   * 项目id\r\n   *\r\n   * @example 'http://yapi.ywwl.org/project/24/interface/api' projectId 对应 24\r\n   */\r\n  projectId: string,\r\n  /** cookie _yapi_token */\r\n  _yapi_token: string,\r\n  /** cookie _yapi_uid */\r\n  _yapi_uid: string,\r\n  /**\r\n   * 输出文件路径。\r\n   *\r\n   * 可以是 `相对路径` 或 `绝对路径`。\r\n   *\r\n   * @example 'src/ywapi/'\r\n   */\r\n  outputFilePath: string,\r\n  /**\r\n   * 自定义代码片段函数\r\n   * 不配置的话会有默认代码片段\r\n   */\r\n  generateApiFileCode?: (api: IOutPut) => string,\r\n}\r\n\r\nexport interface IOutPut {\r\n  /** 生成api 文件名称 */\r\n  name: string,\r\n  /** 接口url */\r\n  path: string,\r\n  method: Method,\r\n  /** 接口名 */\r\n  title: string,\r\n  /** 接口备注 */\r\n  markdown: string,\r\n  /** 分类菜单id */\r\n  catid: number,\r\n  /** 接口ID */\r\n  id: number,\r\n  /** request interface 名称 */\r\n  reqInterfaceName: string,\r\n  /** response interface 名称 */\r\n  resInterfaceName: string,\r\n  requestInterface: string,\r\n  responseInterface: string,\r\n}\r\n\r\n  ```\r\n\r\n  示例\r\n  ```\r\nexport default {\r\n  serverUrl: 'http://yapi.ywwl.org',\r\n  outputFilePath: 'api',\r\n  projectId: '24',\r\n  _yapi_token: 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1aWQiOjE4LCJpYXQiOjE1NTY1MDYyMTUsImV4cCI6MTU1NzExMTAxNX0.ADmz2HEE6hKoe1DP_U2QtyKSSEURLf5soGKRNyJkX_o',\r\n  _yapi_uid: '18',\r\n  generateApiFileCode: (api) => {\r\n    const arr = [\r\n      `\r\n      /**\r\n      * ${api.title}\r\n      * ${api.markdown || ''}\r\n      **/\r\n      `,\r\n      api.requestInterface,\r\n      api.responseInterface,\r\n      `\r\n      export default (data: ${api.reqInterfaceName}): ${api.resInterfaceName} => request({\r\n        method: '${api.method}',\r\n        url: '${api.path}',\r\n        data: data\r\n      })\r\n      `,\r\n    ]\r\n    return arr.join(`\r\n    `)\r\n  }\r\n}\r\n\r\n  ```\r\n\r\n  一般来说 generateApiFileCode 方法需要自己实现一下，组装拼接出符合自己期望的 接口代码格式\r\n\r\n - 3、生成代码\r\n  `ywapi2ts`\r\n  运行该命令 会根据步骤2的配置文件，生产出api（outputFilePath）文件夹，该文件夹下`index.ts`作为所有接口的导出口，供项目中导入使用\r\n\r\n - 4、查看接口变动日志`ywapi2ts changelog`\r\n\r\n### feature","_attachments":{},"license":"MIT"}