{"_id":"@aegis.inc/pont-engine-plus","_rev":"5-5f89fe8accc6be6ba2aa39a41cc735a0","name":"@aegis.inc/pont-engine-plus","dist-tags":{"latest":"0.0.3"},"versions":{"0.0.3":{"name":"@aegis.inc/pont-engine-plus","version":"0.0.3","description":"pont-plus swagger typescript API","main":"lib/index.js","typings":"lib/index.d.ts","bin":{"pont-plus":"bin/init.js"},"scripts":{"pretest":"npm run build","dev":"tsc -w","watch":"tsc -w","build-hooks-js":"tsc --project pontCore/tsconfig.json","build":"shx rm -rf lib & npm run build-hooks-js && tsc"},"dependencies":{"@types/fs-extra":"^9.0.13","chalk":"^2.3.0","commander":"^2.19.0","fs-extra":"^10.0.0","http-server":"^14.1.0","inquirer":"^7.1.0","jest":"^27.4.7","lodash":"^4.17.5","node-fetch":"^1.7.3","prettier":"^2.4.1","react":"^17.0.2","shx":"^0.3.4","swr":"^1.1.2","translation.js":"^0.7.5","typescript":"^3.5.3"},"keywords":["pont-plus","swagger","typescript","API"],"author":{"name":"dshvv"},"license":"MIT","repository":{"type":"git","url":"git+https://github.com/dshvv/pont-engine-plus.git"},"homepage":"https://github.com/dshvv/pont-engine-plus#readme","gitHead":"718ecd9a3887e2fe798bf5bb200399fcd2f562a3","bugs":{"url":"https://github.com/dshvv/pont-engine-plus/issues"},"_id":"@aegis.inc/pont-engine-plus@0.0.3","_nodeVersion":"16.13.2","_npmVersion":"8.1.2","dist":{"integrity":"sha512-47DxeQuqVLYJ0qHrkxTn1VjLEaSyeYa2FDiktfjgMxtKtp6+X/JI3Zgj22XomUKX+6xvL7+rrAKRPD5WcyKchw==","shasum":"f97494457aa7333276ff53a42fa371411f2b2010","tarball":"https://registry.npmjs.org/@aegis.inc/pont-engine-plus/-/pont-engine-plus-0.0.3.tgz","fileCount":70,"unpackedSize":301742,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.13\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJh6QGUCRA9TVsSAnZWagAAuW8P/A5AxDTFsG2/6O2BRAkF\nA3/BVllJ6Yd89le60Wlo/nb60pYKThOglz/V4m3+52Ssattx21BbALmlS1vk\nN7MV0/LNONjGq6LJ5hoCdgyUov1j05d2aLep7TdnlPS3aM9WXsRWee37X4If\n4RgcxNprMASfzcLEnzT/SA6kSAeuHlh5SP9T+/XgHDvYBIm9UNkCvXLu3HVY\nTodXYf41f57ztRGQCp5OKTAUp/BENbue0Az3y/GKx9t1d+EpDYifEnrUxF4z\nZnVGUmFCyjPgL76fMGjLn78vrJYIm83lY1o6lgPi+OpQWkgmRElhug4SSFI2\nFQ5N9plGsOCr8dZjkLQcR0oA+LaA5KLCTzjPZWM7FDVvLTRhqbdo//8xIwI5\nLWUTei+Y7mXUc1Tsr0ZwLkuiUHVly1bk1kHbivVyYhw+LoyAKJ4mQoVMy+ci\nUJN9ULLMti/0OP406edF3ZtDFiLLgj1xNvx+Wiy0xfuG7voyIpp/wY23zxqo\nxznCZQhXMpNWurMAy3OcueiZEEN0K9Je9EUg/xFGP1NR9RXVaOSEAiN1mrqY\n36NATIUaotDAyt2jISfm07YIe9dYb79V1EVlVewpHhLwuqYeDHQjs5bf+VX/\ni3LbW4+MdBh6yJ4U5QLnBWpPEZ/4rQtbHFohu4DwG3sosmC2A+nhof1XAHcj\n0yt/\r\n=dxIU\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQDuM+bUbCeL3HFUR98pQaNBCyDpmzlRYhMol9Qr1KDSqAIgDvhf2hcPVPRWKjISBycH90YysazdJtQ77GEg8hY7Ddk="}]},"_npmUser":{"name":"dshvv","email":"960423114@qq.com"},"directories":{},"maintainers":[{"name":"wuhao000","email":"wh1200@126.com"},{"name":"dshvv","email":"960423114@qq.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/pont-engine-plus_0.0.3_1642660243847_0.3453105961138725"},"_hasShrinkwrap":false}},"time":{"created":"2022-01-20T06:30:43.783Z","0.0.3":"2022-01-20T06:30:44.061Z","modified":"2022-08-16T10:26:46.298Z"},"maintainers":[{"email":"leeyubo1114@163.com","name":"leeyubo"},{"email":"lilchen96@outlook.com","name":"lilchen96"},{"email":"lijunal@126.com","name":"lijunn"},{"email":"xmolan0718@gmail.com","name":"xmon"},{"email":"wh1200@126.com","name":"wuhao000"},{"email":"dshvvvvv@gmail.com","name":"dshvv"}],"description":"pont-plus swagger typescript API","homepage":"https://github.com/dshvv/pont-engine-plus#readme","keywords":["pont-plus","swagger","typescript","API"],"repository":{"type":"git","url":"git+https://github.com/dshvv/pont-engine-plus.git"},"author":{"name":"dshvv"},"bugs":{"url":"https://github.com/dshvv/pont-engine-plus/issues"},"license":"MIT","readme":"  <div align=\"center\">\r\n  <img src=\"https://img.alicdn.com/tfs/TB1cpLSGrvpK1RjSZFqXXcXUVXa-726-396.png\" height=\"100\">\r\n  <h2>Pont - 搭建前后端之桥  </h2>\r\n</div>\r\n\r\n[![npm version](https://badge.fury.io/js/pont-engine.png)](https://badge.fury.io/js/pont-engine)\r\n[![npm downloads](https://img.shields.io/npm/dt/pont-engine.svg?style=flat-square)](https://www.npmjs.com/package/pont-engine)\r\n[![Gitter](https://badges.gitter.im/jasonHzq/pont-engine.svg)](https://gitter.im/jasonHzq/pont-engine?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge)\r\n  \r\n\r\n## 简介\r\nPont 把 swagger、rap、dip 等多种接口文档平台，转换成 Pont 元数据。Pont 利用接口元数据，可以高度定制化生成前端接口层代码，接口 mock 平台和接口测试平台。\r\n其中 swagger 数据源，Pont 已经完美支持。并在一些大型项目中使用了近两年，各种高度定制化需求都可以满足。\r\n\r\n此版本作为原本Pont-v1.0.12的问题修复版，重点解决了一些BUG，如：\r\n```text\r\n修复Swagger V3生成api，无返回类型的映射定义\r\n修复在Swagger V3情况下，没有配置项name的情况下会报错\r\n```\r\n其它均无变化和修改。\r\n\r\n## 安装\r\n```shell\r\n// npm\r\nnpm i pont-engine-plus\r\n\r\n// 或pnpm\r\npnpm i pont-engine-plus\r\n\r\n// 或yarn\r\nyarn add pont-engine-plus\r\n\r\n```\r\n当然也可以全局安装，这点和原版完全一致\r\n\r\n## 使用\r\n```shell\r\npont-plus start\r\n```\r\n使用方式和配置文件均和原版一致，未作改动\r\n\r\n## 代码修改的地方\r\n1、编译命令行修改   \r\n因为源码我从官网下载下build报错，排查发现有使用linux命令，我window自然不兼容。    \r\n所以改为使用跨平台[shx](https://github.com/shelljs/shx)来执行命令（windows的bash、linux的shell等等）。  \r\n\r\npackage.json   \r\n```json\r\n\"build\": \"rm -rf lib & npm run build-hooks-js && tsc\"\r\n```\r\n改为\r\n```json\r\n\"build\": \"shx rm -rf lib & npm run build-hooks-js && tsc\"\r\n```\r\n2、swagger v3配置项无name打包报错修复   \r\n源码打包后，在具体项目使用时如果配置文件`pont-config.json`没有配置name。   \r\n打包会报错。所以做了如下修复。\r\n\r\n/src/manage.ts\r\n```javascript\r\n existsLocal() {\r\n    return (\r\n      fs.existsSync(path.join(this.currConfig.outDir, this.lockFilename)) ||\r\n      _.some(this.allConfigs.map((config) => fs.existsSync(path.join(config.outDir, config.name, this.lockFilename)))) \r\n    );\r\n  }\r\n```\r\n改为\r\n```javascript\r\n existsLocal() { // 判断本地是否已经存在lockFilename文件(即api-lock.json)\r\n    // config.name可能为空,而且lockFilename文件根本不在config.name这里层，而是直接在config.outDir里\r\n    return (\r\n      fs.existsSync(path.join(this.currConfig.outDir, this.lockFilename)) ||\r\n      _.some(this.allConfigs.map((config) => fs.existsSync(path.join(config.outDir, this.lockFilename)))) \r\n    );\r\n  }\r\n```\r\n\r\n3、swagger v3无返回类型修复   \r\n其实也没做什么，因为从npm下载下来的包，一直无返回类型，但是我从源码打包却有。   \r\n因此推论，源码有修复bug后，npm并没有及时更新。   \r\n所以我才重新修复如上问题，在npm上发一个分支包，方便使用\r\n\r\n4、swagger v3修复了生成类型文件错误问提      \r\n如果配置文件`pont-config.json`有name。   \r\n生成的api.d.ts文件则会报错。   \r\n分析代码很明显是因为生成的实体类型嵌套问题\r\n```typescript\r\nype ObjectMap<Key extends string | number | symbol = any, Value = any> = {\r\n  [key in Key]: Value;\r\n};\r\n\r\ndeclare namespace myApi {\r\n    ...\r\n    export class JsonResult<T0 = any> {\r\n      /** code */\r\n      code?: number;\r\n\r\n      /** data */\r\n      data?: defs.myApi.ArticleVOObject;\r\n\r\n      /** msg */\r\n      msg?: string;\r\n    }\r\n}\r\ndeclare namespace API {\r\n   export namespace updateById {\r\n      export class Params {}\r\n\r\n      export type Response = defs.myApi.JsonResult;  //这里引用报错\r\n\r\n      export const init: Response;\r\n\r\n      export function request(params: Params, options?: any): Promise<Response>;\r\n    }\r\n}\r\n\r\n```\r\n所以我将/src/generators/generate.ts做了修改如下\r\n```typescript\r\n/** 获取所有基类的类型定义代码，一个 namespace\r\n   * surrounding, 优先级高于this.surrounding,用于生成api.d.ts时强制保留类型\r\n   */\r\n  getBaseClassesInDeclaration() {\r\n    console.log('3、文件构造器-具体实现-（返回类型）基类的类型定义');\r\n    \r\n    let content = `namespace ${this.dataSource.name || 'defs'} {\r\n      ${this.dataSource.baseClasses\r\n        .map(\r\n          (base) => `\r\n        export ${this.getBaseClassInDeclaration(base)}\r\n      `\r\n        )\r\n        .join('\\n')}\r\n    }\r\n    `;\r\n\r\n    // 改动处：增加了如下代码\r\n    if(this.dataSource.name){\r\n      content = `namespace defs { \r\n        namespace ${this.dataSource.name} {\r\n        ${this.dataSource.baseClasses\r\n          .map(\r\n            (base) => `\r\n          export ${this.getBaseClassInDeclaration(base)}\r\n        `\r\n          )\r\n          .join('\\n')}\r\n        }\r\n      }\r\n      `;\r\n    }\r\n\r\n    return content;\r\n  }\r\n```\r\n\r\n\r\n## 推荐\r\n网友推荐，除了pont，还有其它很多竞品：   \r\n[openapi2typescript](https://github.com/chenshuai2144/openapi2typescript)   \r\n[YApi to TypeScript](https://github.com/fjc0k/yapi-to-typescript)","readmeFilename":"README.md"}