Skip to content

Commit

Permalink
chore: update example.
Browse files Browse the repository at this point in the history
  • Loading branch information
jaywcjlove committed Sep 30, 2021
1 parent 2dc2f26 commit f320c14
Show file tree
Hide file tree
Showing 11 changed files with 26 additions and 11 deletions.
2 changes: 1 addition & 1 deletion example/base/mocker/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const { delay } = require('mocker-api');
const delay = require('mocker-api/lib/delay');
const user = require('./user.mock');

// 是否禁用代理
Expand Down
2 changes: 1 addition & 1 deletion example/create-react-app/mocker/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const { delay } = require('mocker-api');
const delay = require('mocker-api/lib/delay');

// 是否禁用代理
const noProxy = process.env.NO_PROXY === 'true';
Expand Down
4 changes: 1 addition & 3 deletions example/express/mocker/index.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
const { delay } = require('mocker-api');
const delay = require('mocker-api/lib/delay');
const user = require('./user.mock');

console.log('user:', user)

// 是否禁用代理
const noProxy = process.env.NO_PROXY === 'true';

Expand Down
2 changes: 1 addition & 1 deletion example/loadData/mocker/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const { delay } = require('mocker-api');
const delay = require('mocker-api/lib/delay');

// 是否禁用代理
const noProxy = process.env.NO_PROXY === 'true';
Expand Down
11 changes: 11 additions & 0 deletions example/typescript/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
typescript
===

```bash
npm run watch
npm run build
```

```bash
npm run start
```
2 changes: 1 addition & 1 deletion example/typescript/mocker/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const { delay } = require('mocker-api');
const delay = require('mocker-api/lib/delay');
const user = require('./user.mock');

// 是否禁用代理
Expand Down
3 changes: 2 additions & 1 deletion example/typescript/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"description": "",
"main": "index.js",
"scripts": {
"start": "node lib/index.js",
"watch": "tsc -p ./ --types --outDir lib --watch",
"build": "tsc -p ./ --types --outDir lib",
"test": "tsc --noEmit"
Expand All @@ -17,6 +18,6 @@
"express": "4.17.1"
},
"devDependencies": {
"typescript": "4.3.2"
"typescript": "4.4.3"
}
}
2 changes: 1 addition & 1 deletion example/webpack/mocker/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const { delay } = require('mocker-api');
const delay = require('mocker-api/lib/delay');
const { login } = require('./user');

// 是否禁用代理
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
"author": "Kenny Wong <wowohoo@qq.com>",
"devDependencies": {
"tsbb": "3.3.7",
"typescript": "4.3.5",
"typescript": "4.4.3",
"typedoc": "0.22.4"
}
}
5 changes: 4 additions & 1 deletion packages/core/src/delay.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,10 @@ import { MockerProxyRoute, MockerResult, MockerResultFunction } from './';
* module.exports = (noProxy ? {} : delay(proxy, 1000));
* ```
*/
export function delay(proxy: MockerProxyRoute, timer: number = 0): MockerResult {

module.exports = delay;

export default function delay(proxy: MockerProxyRoute, timer: number = 0): MockerResult {
const mockApi: MockerResult = {};
Object.keys(proxy).forEach((key) => {
const result = proxy[key];
Expand Down
2 changes: 2 additions & 0 deletions packages/core/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,8 @@ export interface MockerOption {
const pathToRegexp = toRegexp.pathToRegexp;
let mocker: MockerProxyRoute = {};

module.exports = mockerApi

export default function mockerApi(app: Application, watchFile: string | string[] | MockerProxyRoute, conf: MockerOption = {}) {
const watchFiles = (Array.isArray(watchFile) ? watchFile : typeof watchFile === 'string' ? [watchFile] : []).map(str => PATH.resolve(str));

Expand Down

0 comments on commit f320c14

Please sign in to comment.