1.0.26 • Published 4 years ago

mock2ts v1.0.26

Weekly downloads
84
License
MIT
Repository
-
Last release
4 years ago

image.png Mock2ts

mock 平台(目前支持 rap2) 转换成 typescript 工具

用法

1. 安装包

yarn add @ali/mock2ts 或 tnpm install -i @ali/mock2ts

2. 在项目跟目录配置文件 mock2ts.json

{
  "projectId": 3040,
  "outDir": "src/api/api-define",
  "responseField": "data",
  "template": "mock2ts.template",
  "prettierOpts": {
    "printWidth": 120,
    "singleQuote": true,
    "trailingComma": "none",
    "jsxBracketSameLine": true
  }
}

3. 配置生成的接口模板 mock2ts.template

内置变量有 desc、author、url、interfaceNameSpace、request、response、subClass 你可以根据业务需求改变模板

/**
 * <%= desc %>
 * @auto ${author}
 * @description auto generated by AutoMachineTools
 * @mockUrl <%= url %>
 **/
declare namespace ${interfaceNameSpace} {
<%= request %>
<%= response %>
<%= subClass %>
  // BaseInfo
}
export { ${interfaceNameSpace} };

4. 在业务项目的 packjson 中配置 script 脚本

"mock": "mock2ts",

5. 执行命令,查看结果

执行 mock 命令后, 查看  src/api 目录下是否有接口和 Pojo 文件生成;

mock;

6. 使用前后流程的变化;

【以往】

前后端协作流程 old.png

【现在】

前后端协作流程 new.png

命令

  • watch 启动监控
  • startG 开始生成
1.0.26

4 years ago

1.0.25

4 years ago

1.0.24

4 years ago

1.0.23

4 years ago

1.0.22

4 years ago

1.0.21

4 years ago

1.0.20

4 years ago

1.0.19

4 years ago

1.0.18

4 years ago

1.0.4

4 years ago

1.0.3

4 years ago