# mock2ts

> Mock API(rap2) to typescript tools

Latest version **1.0.26** (published 2020-05-25) · MIT license · 0 weekly downloads

## Install

```sh
npm install mock2ts
pnpm add mock2ts
yarn add mock2ts
bun add mock2ts
```

Provides the command `mock2ts`.

## Health

**Score 30/100 (F)** — status: abandoned.

Positive: has types; esm support; no vulnerabilities; high quality score.

Warnings: low downloads.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.26 |
| Published | 2020-05-25 |
| First published | 2020-05-21 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Node | >=8.9 |
| Dependencies | 7 |
| Unpacked size | 442.2 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Maintainers | test_zy |

## Links

- npm: https://www.npmjs.com/package/mock2ts
- npm.io page: https://npm.io/package/mock2ts

## Dependencies (7)

- [chalk](https://npm.io/package/chalk.md) ^2.4.2
- [lodash](https://npm.io/package/lodash.md) ^4.17.11
- [sha.js](https://npm.io/package/sha.js.md) ^2.4.11
- [fetch-ajax](https://npm.io/package/fetch-ajax.md) ^0.0.10
- [node-fetch](https://npm.io/package/node-fetch.md) ^2.3.0
- [file-system](https://npm.io/package/file-system.md) ^2.2.2
- [tslint-config-ali](https://npm.io/package/tslint-config-ali.md) ^0.2.4

## Recent versions

- 1.0.26 (latest) — 2020-05-25
- 1.0.25 — 2020-05-25
- 1.0.24 — 2020-05-22
- 1.0.23 — 2020-05-22
- 1.0.22 — 2020-05-22
- 1.0.21 — 2020-05-22
- 1.0.20 — 2020-05-21
- 1.0.19 — 2020-05-21
- 1.0.18 — 2020-05-21
- 1.0.4 — 2020-05-21
- 1.0.3 — 2020-05-21

## README

# ![image.png](https://intranetproxy.alipay.com/skylark/lark/0/2019/png/5014/1558247021534-e8671390-b56d-424b-b7cc-5abd1f1d5baa.png#align=left&display=inline&height=49&name=image.png&originHeight=98&originWidth=85&size=4272&status=done&width=32.5)       Mock2ts

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

# 用法

## 1. 安装包

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

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

```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
> 你可以根据业务需求改变模板

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

```

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

```json
"mock": "mock2ts",
```

## 5. 执行命令，查看结果

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

```node
mock;
```

## 6.  使用前后流程的变化； 
#### 【以往】
> 前后端协作流程
![old.png](https://intranetproxy.alipay.com/skylark/lark/0/2019/png/5014/1558245803637-f514a543-dde0-435f-bb57-ecd900998bd5.png#align=left&display=inline&height=743&name=old.png&originHeight=743&originWidth=1588&size=202808&status=done&width=1588)

<br /><br />

#### 【现在】
> 前后端协作流程
![new.png](https://intranetproxy.alipay.com/skylark/lark/0/2019/png/5014/1558245803598-231e0832-5b71-4f09-9f57-279f89242bdb.png#align=left&display=inline&height=819&name=new.png&originHeight=819&originWidth=1588&size=175267&status=done&width=1588)

# 命令

- watch 启动监控
- startG 开始生成

---
_Source: https://npm.io/package/mock2ts · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
