-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #18 from GuoXiCheng/dev-c
Dev c
- Loading branch information
Showing
8 changed files
with
179 additions
and
45 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
name: Publish npm package | ||
|
||
on: | ||
push: | ||
branches: | ||
- publish | ||
|
||
jobs: | ||
publish: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Checkout code | ||
uses: actions/checkout@v2 | ||
|
||
- name: Set up Node.js | ||
uses: actions/setup-node@v2 | ||
with: | ||
node-version: '14' # 指定 Node.js 版本 | ||
registry-url: 'https://registry.npmjs.org' | ||
|
||
- name: Install dependencies | ||
run: npm install | ||
|
||
- name: Build package | ||
run: npm run build | ||
|
||
- name: Publish to npm | ||
run: npm publish | ||
env: | ||
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import { AxiosInstance } from 'axios'; | ||
import { TinyRequest } from './interfaces'; | ||
|
||
export class AxiosRequest implements TinyRequest { | ||
constructor(private axios: AxiosInstance) { } | ||
|
||
get(url: string) { | ||
this.axios.get(url); | ||
} | ||
|
||
post(url: string) { | ||
this.axios.post(url); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
export interface WxInstance { | ||
request(options: WxRequestOptions): void; | ||
[prop: string]: any; | ||
} | ||
|
||
export interface WxRequestOptions { | ||
url: string; | ||
method: 'GET' | 'POST'; | ||
} | ||
|
||
export interface TinyRequest { | ||
get(url: string): void; | ||
post(url: string): void; | ||
}; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import { AxiosInstance } from "axios"; | ||
import { TinyRequest, WxInstance } from "./interfaces"; | ||
import { AxiosRequest } from "./axios-request"; | ||
import { WxRequest } from "./wx-request"; | ||
|
||
export type RequestInstance = WxInstance | AxiosInstance; | ||
|
||
abstract class TinyRequestFactory { | ||
abstract createRequest(instance: RequestInstance): TinyRequest; | ||
} | ||
|
||
export class AxiosRequestFactory extends TinyRequestFactory { | ||
createRequest(instance: AxiosInstance) { | ||
return new AxiosRequest(instance); | ||
} | ||
} | ||
|
||
export class WxRequestFactory extends TinyRequestFactory { | ||
createRequest(instance: WxInstance) { | ||
return new WxRequest(instance); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import { WxInstance, TinyRequest } from './interfaces'; | ||
|
||
export class WxRequest implements TinyRequest { | ||
constructor(private wx: WxInstance) { } | ||
|
||
get(url: string) { | ||
this.wx.request({ | ||
url, | ||
method: 'GET' | ||
}); | ||
} | ||
|
||
post(url: string) { | ||
this.wx.request({ | ||
url, | ||
method: 'POST' | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,45 +1,76 @@ | ||
import { RequestLib, RequestLibType } from "."; | ||
|
||
interface TinyRequest { | ||
get(): void; | ||
post(): void; | ||
}; | ||
|
||
class AxiosRequest implements TinyRequest { | ||
constructor() {} | ||
get() { } | ||
post() { } | ||
} | ||
|
||
class WxRequest implements TinyRequest { | ||
get() { } | ||
post() { } | ||
} | ||
|
||
abstract class TinyRequestFactory { | ||
abstract createRequest(): TinyRequest; | ||
} | ||
|
||
class AxiosRequestFactory extends TinyRequestFactory { | ||
createRequest() { | ||
return new AxiosRequest(); | ||
} | ||
} | ||
|
||
class WxRequestFactory extends TinyRequestFactory { | ||
createRequest() { | ||
return new WxRequest(); | ||
} | ||
} | ||
|
||
function clientNode(requestLibType: RequestLibType, requestInstance: any) { | ||
switch(requestLibType) { | ||
case RequestLib.axios: | ||
return new AxiosRequestFactory().createRequest(); | ||
case RequestLib.wx: | ||
return new WxRequestFactory().createRequest(); | ||
default: | ||
throw new Error("request lib not support"); | ||
} | ||
} | ||
// import { RequestLib, RequestLibType } from "."; | ||
// import { AxiosInstance } from 'axios'; | ||
// interface WxInstance { | ||
// request(options: WxRequestOptions): void; | ||
// [prop: string]: any; | ||
// } | ||
|
||
// interface WxRequestOptions { | ||
// url: string; | ||
// method: 'GET' | 'POST'; | ||
// } | ||
|
||
// type RequestInstance = WxInstance | AxiosInstance; | ||
|
||
// interface TinyRequest { | ||
// get(url: string): void; | ||
// post(url: string): void; | ||
// }; | ||
|
||
// class AxiosRequest implements TinyRequest { | ||
// constructor(private axios: AxiosInstance) { } | ||
|
||
// get(url: string) { | ||
// this.axios.get(url); | ||
// } | ||
|
||
// post(url: string) { | ||
// this.axios.post(url); | ||
// } | ||
// } | ||
|
||
// class WxRequest implements TinyRequest { | ||
// constructor(private wx: WxInstance) { } | ||
|
||
// get(url: string) { | ||
// this.wx.request({ | ||
// url, | ||
// method: 'GET' | ||
// }); | ||
// } | ||
|
||
// post(url: string) { | ||
// this.wx.request({ | ||
// url, | ||
// method: 'POST' | ||
// }); | ||
// } | ||
// } | ||
|
||
// abstract class TinyRequestFactory { | ||
// abstract createRequest(instance: RequestInstance): TinyRequest; | ||
// } | ||
|
||
// class AxiosRequestFactory extends TinyRequestFactory { | ||
// createRequest(instance: AxiosInstance) { | ||
// return new AxiosRequest(instance); | ||
// } | ||
// } | ||
|
||
// class WxRequestFactory extends TinyRequestFactory { | ||
// createRequest(instance: WxInstance) { | ||
// return new WxRequest(instance); | ||
// } | ||
// } | ||
|
||
// function clientNode(requestLibType: RequestLibType, instance: RequestInstance) { | ||
// switch (requestLibType) { | ||
// case RequestLib.axios: | ||
// return new AxiosRequestFactory().createRequest(instance as AxiosInstance); | ||
// case RequestLib.wx: | ||
// return new WxRequestFactory().createRequest(instance as WxInstance); | ||
// default: | ||
// throw new Error("request lib not support"); | ||
// } | ||
// } | ||
|