# @zsee/msync

> Sync real data to mock server

Latest version **1.0.1** (published 2019-09-11) · MIT license · 0 weekly downloads

## Install

```sh
npm install @zsee/msync
pnpm add @zsee/msync
yarn add @zsee/msync
bun add @zsee/msync
```

Provides the command `msync`.

## Health

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

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.1 |
| Published | 2019-09-11 |
| First published | 2019-09-10 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Node | >=8.0 |
| Dependencies | 9 |
| Unpacked size | 85.6 KB |
| Known vulnerabilities | 0 (+25 in 1 direct dependencies) |
| Install scripts | no |
| Author | zhaosaisai |
| Maintainers | zsee |
| Keywords | node, mock, swagger |

## Links

- npm: https://www.npmjs.com/package/@zsee/msync
- Repository: https://github.com/zhaosaisai/msync
- Homepage: https://github.com/zhaosaisai/msync#readme
- Issues: https://github.com/zhaosaisai/msync/issues
- npm.io page: https://npm.io/package/@zsee/msync

## Dependencies (9)

- [axios](https://npm.io/package/axios.md) ^0.19.0
- [chalk](https://npm.io/package/chalk.md) ^2.4.2
- [dotenv](https://npm.io/package/dotenv.md) ^8.1.0
- [inquirer](https://npm.io/package/inquirer.md) ^7.0.0
- [commander](https://npm.io/package/commander.md) ^3.0.1
- [get-value](https://npm.io/package/get-value.md) ^3.0.1
- [mixin-deep](https://npm.io/package/mixin-deep.md) ^2.0.1
- [pretty-error](https://npm.io/package/pretty-error.md) ^2.1.1
- [schema-utils](https://npm.io/package/schema-utils.md) ^2.2.0

## Alternatives

- [@expo/fingerprint](https://npm.io/package/@expo/fingerprint.md) — 6.2M weekly downloads
- [@azure/monitor-opentelemetry-exporter](https://npm.io/package/@azure/monitor-opentelemetry-exporter.md) — 850.0K weekly downloads
- [@azure/monitor-opentelemetry](https://npm.io/package/@azure/monitor-opentelemetry.md) — 624.0K weekly downloads
- [@posthog/ai](https://npm.io/package/@posthog/ai.md) — 423.3K weekly downloads
- [fakefilter](https://npm.io/package/fakefilter.md) — 63.9K weekly downloads

## Recent versions

- 1.0.1 (latest) — 2019-09-11
- 1.0.0 — 2019-09-10

## README

<p align="center"><img src="https://51nbimg.u51.com/5c7a37623dcd42d6ba5e0a230b2bdda9.png"></p>

# msync

## 能做什么？

做的事情很简单，**将测试环境相关接口的返回数据自动同步到easy mock平台上**。

## 为什么这样做

目的也很简单，需要更真实的开发场景。`easy-mock`平台虽然能够对接口的返回值进行`mock`，但返回的都是一些随机的数据。这些数据在大多数开发情况下都能够帮助我们开发，提升我们的开发效率。为了得到更真实的开发场景，我们有必要把我们测试服务器接口的返回值同步到`easy-mock`平台上。

## 怎么用

```bash
npm install @zsee/msync -g
```

查看使用帮助

```bash
msync -h
```

```bash
Usage: msync [options] [command]

Options:
  -V, --version    输出版本号
  -c, --check      检查当前环境是否满足同步环境 (default: false)
  -h, --help       查看使用帮助

Commands:
  login [options]  登录easy-mock <https://mock.u51-inc.com> 服务器
  whoami           查看当前登录的easy-mock用户

  Run msync <command> --help for detailed usage of given command.
```


## 怎么做

很简单，项目根目录下添加配置文件`sync.config.js`，并作如下配置

```js
export default {
  mappings: [
    {
      // 需要同步的 swagger地址 需要返回json格式的swagger数据
      swagger: 'http://swagger.json',
      // 需要同步到 easy-mock平台下哪个项目下，这个就是对应的项目id
      id: '5d74fcc890851c9701075bdd'
    }
  ],
  // 测试环境用于鉴权的 userId
  userId: '',
  // 测试环境用于鉴权的 token
  token: ''
}
```

> `userId`和`token`会放在request header中 `{userId: '', Authorization: encrypt token}`。其它鉴权方式目前还未作兼容处理。

然后运行

```bash
msync start
```

运行这个命令的时候，如果发现不符合同步环境，程序会退出并给予相应的提示。

## 结果如何

接口同步进行中...

![](https://51nbimg.u51.com/a51b78003fb441c58a8311d34f28b4de.jpg)

接口同步前的`mock`数据

```js
{
  "userInfoDto": {
    "availableLimit": "@integer(60, 100)",
    "baseLimit": "@integer(60, 100)",
    "gainLimit": "@integer(60, 100)",
    "isCertificated": "@boolean",
    "limitStatus": "@integer(60, 100)",
    "maxLimit": "@integer(60, 100)",
    "minLimit": "@integer(60, 100)",
    "remainBaseLimit": "@integer(60, 100)",
    "remainGainLimit": "@integer(60, 100)",
    "userLabelType": "@integer(60, 100)",
    "userLabelTypeList": [
      "@integer(60, 100)"
    ]
  }
}
```

接口同步后的`mock`数据

```js
{
  "userInfoDto": {
    "minLimit": 3000,
    "maxLimit": 200000,
    "isCertificated": true,
    "limitStatus": 1,
    "baseLimit": 8000,
    "gainLimit": 0,
    "availableLimit": 8000,
    "remainBaseLimit": 8000,
    "remainGainLimit": 0,
    "userLabelType": 0,
    "userLabelTypeList": [
      0
    ]
  }
}
```

## TODO

- [x] 更完善的错误判断
- [x] 完善命令行程序
- [x] `easy-mock`自动登录
- [ ] 自定义参数传递
- [ ] `controller`黑/白名单
- [ ] 单接口同步
- [x] 多`swagger`同步

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