Skip to content

Commit

Permalink
Feature/merge wx (#12)
Browse files Browse the repository at this point in the history
* refactor: close #10, merge wx into core, add adapters/ dir, update deps

* docs: add link to @tua-mp/service
  • Loading branch information
BuptStEve authored Nov 13, 2018
1 parent 674333b commit 6eb6f6b
Show file tree
Hide file tree
Showing 21 changed files with 218 additions and 267 deletions.
16 changes: 7 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@

目前已适配:

* web 端:直接引入 `tua-api` (axios, fetch-jsonp)
* Node 端:直接引入 `tua-api` (axios)
* 小程序端:引入 `tua-api/dist/mp` (wx.request)
* web 端:axios, fetch-jsonp
* Node 端:axios
* 小程序端:wx.request

## 安装
### web 端
Expand Down Expand Up @@ -62,21 +62,19 @@ $ yarn add fetch-jsonp
但是 jsonp 只支持使用 get 的方式请求,所以如果需要发送 post 或其他方式的请求,还是需要装 `axios`

### 小程序端
#### 安装本体
#### 安装本体即可

```bash
$ npm i -S tua-api
# OR
$ yarn add tua-api
```

**注意并非直接导入!**因为正宫是 web 端...

```js
import TuaApi from 'tua-api/dist/mp'
import TuaApi from 'tua-api'
```

或者在 webpack 配置中,设置 `alias`
> 小程序还用不了 npm?[@tua-mp/service](https://tuateam.github.io/tua-mp/tua-mp-service/) 了解一下?
## `tua-api` 能干什么?
`tua-api` 能实现统一管理 api 配置(例如一般放在 `src/apis/` 下)。经过处理后,业务侧代码只需要这样写即可:
Expand Down Expand Up @@ -175,7 +173,7 @@ export default {
最后来看一下 `apis/index.js` 该怎么写:

```js
import TuaApi from 'tua-api' // 小程序用 dist/mp
import TuaApi from 'tua-api'

// 初始化
const tuaApi = new TuaApi({ ... })
Expand Down
2 changes: 1 addition & 1 deletion docs/config/default.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
默认配置指的就是在 `tua-api` 初始化时传递的配置

```js
import TuaApi from 'tua-api' // 小程序用 tua-api/dist/mp
import TuaApi from 'tua-api'

new TuaApi({
host,
Expand Down
9 changes: 4 additions & 5 deletions docs/quick-start/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@

目前已适配:

* web 端:直接引入 `tua-api` (axios, fetch-jsonp)
* Node 端:直接引入 `tua-api` (axios)
* 小程序端:引入 `tua-api/dist/mp` (wx.request)
* web 端:axios, fetch-jsonp
* Node 端:axios
* 小程序端:wx.request

## `tua-api` 能干什么?
`tua-api` 能实现统一管理 api 配置(例如一般放在 `src/apis/` 下)。经过处理后,业务侧代码只需要这样写即可:
Expand All @@ -30,7 +30,6 @@ fooApi
```js
// 甚至可以更进一步和 tua-storage 配合使用
import TuaStorage from 'tua-storage'
// 小程序端要引入 'tua-api/dist/mp'
import { getSyncFnMapByApis } from 'tua-api'

// 本地写好的各种接口配置
Expand Down Expand Up @@ -112,7 +111,7 @@ export default {
最后来看一下 `apis/index.js` 该怎么写:

```js
import TuaApi from 'tua-api' // 小程序用 dist/mp
import TuaApi from 'tua-api'

// 初始化
const tuaApi = new TuaApi({ ... })
Expand Down
8 changes: 2 additions & 6 deletions docs/quick-start/installation.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,22 +44,18 @@ $ yarn add fetch-jsonp
:::

## 小程序端
### 安装本体
### 安装本体即可

```bash
$ npm i -S tua-api
# OR
$ yarn add tua-api
```

**注意并非直接导入!**,因为正宫是 web 端...

```js
import TuaApi from 'tua-api/dist/mp'
import TuaApi from 'tua-api'
```

或者在 webpack 配置中,设置 `alias`

::: tip
小程序还用不了 npm?[@tua-mp/service](https://tuateam.github.io/tua-mp/tua-mp-service/) 了解一下?
:::
4 changes: 2 additions & 2 deletions examples/apis-mp/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import TuaApi from '../../src/TuaApiMp'
import TuaApi from '../../src/TuaApi'

const tuaApi = new TuaApi()
const tuaApi = new TuaApi({ reqType: 'wx' })

// 使用中间件
tuaApi.use(async (ctx, next) => {
Expand Down
1 change: 1 addition & 0 deletions examples/apis-web/fake-post.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ export default {
{
path: 'array-params',
type: 'post',
reqType: 'axios',
params: ['param1', 'param2'],
},
/**
Expand Down
2 changes: 1 addition & 1 deletion examples/apis-web/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import TuaApi from '../../src/TuaApiWeb'
import TuaApi from '../../src/TuaApi'

const tuaApi = new TuaApi({
host: 'http://example-base.com/',
Expand Down
41 changes: 19 additions & 22 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "tua-api",
"version": "0.2.2",
"version": "0.3.0",
"main": "dist/umd.js",
"module": "dist/es.js",
"jsnext:main": "dist/es.js",
Expand All @@ -14,9 +14,7 @@
"lint": "eslint --fix src/ test/",
"deploy": "yarn docs:build && gh-pages -m \"[ci skip]\" -d docs/.vuepress/dist",
"prebuild": "rimraf dist/* & npm run test",
"build": "npm run build:wx & npm run build:web",
"build:wx": "cross-env NODE_ENV=prod rollup -c rollup.mp.config.js",
"build:web": "cross-env NODE_ENV=prod rollup -c rollup.web.config.js",
"build": "cross-env NODE_ENV=prod rollup -c",
"pub": "npm run build && npm publish"
},
"husky": {
Expand Down Expand Up @@ -53,39 +51,38 @@
"author": "StEve Young",
"license": "MIT",
"devDependencies": {
"@commitlint/cli": "^7.0.0",
"@commitlint/config-conventional": "^7.0.1",
"@commitlint/cli": "^7.2.1",
"@commitlint/config-conventional": "^7.1.2",
"axios": "^0.18.0",
"axios-mock-adapter": "^1.14.1",
"babel-core": "^6.26.0",
"babel-eslint": "^9.0.0",
"axios-mock-adapter": "^1.15.0",
"babel-core": "^6.26.3",
"babel-eslint": "^10.0.1",
"babel-jest": "^23.6.0",
"babel-plugin-external-helpers": "^6.22.0",
"babel-plugin-ramda": "^1.6.3",
"babel-plugin-transform-decorators-legacy": "^1.3.4",
"babel-plugin-transform-decorators-legacy": "^1.3.5",
"babel-plugin-transform-object-rest-spread": "^6.26.0",
"babel-preset-env": "^1.6.1",
"babel-preset-env": "^1.7.0",
"codecov": "^3.1.0",
"cross-env": "^5.1.6",
"eslint": "^5.6.0",
"cross-env": "^5.2.0",
"eslint": "^5.9.0",
"eslint-config-standard": "^12.0.0",
"eslint-plugin-import": "^2.8.0",
"eslint-plugin-node": "^7.0.1",
"eslint-plugin-import": "^2.14.0",
"eslint-plugin-node": "^8.0.0",
"eslint-plugin-promise": "^4.0.1",
"eslint-plugin-standard": "^4.0.0",
"fetch-jsonp": "^1.1.3",
"gh-pages": "^2.0.0",
"husky": "^1.0.0-rc.15",
"gh-pages": "^2.0.1",
"husky": "^1.1.4",
"jest": "^23.6.0",
"lint-staged": "^7.3.0",
"lint-staged": "^8.0.4",
"rimraf": "^2.6.2",
"rollup": "^0.66.2",
"rollup": "^0.67.1",
"rollup-plugin-babel": "^3.0.7",
"rollup-plugin-commonjs": "^9.1.8",
"rollup-plugin-commonjs": "^9.2.0",
"rollup-plugin-eslint": "^5.0.0",
"rollup-plugin-json": "^3.1.0",
"rollup-plugin-node-resolve": "^3.4.0",
"rollup-plugin-replace": "^2.0.0",
"rollup-plugin-replace": "^2.1.0",
"vuepress": "^0.14.4"
},
"dependencies": {
Expand Down
6 changes: 2 additions & 4 deletions rollup.web.config.js → rollup.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { eslint } from 'rollup-plugin-eslint'
import nodeResolve from 'rollup-plugin-node-resolve'

export default {
input: 'src/TuaApiWeb.js',
input: 'src/TuaApi.js',
output: [{
file: 'dist/umd.js',
name: 'TuaApi',
Expand All @@ -24,9 +24,7 @@ export default {
eslint(),
json(),
nodeResolve(),
babel({
plugins: [['ramda', { useES: true }]],
}),
babel(),
commonjs(),
replace({
'process.env.NODE_ENV': JSON.stringify('prod'),
Expand Down
26 changes: 0 additions & 26 deletions rollup.mp.config.js

This file was deleted.

Loading

0 comments on commit 6eb6f6b

Please sign in to comment.