From 69a90884d5cccf640bcc2de72109afb8cf1552eb Mon Sep 17 00:00:00 2001 From: King Wang Date: Thu, 7 Oct 2021 15:30:02 +0800 Subject: [PATCH] examples to new tsrpc-cli --- examples/chatroom/backend/package.json | 18 +- examples/chatroom/backend/tsrpc.config.ts | 36 +++ examples/chatroom/frontend/package.json | 14 +- examples/chatroom/frontend/src/shared | 1 + .../frontend/src/shared/protocols/MsgChat.ts | 4 - .../frontend/src/shared/protocols/PtlSend.ts | 7 - .../src/shared/protocols/serviceProto.ts | 75 ----- examples/client-mock/backend/package.json | 20 +- examples/client-mock/backend/tsrpc.config.ts | 36 +++ examples/client-mock/frontend/package.json | 10 +- examples/client-mock/frontend/src/shared | 1 + .../src/shared/protocols/PtlAddData.ts | 10 - .../src/shared/protocols/PtlGetData.ts | 13 - .../src/shared/protocols/serviceProto.ts | 98 ------ .../cocos-creator-3.3.0/backend/package.json | 18 +- .../src}/shared/protocols.meta | 2 +- .../src}/shared/protocols/MsgChat.ts.meta | 2 +- .../src}/shared/protocols/PtlSend.ts.meta | 2 +- .../shared/protocols/serviceProto.ts.meta | 2 +- .../backend/tsrpc.config.ts | 36 +++ .../frontend/assets/scripts/shared | 1 + .../scripts/shared/protocols/MsgChat.ts | 4 - .../scripts/shared/protocols/PtlSend.ts | 7 - .../scripts/shared/protocols/serviceProto.ts | 75 ----- .../cocos-creator-3.3.0/frontend/package.json | 2 +- .../frontend/profiles/v2/packages/scene.json | 6 +- .../settings/v2/packages/cocos-service.json | 2 +- examples/custom-http-res/package.json | 24 +- examples/custom-http-res/src/index.ts | 7 +- examples/custom-http-res/tsrpc.config.ts | 36 +++ examples/file-upload/backend/package.json | 18 +- examples/file-upload/backend/tsrpc.config.ts | 36 +++ examples/file-upload/frontend/package.json | 14 +- examples/file-upload/frontend/src/shared | 1 + .../src/shared/protocols/PtlUpload.ts | 8 - .../src/shared/protocols/serviceProto.ts | 59 ---- examples/first-api/backend/package.json | 18 +- examples/first-api/backend/tsrpc.config.ts | 36 +++ examples/first-api/frontend/package.json | 14 +- examples/first-api/frontend/src/shared | 1 + .../frontend/src/shared/protocols/PtlHello.ts | 8 - .../src/shared/protocols/serviceProto.ts | 57 ---- examples/layaair/backend/package.json | 20 +- examples/layaair/backend/tsrpc.config.ts | 36 +++ examples/layaair/frontend/package.json | 10 +- examples/mongodb-crud/backend/package.json | 33 +-- examples/mongodb-crud/backend/tsrpc.config.ts | 36 +++ examples/mongodb-crud/frontend/package.json | 10 +- examples/mongodb-crud/frontend/src/shared | 1 + .../src/shared/protocols/PtlAddPost.ts | 9 - .../src/shared/protocols/PtlDelPost.ts | 7 - .../src/shared/protocols/PtlGetPost.ts | 9 - .../src/shared/protocols/PtlUpdatePost.ts | 9 - .../src/shared/protocols/models/Post.ts | 17 -- .../src/shared/protocols/serviceProto.ts | 276 ----------------- .../session-and-cookie/backend/package.json | 20 +- .../backend/tsrpc.config.ts | 36 +++ .../session-and-cookie/frontend/package.json | 14 +- .../session-and-cookie/frontend/src/shared | 1 + .../frontend/src/shared/protocols/PtlClear.ts | 9 - .../src/shared/protocols/PtlSetCookie.ts | 9 - .../src/shared/protocols/PtlSetSession.ts | 9 - .../frontend/src/shared/protocols/PtlTest.ts | 10 - .../frontend/src/shared/protocols/base.ts | 12 - .../src/shared/protocols/serviceProto.ts | 209 ------------- .../transfer-encryption/backend/package.json | 20 +- .../backend/tsrpc.config.ts | 36 +++ .../transfer-encryption/frontend/package.json | 10 +- .../transfer-encryption/frontend/src/shared | 1 + .../frontend/src/shared/models/EncryptUtil.ts | 17 -- .../src/shared/protocols/PtlAddData.ts | 10 - .../src/shared/protocols/PtlGetData.ts | 13 - .../src/shared/protocols/serviceProto.ts | 98 ------ .../user-authentication/backend/package.json | 20 +- .../src/shared/protocols/serviceProto.ts | 39 ++- .../backend/tsrpc.config.ts | 36 +++ .../user-authentication/frontend/package.json | 14 +- .../user-authentication/frontend/src/shared | 1 + .../shared/protocols/action/PtlAdminAction.ts | 14 - .../shared/protocols/action/PtlGuestAction.ts | 13 - .../protocols/action/PtlNormalAction.ts | 13 - .../frontend/src/shared/protocols/base.ts | 13 - .../src/shared/protocols/serviceProto.ts | 279 ------------------ .../src/shared/protocols/user/PtlLogin.ts | 14 - .../src/shared/protocols/user/PtlLogout.ts | 13 - scripts/npm-update.js | 34 ++- 86 files changed, 652 insertions(+), 1697 deletions(-) create mode 100644 examples/chatroom/backend/tsrpc.config.ts create mode 120000 examples/chatroom/frontend/src/shared delete mode 100644 examples/chatroom/frontend/src/shared/protocols/MsgChat.ts delete mode 100644 examples/chatroom/frontend/src/shared/protocols/PtlSend.ts delete mode 100644 examples/chatroom/frontend/src/shared/protocols/serviceProto.ts create mode 100644 examples/client-mock/backend/tsrpc.config.ts create mode 120000 examples/client-mock/frontend/src/shared delete mode 100644 examples/client-mock/frontend/src/shared/protocols/PtlAddData.ts delete mode 100644 examples/client-mock/frontend/src/shared/protocols/PtlGetData.ts delete mode 100644 examples/client-mock/frontend/src/shared/protocols/serviceProto.ts rename examples/cocos-creator-3.3.0/{frontend/assets/scripts => backend/src}/shared/protocols.meta (77%) rename examples/cocos-creator-3.3.0/{frontend/assets/scripts => backend/src}/shared/protocols/MsgChat.ts.meta (70%) rename examples/cocos-creator-3.3.0/{frontend/assets/scripts => backend/src}/shared/protocols/PtlSend.ts.meta (70%) rename examples/cocos-creator-3.3.0/{frontend/assets/scripts => backend/src}/shared/protocols/serviceProto.ts.meta (70%) create mode 100644 examples/cocos-creator-3.3.0/backend/tsrpc.config.ts create mode 120000 examples/cocos-creator-3.3.0/frontend/assets/scripts/shared delete mode 100644 examples/cocos-creator-3.3.0/frontend/assets/scripts/shared/protocols/MsgChat.ts delete mode 100644 examples/cocos-creator-3.3.0/frontend/assets/scripts/shared/protocols/PtlSend.ts delete mode 100644 examples/cocos-creator-3.3.0/frontend/assets/scripts/shared/protocols/serviceProto.ts create mode 100644 examples/custom-http-res/tsrpc.config.ts create mode 100644 examples/file-upload/backend/tsrpc.config.ts create mode 120000 examples/file-upload/frontend/src/shared delete mode 100644 examples/file-upload/frontend/src/shared/protocols/PtlUpload.ts delete mode 100644 examples/file-upload/frontend/src/shared/protocols/serviceProto.ts create mode 100644 examples/first-api/backend/tsrpc.config.ts create mode 120000 examples/first-api/frontend/src/shared delete mode 100644 examples/first-api/frontend/src/shared/protocols/PtlHello.ts delete mode 100644 examples/first-api/frontend/src/shared/protocols/serviceProto.ts create mode 100644 examples/layaair/backend/tsrpc.config.ts create mode 100644 examples/mongodb-crud/backend/tsrpc.config.ts create mode 120000 examples/mongodb-crud/frontend/src/shared delete mode 100644 examples/mongodb-crud/frontend/src/shared/protocols/PtlAddPost.ts delete mode 100644 examples/mongodb-crud/frontend/src/shared/protocols/PtlDelPost.ts delete mode 100644 examples/mongodb-crud/frontend/src/shared/protocols/PtlGetPost.ts delete mode 100644 examples/mongodb-crud/frontend/src/shared/protocols/PtlUpdatePost.ts delete mode 100644 examples/mongodb-crud/frontend/src/shared/protocols/models/Post.ts delete mode 100644 examples/mongodb-crud/frontend/src/shared/protocols/serviceProto.ts create mode 100644 examples/session-and-cookie/backend/tsrpc.config.ts create mode 120000 examples/session-and-cookie/frontend/src/shared delete mode 100644 examples/session-and-cookie/frontend/src/shared/protocols/PtlClear.ts delete mode 100644 examples/session-and-cookie/frontend/src/shared/protocols/PtlSetCookie.ts delete mode 100644 examples/session-and-cookie/frontend/src/shared/protocols/PtlSetSession.ts delete mode 100644 examples/session-and-cookie/frontend/src/shared/protocols/PtlTest.ts delete mode 100644 examples/session-and-cookie/frontend/src/shared/protocols/base.ts delete mode 100644 examples/session-and-cookie/frontend/src/shared/protocols/serviceProto.ts create mode 100644 examples/transfer-encryption/backend/tsrpc.config.ts create mode 120000 examples/transfer-encryption/frontend/src/shared delete mode 100644 examples/transfer-encryption/frontend/src/shared/models/EncryptUtil.ts delete mode 100644 examples/transfer-encryption/frontend/src/shared/protocols/PtlAddData.ts delete mode 100644 examples/transfer-encryption/frontend/src/shared/protocols/PtlGetData.ts delete mode 100644 examples/transfer-encryption/frontend/src/shared/protocols/serviceProto.ts create mode 100644 examples/user-authentication/backend/tsrpc.config.ts create mode 120000 examples/user-authentication/frontend/src/shared delete mode 100644 examples/user-authentication/frontend/src/shared/protocols/action/PtlAdminAction.ts delete mode 100644 examples/user-authentication/frontend/src/shared/protocols/action/PtlGuestAction.ts delete mode 100644 examples/user-authentication/frontend/src/shared/protocols/action/PtlNormalAction.ts delete mode 100644 examples/user-authentication/frontend/src/shared/protocols/base.ts delete mode 100644 examples/user-authentication/frontend/src/shared/protocols/serviceProto.ts delete mode 100644 examples/user-authentication/frontend/src/shared/protocols/user/PtlLogin.ts delete mode 100644 examples/user-authentication/frontend/src/shared/protocols/user/PtlLogout.ts diff --git a/examples/chatroom/backend/package.json b/examples/chatroom/backend/package.json index f6a1ea8..da02ca7 100644 --- a/examples/chatroom/backend/package.json +++ b/examples/chatroom/backend/package.json @@ -4,20 +4,20 @@ "main": "index.js", "private": true, "scripts": { - "proto": "tsrpc proto -i src/shared/protocols -o src/shared/protocols/serviceProto.ts", - "sync": "tsrpc sync --from src/shared --to ../frontend/src/shared", - "api": "tsrpc api -i src/shared/protocols/serviceProto.ts -o src/api", - "dev": "onchange \"src/**/*.ts\" -i -k -- ts-node \"src/index.ts\"", - "build": "tsrpc build" + "proto": "tsrpc proto --config tsrpc.config.ts", + "sync": "tsrpc sync --config tsrpc.config.ts", + "api": "tsrpc api --config tsrpc.config.ts", + "dev": "tsrpc dev --config tsrpc.config.ts", + "build": "tsrpc build --config tsrpc.config.ts" }, "devDependencies": { - "@types/node": "^15.12.3", + "@types/node": "^15.14.9", "onchange": "^7.1.0", "ts-node": "^9.1.1", - "tsrpc-cli": "^2.0.3", - "typescript": "^4.3.4" + "tsrpc-cli": "^2.0.8", + "typescript": "^4.4.3" }, "dependencies": { - "tsrpc": "^3.0.2" + "tsrpc": "^3.0.9" } } diff --git a/examples/chatroom/backend/tsrpc.config.ts b/examples/chatroom/backend/tsrpc.config.ts new file mode 100644 index 0000000..704baed --- /dev/null +++ b/examples/chatroom/backend/tsrpc.config.ts @@ -0,0 +1,36 @@ +import { TsrpcConfig } from 'tsrpc-cli'; + +const tsrpcConf: TsrpcConfig = { + // Generate ServiceProto + proto: [ + { + ptlDir: 'src/shared/protocols', // Protocol dir + output: 'src/shared/protocols/serviceProto.ts', // Path for generated ServiceProto + apiDir: 'src/api' // API dir + } + ], + // Sync shared code + sync: [ + { + from: 'src/shared', + to: '../frontend/src/shared', + type: 'symlink' // Change this to 'copy' if your environment not support symlink + } + ], + // Dev server + dev: { + autoProto: true, // Auto regenerate proto + autoSync: true, // Auto sync when file changed + autoApi: true, // Auto create API when ServiceProto updated + watch: 'src', // Restart dev server when these files changed + entry: 'src/index.ts', // Dev server command: node -r ts-node/register {entry} + }, + // Build config + build: { + autoProto: true, // Auto generate proto before build + autoSync: true, // Auto sync before build + autoApi: true, // Auto generate API before build + outDir: 'dist', // Clean this dir before build + } +} +export default tsrpcConf; \ No newline at end of file diff --git a/examples/chatroom/frontend/package.json b/examples/chatroom/frontend/package.json index 9c41578..3df127f 100644 --- a/examples/chatroom/frontend/package.json +++ b/examples/chatroom/frontend/package.json @@ -7,15 +7,15 @@ "build": "webpack --mode=production" }, "devDependencies": { - "copy-webpack-plugin": "^9.0.0", - "html-webpack-plugin": "^5.3.1", - "ts-loader": "^9.2.3", - "typescript": "^4.3.4", - "webpack": "^5.39.1", - "webpack-cli": "^4.7.2", + "copy-webpack-plugin": "^9.0.1", + "html-webpack-plugin": "^5.3.2", + "ts-loader": "^9.2.6", + "typescript": "^4.4.3", + "webpack": "^5.57.1", + "webpack-cli": "^4.9.0", "webpack-dev-server": "^3.11.2" }, "dependencies": { - "tsrpc-browser": "^3.0.3" + "tsrpc-browser": "^3.0.7" } } diff --git a/examples/chatroom/frontend/src/shared b/examples/chatroom/frontend/src/shared new file mode 120000 index 0000000..b72cd26 --- /dev/null +++ b/examples/chatroom/frontend/src/shared @@ -0,0 +1 @@ +../../backend/src/shared \ No newline at end of file diff --git a/examples/chatroom/frontend/src/shared/protocols/MsgChat.ts b/examples/chatroom/frontend/src/shared/protocols/MsgChat.ts deleted file mode 100644 index 4912efe..0000000 --- a/examples/chatroom/frontend/src/shared/protocols/MsgChat.ts +++ /dev/null @@ -1,4 +0,0 @@ -export interface MsgChat { - content: string, - time: Date -} \ No newline at end of file diff --git a/examples/chatroom/frontend/src/shared/protocols/PtlSend.ts b/examples/chatroom/frontend/src/shared/protocols/PtlSend.ts deleted file mode 100644 index ed2505d..0000000 --- a/examples/chatroom/frontend/src/shared/protocols/PtlSend.ts +++ /dev/null @@ -1,7 +0,0 @@ -export interface ReqSend { - content: string -} - -export interface ResSend { - time: Date -} \ No newline at end of file diff --git a/examples/chatroom/frontend/src/shared/protocols/serviceProto.ts b/examples/chatroom/frontend/src/shared/protocols/serviceProto.ts deleted file mode 100644 index d007337..0000000 --- a/examples/chatroom/frontend/src/shared/protocols/serviceProto.ts +++ /dev/null @@ -1,75 +0,0 @@ -import { ServiceProto } from 'tsrpc-proto'; -import { MsgChat } from './MsgChat'; -import { ReqSend, ResSend } from './PtlSend'; - -export interface ServiceType { - api: { - "Send": { - req: ReqSend, - res: ResSend - } - }, - msg: { - "Chat": MsgChat - } -} - -export const serviceProto: ServiceProto = { - "services": [ - { - "id": 0, - "name": "Chat", - "type": "msg" - }, - { - "id": 1, - "name": "Send", - "type": "api" - } - ], - "types": { - "MsgChat/MsgChat": { - "type": "Interface", - "properties": [ - { - "id": 0, - "name": "content", - "type": { - "type": "String" - } - }, - { - "id": 1, - "name": "time", - "type": { - "type": "Date" - } - } - ] - }, - "PtlSend/ReqSend": { - "type": "Interface", - "properties": [ - { - "id": 0, - "name": "content", - "type": { - "type": "String" - } - } - ] - }, - "PtlSend/ResSend": { - "type": "Interface", - "properties": [ - { - "id": 0, - "name": "time", - "type": { - "type": "Date" - } - } - ] - } - } -}; \ No newline at end of file diff --git a/examples/client-mock/backend/package.json b/examples/client-mock/backend/package.json index d9e35bd..dc9a17b 100644 --- a/examples/client-mock/backend/package.json +++ b/examples/client-mock/backend/package.json @@ -4,20 +4,20 @@ "main": "index.js", "private": true, "scripts": { - "proto": "tsrpc proto -i src/shared/protocols -o src/shared/protocols/serviceProto.ts", - "sync": "tsrpc sync --from src/shared --to ../frontend/src/shared", - "api": "tsrpc api -i src/shared/protocols/serviceProto.ts -o src/api", - "dev": "onchange \"src/**/*.ts\" -i -k -- ts-node \"src/index.ts\"", - "build": "tsrpc build" + "proto": "tsrpc proto --config tsrpc.config.ts", + "sync": "tsrpc sync --config tsrpc.config.ts", + "api": "tsrpc api --config tsrpc.config.ts", + "dev": "tsrpc dev --config tsrpc.config.ts", + "build": "tsrpc build --config tsrpc.config.ts" }, "devDependencies": { - "@types/node": "^15.12.5", + "@types/node": "^15.14.9", "onchange": "^7.1.0", - "ts-node": "^10.0.0", - "tsrpc-cli": "^2.0.3", - "typescript": "^4.3.4" + "ts-node": "^10.2.1", + "tsrpc-cli": "^2.0.8", + "typescript": "^4.4.3" }, "dependencies": { - "tsrpc": "^3.0.4" + "tsrpc": "^3.0.9" } } diff --git a/examples/client-mock/backend/tsrpc.config.ts b/examples/client-mock/backend/tsrpc.config.ts new file mode 100644 index 0000000..704baed --- /dev/null +++ b/examples/client-mock/backend/tsrpc.config.ts @@ -0,0 +1,36 @@ +import { TsrpcConfig } from 'tsrpc-cli'; + +const tsrpcConf: TsrpcConfig = { + // Generate ServiceProto + proto: [ + { + ptlDir: 'src/shared/protocols', // Protocol dir + output: 'src/shared/protocols/serviceProto.ts', // Path for generated ServiceProto + apiDir: 'src/api' // API dir + } + ], + // Sync shared code + sync: [ + { + from: 'src/shared', + to: '../frontend/src/shared', + type: 'symlink' // Change this to 'copy' if your environment not support symlink + } + ], + // Dev server + dev: { + autoProto: true, // Auto regenerate proto + autoSync: true, // Auto sync when file changed + autoApi: true, // Auto create API when ServiceProto updated + watch: 'src', // Restart dev server when these files changed + entry: 'src/index.ts', // Dev server command: node -r ts-node/register {entry} + }, + // Build config + build: { + autoProto: true, // Auto generate proto before build + autoSync: true, // Auto sync before build + autoApi: true, // Auto generate API before build + outDir: 'dist', // Clean this dir before build + } +} +export default tsrpcConf; \ No newline at end of file diff --git a/examples/client-mock/frontend/package.json b/examples/client-mock/frontend/package.json index e44937d..d423635 100644 --- a/examples/client-mock/frontend/package.json +++ b/examples/client-mock/frontend/package.json @@ -9,14 +9,14 @@ "devDependencies": { "copy-webpack-plugin": "^9.0.1", "html-webpack-plugin": "^5.3.2", - "ts-loader": "^9.2.3", - "typescript": "^4.3.4", - "webpack": "^5.41.1", - "webpack-cli": "^4.7.2", + "ts-loader": "^9.2.6", + "typescript": "^4.4.3", + "webpack": "^5.57.1", + "webpack-cli": "^4.9.0", "webpack-dev-server": "^3.11.2" }, "dependencies": { - "tsrpc-browser": "^3.0.4" + "tsrpc-browser": "^3.0.7" }, "browserslist": [ "defaults" diff --git a/examples/client-mock/frontend/src/shared b/examples/client-mock/frontend/src/shared new file mode 120000 index 0000000..b72cd26 --- /dev/null +++ b/examples/client-mock/frontend/src/shared @@ -0,0 +1 @@ +../../backend/src/shared \ No newline at end of file diff --git a/examples/client-mock/frontend/src/shared/protocols/PtlAddData.ts b/examples/client-mock/frontend/src/shared/protocols/PtlAddData.ts deleted file mode 100644 index 7f442ae..0000000 --- a/examples/client-mock/frontend/src/shared/protocols/PtlAddData.ts +++ /dev/null @@ -1,10 +0,0 @@ -// This is a demo code file -// Feel free to delete it - -export interface ReqAddData { - content: string; -} - -export interface ResAddData { - time: Date -} \ No newline at end of file diff --git a/examples/client-mock/frontend/src/shared/protocols/PtlGetData.ts b/examples/client-mock/frontend/src/shared/protocols/PtlGetData.ts deleted file mode 100644 index 8ac35a7..0000000 --- a/examples/client-mock/frontend/src/shared/protocols/PtlGetData.ts +++ /dev/null @@ -1,13 +0,0 @@ -// This is a demo code file -// Feel free to delete it - -export interface ReqGetData { - -} - -export interface ResGetData { - data: { - content: string, - time: Date - }[] -} \ No newline at end of file diff --git a/examples/client-mock/frontend/src/shared/protocols/serviceProto.ts b/examples/client-mock/frontend/src/shared/protocols/serviceProto.ts deleted file mode 100644 index e7207a9..0000000 --- a/examples/client-mock/frontend/src/shared/protocols/serviceProto.ts +++ /dev/null @@ -1,98 +0,0 @@ -import { ServiceProto } from 'tsrpc-proto'; -import { ReqAddData, ResAddData } from './PtlAddData'; -import { ReqGetData, ResGetData } from './PtlGetData'; - -// This is a demo service proto file (auto generated) -// Feel free to delete it - -export interface ServiceType { - api: { - "AddData": { - req: ReqAddData, - res: ResAddData - }, - "GetData": { - req: ReqGetData, - res: ResGetData - } - }, - msg: { - - } -} - -export const serviceProto: ServiceProto = { - "version": 1, - "services": [ - { - "id": 0, - "name": "AddData", - "type": "api" - }, - { - "id": 1, - "name": "GetData", - "type": "api" - } - ], - "types": { - "PtlAddData/ReqAddData": { - "type": "Interface", - "properties": [ - { - "id": 0, - "name": "content", - "type": { - "type": "String" - } - } - ] - }, - "PtlAddData/ResAddData": { - "type": "Interface", - "properties": [ - { - "id": 0, - "name": "time", - "type": { - "type": "Date" - } - } - ] - }, - "PtlGetData/ReqGetData": { - "type": "Interface" - }, - "PtlGetData/ResGetData": { - "type": "Interface", - "properties": [ - { - "id": 0, - "name": "data", - "type": { - "type": "Array", - "elementType": { - "type": "Interface", - "properties": [ - { - "id": 0, - "name": "content", - "type": { - "type": "String" - } - }, - { - "id": 1, - "name": "time", - "type": { - "type": "Date" - } - } - ] - } - } - } - ] - } - } -}; \ No newline at end of file diff --git a/examples/cocos-creator-3.3.0/backend/package.json b/examples/cocos-creator-3.3.0/backend/package.json index 59acc2c..da02ca7 100644 --- a/examples/cocos-creator-3.3.0/backend/package.json +++ b/examples/cocos-creator-3.3.0/backend/package.json @@ -4,20 +4,20 @@ "main": "index.js", "private": true, "scripts": { - "proto": "tsrpc proto -i src/shared/protocols -o src/shared/protocols/serviceProto.ts", - "sync": "tsrpc sync --from src/shared --to ../frontend/assets/scripts/shared", - "api": "tsrpc api -i src/shared/protocols/serviceProto.ts -o src/api", - "dev": "onchange \"src/**/*.ts\" -i -k -- ts-node \"src/index.ts\"", - "build": "tsrpc build" + "proto": "tsrpc proto --config tsrpc.config.ts", + "sync": "tsrpc sync --config tsrpc.config.ts", + "api": "tsrpc api --config tsrpc.config.ts", + "dev": "tsrpc dev --config tsrpc.config.ts", + "build": "tsrpc build --config tsrpc.config.ts" }, "devDependencies": { - "@types/node": "^15.12.3", + "@types/node": "^15.14.9", "onchange": "^7.1.0", "ts-node": "^9.1.1", - "tsrpc-cli": "^2.0.3", - "typescript": "^4.3.4" + "tsrpc-cli": "^2.0.8", + "typescript": "^4.4.3" }, "dependencies": { - "tsrpc": "^3.0.2" + "tsrpc": "^3.0.9" } } diff --git a/examples/cocos-creator-3.3.0/frontend/assets/scripts/shared/protocols.meta b/examples/cocos-creator-3.3.0/backend/src/shared/protocols.meta similarity index 77% rename from examples/cocos-creator-3.3.0/frontend/assets/scripts/shared/protocols.meta rename to examples/cocos-creator-3.3.0/backend/src/shared/protocols.meta index 79ab5da..bee9264 100644 --- a/examples/cocos-creator-3.3.0/frontend/assets/scripts/shared/protocols.meta +++ b/examples/cocos-creator-3.3.0/backend/src/shared/protocols.meta @@ -2,7 +2,7 @@ "ver": "1.1.0", "importer": "directory", "imported": true, - "uuid": "ba5a8782-c57d-437b-9371-4441de673229", + "uuid": "40721700-8121-4c1e-be92-c90e93cdc4c8", "files": [], "subMetas": {}, "userData": { diff --git a/examples/cocos-creator-3.3.0/frontend/assets/scripts/shared/protocols/MsgChat.ts.meta b/examples/cocos-creator-3.3.0/backend/src/shared/protocols/MsgChat.ts.meta similarity index 70% rename from examples/cocos-creator-3.3.0/frontend/assets/scripts/shared/protocols/MsgChat.ts.meta rename to examples/cocos-creator-3.3.0/backend/src/shared/protocols/MsgChat.ts.meta index 2ea2a5e..09f623e 100644 --- a/examples/cocos-creator-3.3.0/frontend/assets/scripts/shared/protocols/MsgChat.ts.meta +++ b/examples/cocos-creator-3.3.0/backend/src/shared/protocols/MsgChat.ts.meta @@ -2,7 +2,7 @@ "ver": "4.0.22", "importer": "typescript", "imported": true, - "uuid": "bd48404c-a47a-4bbc-b177-19352bd570bf", + "uuid": "43723a09-6be4-404b-a21a-22ad675d0e58", "files": [], "subMetas": {}, "userData": {} diff --git a/examples/cocos-creator-3.3.0/frontend/assets/scripts/shared/protocols/PtlSend.ts.meta b/examples/cocos-creator-3.3.0/backend/src/shared/protocols/PtlSend.ts.meta similarity index 70% rename from examples/cocos-creator-3.3.0/frontend/assets/scripts/shared/protocols/PtlSend.ts.meta rename to examples/cocos-creator-3.3.0/backend/src/shared/protocols/PtlSend.ts.meta index 7ce3e35..625242f 100644 --- a/examples/cocos-creator-3.3.0/frontend/assets/scripts/shared/protocols/PtlSend.ts.meta +++ b/examples/cocos-creator-3.3.0/backend/src/shared/protocols/PtlSend.ts.meta @@ -2,7 +2,7 @@ "ver": "4.0.22", "importer": "typescript", "imported": true, - "uuid": "2a458e30-4c4a-4f1a-9aff-05ea0bdf0ab6", + "uuid": "48e989fd-b5a5-4a5b-ac68-71d7f7f3d8ee", "files": [], "subMetas": {}, "userData": {} diff --git a/examples/cocos-creator-3.3.0/frontend/assets/scripts/shared/protocols/serviceProto.ts.meta b/examples/cocos-creator-3.3.0/backend/src/shared/protocols/serviceProto.ts.meta similarity index 70% rename from examples/cocos-creator-3.3.0/frontend/assets/scripts/shared/protocols/serviceProto.ts.meta rename to examples/cocos-creator-3.3.0/backend/src/shared/protocols/serviceProto.ts.meta index 906b420..ca3cf01 100644 --- a/examples/cocos-creator-3.3.0/frontend/assets/scripts/shared/protocols/serviceProto.ts.meta +++ b/examples/cocos-creator-3.3.0/backend/src/shared/protocols/serviceProto.ts.meta @@ -2,7 +2,7 @@ "ver": "4.0.22", "importer": "typescript", "imported": true, - "uuid": "56f77762-3150-4a83-ab4a-15025fd73ade", + "uuid": "aeef551d-77fd-412f-be4b-4ea615a24639", "files": [], "subMetas": {}, "userData": {} diff --git a/examples/cocos-creator-3.3.0/backend/tsrpc.config.ts b/examples/cocos-creator-3.3.0/backend/tsrpc.config.ts new file mode 100644 index 0000000..c96a16a --- /dev/null +++ b/examples/cocos-creator-3.3.0/backend/tsrpc.config.ts @@ -0,0 +1,36 @@ +import { TsrpcConfig } from 'tsrpc-cli'; + +const tsrpcConf: TsrpcConfig = { + // Generate ServiceProto + proto: [ + { + ptlDir: 'src/shared/protocols', // Protocol dir + output: 'src/shared/protocols/serviceProto.ts', // Path for generated ServiceProto + apiDir: 'src/api' // API dir + } + ], + // Sync shared code + sync: [ + { + from: 'src/shared', + to: '../frontend/assets/scripts/shared', + type: 'symlink' // Change this to 'copy' if your environment not support symlink + } + ], + // Dev server + dev: { + autoProto: true, // Auto regenerate proto + autoSync: true, // Auto sync when file changed + autoApi: true, // Auto create API when ServiceProto updated + watch: 'src', // Restart dev server when these files changed + entry: 'src/index.ts', // Dev server command: node -r ts-node/register {entry} + }, + // Build config + build: { + autoProto: true, // Auto generate proto before build + autoSync: true, // Auto sync before build + autoApi: true, // Auto generate API before build + outDir: 'dist', // Clean this dir before build + } +} +export default tsrpcConf; \ No newline at end of file diff --git a/examples/cocos-creator-3.3.0/frontend/assets/scripts/shared b/examples/cocos-creator-3.3.0/frontend/assets/scripts/shared new file mode 120000 index 0000000..4f09031 --- /dev/null +++ b/examples/cocos-creator-3.3.0/frontend/assets/scripts/shared @@ -0,0 +1 @@ +../../../backend/src/shared \ No newline at end of file diff --git a/examples/cocos-creator-3.3.0/frontend/assets/scripts/shared/protocols/MsgChat.ts b/examples/cocos-creator-3.3.0/frontend/assets/scripts/shared/protocols/MsgChat.ts deleted file mode 100644 index 4912efe..0000000 --- a/examples/cocos-creator-3.3.0/frontend/assets/scripts/shared/protocols/MsgChat.ts +++ /dev/null @@ -1,4 +0,0 @@ -export interface MsgChat { - content: string, - time: Date -} \ No newline at end of file diff --git a/examples/cocos-creator-3.3.0/frontend/assets/scripts/shared/protocols/PtlSend.ts b/examples/cocos-creator-3.3.0/frontend/assets/scripts/shared/protocols/PtlSend.ts deleted file mode 100644 index ed2505d..0000000 --- a/examples/cocos-creator-3.3.0/frontend/assets/scripts/shared/protocols/PtlSend.ts +++ /dev/null @@ -1,7 +0,0 @@ -export interface ReqSend { - content: string -} - -export interface ResSend { - time: Date -} \ No newline at end of file diff --git a/examples/cocos-creator-3.3.0/frontend/assets/scripts/shared/protocols/serviceProto.ts b/examples/cocos-creator-3.3.0/frontend/assets/scripts/shared/protocols/serviceProto.ts deleted file mode 100644 index d007337..0000000 --- a/examples/cocos-creator-3.3.0/frontend/assets/scripts/shared/protocols/serviceProto.ts +++ /dev/null @@ -1,75 +0,0 @@ -import { ServiceProto } from 'tsrpc-proto'; -import { MsgChat } from './MsgChat'; -import { ReqSend, ResSend } from './PtlSend'; - -export interface ServiceType { - api: { - "Send": { - req: ReqSend, - res: ResSend - } - }, - msg: { - "Chat": MsgChat - } -} - -export const serviceProto: ServiceProto = { - "services": [ - { - "id": 0, - "name": "Chat", - "type": "msg" - }, - { - "id": 1, - "name": "Send", - "type": "api" - } - ], - "types": { - "MsgChat/MsgChat": { - "type": "Interface", - "properties": [ - { - "id": 0, - "name": "content", - "type": { - "type": "String" - } - }, - { - "id": 1, - "name": "time", - "type": { - "type": "Date" - } - } - ] - }, - "PtlSend/ReqSend": { - "type": "Interface", - "properties": [ - { - "id": 0, - "name": "content", - "type": { - "type": "String" - } - } - ] - }, - "PtlSend/ResSend": { - "type": "Interface", - "properties": [ - { - "id": 0, - "name": "time", - "type": { - "type": "Date" - } - } - ] - } - } -}; \ No newline at end of file diff --git a/examples/cocos-creator-3.3.0/frontend/package.json b/examples/cocos-creator-3.3.0/frontend/package.json index 6e74670..6d8b270 100755 --- a/examples/cocos-creator-3.3.0/frontend/package.json +++ b/examples/cocos-creator-3.3.0/frontend/package.json @@ -4,7 +4,7 @@ "uuid": "cd1e2fff-2ab5-4407-b917-e60b25207723", "version": "3.3.0", "dependencies": { - "tsrpc-browser": "^3.0.6", + "tsrpc-browser": "^3.0.7", "tsrpc-miniapp": "^3.0.6" } } diff --git a/examples/cocos-creator-3.3.0/frontend/profiles/v2/packages/scene.json b/examples/cocos-creator-3.3.0/frontend/profiles/v2/packages/scene.json index fea0cd6..0126541 100644 --- a/examples/cocos-creator-3.3.0/frontend/profiles/v2/packages/scene.json +++ b/examples/cocos-creator-3.3.0/frontend/profiles/v2/packages/scene.json @@ -48,8 +48,8 @@ }, "86c03e47-dc7e-4335-92f0-cf39fcd2462e": { "position": { - "x": 807.1672726448774, - "y": 621.6458364416596, + "x": 1061.8571855907594, + "y": 54.22598603125158, "z": 5000 }, "rotation": { @@ -66,6 +66,6 @@ } }, "camera-uuids": [ - "86c03e47-dc7e-4335-92f0-cf39fcd2462e" + "f46876e4-e81b-4931-b493-6d367be385e7" ] } diff --git a/examples/cocos-creator-3.3.0/frontend/settings/v2/packages/cocos-service.json b/examples/cocos-creator-3.3.0/frontend/settings/v2/packages/cocos-service.json index 2e128b1..a2b00f4 100644 --- a/examples/cocos-creator-3.3.0/frontend/settings/v2/packages/cocos-service.json +++ b/examples/cocos-creator-3.3.0/frontend/settings/v2/packages/cocos-service.json @@ -1,6 +1,6 @@ { "game": { - "name": "UNKNOW GAME", + "name": "未知游戏", "app_id": "UNKNOW", "c_id": "0" }, diff --git a/examples/custom-http-res/package.json b/examples/custom-http-res/package.json index 1669f31..4efc99f 100644 --- a/examples/custom-http-res/package.json +++ b/examples/custom-http-res/package.json @@ -4,23 +4,23 @@ "main": "index.js", "private": true, "scripts": { - "proto": "tsrpc proto -i src/shared/protocols -o src/shared/protocols/serviceProto.ts", - "sync": "tsrpc sync --from src/shared --to ../frontend/src/shared", - "api": "tsrpc api -i src/shared/protocols/serviceProto.ts -o src/api", - "dev": "onchange \"src/**/*.ts\" -i -k -- ts-node \"src/index.ts\"", + "proto": "tsrpc proto --config tsrpc.config.ts", + "sync": "tsrpc sync --config tsrpc.config.ts", + "api": "tsrpc api --config tsrpc.config.ts", + "dev": "tsrpc dev --config tsrpc.config.ts", "test": "mocha test/**/*.test.ts", - "build": "tsrpc build" + "build": "tsrpc build --config tsrpc.config.ts" }, "devDependencies": { - "@types/mocha": "^8.2.2", - "@types/node": "^15.12.5", - "mocha": "^9.0.1", + "@types/mocha": "^8.2.3", + "@types/node": "^15.14.9", + "mocha": "^9.1.2", "onchange": "^7.1.0", - "ts-node": "^10.0.0", - "tsrpc-cli": "^2.0.3", - "typescript": "^4.3.4" + "ts-node": "^10.2.1", + "tsrpc-cli": "^2.0.8", + "typescript": "^4.4.3" }, "dependencies": { - "tsrpc": "^3.0.4" + "tsrpc": "^3.0.9" } } diff --git a/examples/custom-http-res/src/index.ts b/examples/custom-http-res/src/index.ts index ba933ad..ef36fd1 100644 --- a/examples/custom-http-res/src/index.ts +++ b/examples/custom-http-res/src/index.ts @@ -14,13 +14,14 @@ server.flows.preRecvBufferFlow.push(async v => { let conn = v.conn as HttpConnection; if (conn.httpReq.method === 'GET') { + conn.logger.log('[GET]', conn.httpReq.url); // Static File Service if (conn.httpReq.url) { - // Check whether the file is existed + // Check if the file is existed let resFilePath = path.join('res', conn.httpReq.url) let isExisted = await fs.access(resFilePath).then(() => true).catch(() => false); - if (isExisted) { - // Response the file + if (isExisted && (await fs.stat(resFilePath)).isFile()) { + // Send the file let content = await fs.readFile(resFilePath); conn.httpRes.end(content); return undefined; diff --git a/examples/custom-http-res/tsrpc.config.ts b/examples/custom-http-res/tsrpc.config.ts new file mode 100644 index 0000000..dc654b2 --- /dev/null +++ b/examples/custom-http-res/tsrpc.config.ts @@ -0,0 +1,36 @@ +import { TsrpcConfig } from 'tsrpc-cli'; + +const tsrpcConf: TsrpcConfig = { + // Generate ServiceProto + proto: [ + { + ptlDir: 'src/shared/protocols', // Protocol dir + output: 'src/shared/protocols/serviceProto.ts', // Path for generated ServiceProto + apiDir: 'src/api' // API dir + } + ], + // Sync shared code + sync: [ + // { + // from: 'src/shared', + // to: '../frontend/src/shared', + // type: 'symlink' // Change this to 'copy' if your environment not support symlink + // } + ], + // Dev server + dev: { + autoProto: true, // Auto regenerate proto + autoSync: true, // Auto sync when file changed + autoApi: true, // Auto create API when ServiceProto updated + watch: 'src', // Restart dev server when these files changed + entry: 'src/index.ts', // Dev server command: node -r ts-node/register {entry} + }, + // Build config + build: { + autoProto: true, // Auto generate proto before build + autoSync: true, // Auto sync before build + autoApi: true, // Auto generate API before build + outDir: 'dist', // Clean this dir before build + } +} +export default tsrpcConf; \ No newline at end of file diff --git a/examples/file-upload/backend/package.json b/examples/file-upload/backend/package.json index 9510e73..cbfcfe7 100644 --- a/examples/file-upload/backend/package.json +++ b/examples/file-upload/backend/package.json @@ -4,20 +4,20 @@ "main": "index.js", "private": true, "scripts": { - "proto": "tsrpc proto -i src/shared/protocols -o src/shared/protocols/serviceProto.ts", - "sync": "tsrpc sync --from src/shared --to ../frontend/src/shared", - "api": "tsrpc api -i src/shared/protocols/serviceProto.ts -o src/api", - "dev": "onchange \"src/**/*.ts\" -i -k -- ts-node \"src/index.ts\"", - "build": "tsrpc build" + "proto": "tsrpc proto --config tsrpc.config.ts", + "sync": "tsrpc sync --config tsrpc.config.ts", + "api": "tsrpc api --config tsrpc.config.ts", + "dev": "tsrpc dev --config tsrpc.config.ts", + "build": "tsrpc build --config tsrpc.config.ts" }, "devDependencies": { - "@types/node": "^15.12.3", + "@types/node": "^15.14.9", "onchange": "^7.1.0", "ts-node": "^9.1.1", - "tsrpc-cli": "^2.0.3", - "typescript": "^4.3.4" + "tsrpc-cli": "^2.0.8", + "typescript": "^4.4.3" }, "dependencies": { - "tsrpc": "^3.0.2" + "tsrpc": "^3.0.9" } } diff --git a/examples/file-upload/backend/tsrpc.config.ts b/examples/file-upload/backend/tsrpc.config.ts new file mode 100644 index 0000000..704baed --- /dev/null +++ b/examples/file-upload/backend/tsrpc.config.ts @@ -0,0 +1,36 @@ +import { TsrpcConfig } from 'tsrpc-cli'; + +const tsrpcConf: TsrpcConfig = { + // Generate ServiceProto + proto: [ + { + ptlDir: 'src/shared/protocols', // Protocol dir + output: 'src/shared/protocols/serviceProto.ts', // Path for generated ServiceProto + apiDir: 'src/api' // API dir + } + ], + // Sync shared code + sync: [ + { + from: 'src/shared', + to: '../frontend/src/shared', + type: 'symlink' // Change this to 'copy' if your environment not support symlink + } + ], + // Dev server + dev: { + autoProto: true, // Auto regenerate proto + autoSync: true, // Auto sync when file changed + autoApi: true, // Auto create API when ServiceProto updated + watch: 'src', // Restart dev server when these files changed + entry: 'src/index.ts', // Dev server command: node -r ts-node/register {entry} + }, + // Build config + build: { + autoProto: true, // Auto generate proto before build + autoSync: true, // Auto sync before build + autoApi: true, // Auto generate API before build + outDir: 'dist', // Clean this dir before build + } +} +export default tsrpcConf; \ No newline at end of file diff --git a/examples/file-upload/frontend/package.json b/examples/file-upload/frontend/package.json index c146185..c468ee2 100644 --- a/examples/file-upload/frontend/package.json +++ b/examples/file-upload/frontend/package.json @@ -7,15 +7,15 @@ "build": "webpack --mode=production" }, "devDependencies": { - "copy-webpack-plugin": "^9.0.0", - "html-webpack-plugin": "^5.3.1", - "ts-loader": "^9.2.3", - "typescript": "^4.3.4", - "webpack": "^5.39.1", - "webpack-cli": "^4.7.2", + "copy-webpack-plugin": "^9.0.1", + "html-webpack-plugin": "^5.3.2", + "ts-loader": "^9.2.6", + "typescript": "^4.4.3", + "webpack": "^5.57.1", + "webpack-cli": "^4.9.0", "webpack-dev-server": "^3.11.2" }, "dependencies": { - "tsrpc-browser": "^3.0.3" + "tsrpc-browser": "^3.0.7" } } diff --git a/examples/file-upload/frontend/src/shared b/examples/file-upload/frontend/src/shared new file mode 120000 index 0000000..b72cd26 --- /dev/null +++ b/examples/file-upload/frontend/src/shared @@ -0,0 +1 @@ +../../backend/src/shared \ No newline at end of file diff --git a/examples/file-upload/frontend/src/shared/protocols/PtlUpload.ts b/examples/file-upload/frontend/src/shared/protocols/PtlUpload.ts deleted file mode 100644 index b5dbb54..0000000 --- a/examples/file-upload/frontend/src/shared/protocols/PtlUpload.ts +++ /dev/null @@ -1,8 +0,0 @@ -export interface ReqUpload { - fileName: string, - fileData: Uint8Array -} - -export interface ResUpload { - url: string; -} \ No newline at end of file diff --git a/examples/file-upload/frontend/src/shared/protocols/serviceProto.ts b/examples/file-upload/frontend/src/shared/protocols/serviceProto.ts deleted file mode 100644 index ed596b5..0000000 --- a/examples/file-upload/frontend/src/shared/protocols/serviceProto.ts +++ /dev/null @@ -1,59 +0,0 @@ -import { ServiceProto } from 'tsrpc-proto'; -import { ReqUpload, ResUpload } from './PtlUpload'; - -export interface ServiceType { - api: { - "Upload": { - req: ReqUpload, - res: ResUpload - } - }, - msg: { - - } -} - -export const serviceProto: ServiceProto = { - "version": 2, - "services": [ - { - "id": 0, - "name": "Upload", - "type": "api" - } - ], - "types": { - "PtlUpload/ReqUpload": { - "type": "Interface", - "properties": [ - { - "id": 0, - "name": "fileName", - "type": { - "type": "String" - } - }, - { - "id": 1, - "name": "fileData", - "type": { - "type": "Buffer", - "arrayType": "Uint8Array" - } - } - ] - }, - "PtlUpload/ResUpload": { - "type": "Interface", - "properties": [ - { - "id": 2, - "name": "url", - "type": { - "type": "String" - } - } - ] - } - } -}; \ No newline at end of file diff --git a/examples/first-api/backend/package.json b/examples/first-api/backend/package.json index 9510e73..cbfcfe7 100644 --- a/examples/first-api/backend/package.json +++ b/examples/first-api/backend/package.json @@ -4,20 +4,20 @@ "main": "index.js", "private": true, "scripts": { - "proto": "tsrpc proto -i src/shared/protocols -o src/shared/protocols/serviceProto.ts", - "sync": "tsrpc sync --from src/shared --to ../frontend/src/shared", - "api": "tsrpc api -i src/shared/protocols/serviceProto.ts -o src/api", - "dev": "onchange \"src/**/*.ts\" -i -k -- ts-node \"src/index.ts\"", - "build": "tsrpc build" + "proto": "tsrpc proto --config tsrpc.config.ts", + "sync": "tsrpc sync --config tsrpc.config.ts", + "api": "tsrpc api --config tsrpc.config.ts", + "dev": "tsrpc dev --config tsrpc.config.ts", + "build": "tsrpc build --config tsrpc.config.ts" }, "devDependencies": { - "@types/node": "^15.12.3", + "@types/node": "^15.14.9", "onchange": "^7.1.0", "ts-node": "^9.1.1", - "tsrpc-cli": "^2.0.3", - "typescript": "^4.3.4" + "tsrpc-cli": "^2.0.8", + "typescript": "^4.4.3" }, "dependencies": { - "tsrpc": "^3.0.2" + "tsrpc": "^3.0.9" } } diff --git a/examples/first-api/backend/tsrpc.config.ts b/examples/first-api/backend/tsrpc.config.ts new file mode 100644 index 0000000..704baed --- /dev/null +++ b/examples/first-api/backend/tsrpc.config.ts @@ -0,0 +1,36 @@ +import { TsrpcConfig } from 'tsrpc-cli'; + +const tsrpcConf: TsrpcConfig = { + // Generate ServiceProto + proto: [ + { + ptlDir: 'src/shared/protocols', // Protocol dir + output: 'src/shared/protocols/serviceProto.ts', // Path for generated ServiceProto + apiDir: 'src/api' // API dir + } + ], + // Sync shared code + sync: [ + { + from: 'src/shared', + to: '../frontend/src/shared', + type: 'symlink' // Change this to 'copy' if your environment not support symlink + } + ], + // Dev server + dev: { + autoProto: true, // Auto regenerate proto + autoSync: true, // Auto sync when file changed + autoApi: true, // Auto create API when ServiceProto updated + watch: 'src', // Restart dev server when these files changed + entry: 'src/index.ts', // Dev server command: node -r ts-node/register {entry} + }, + // Build config + build: { + autoProto: true, // Auto generate proto before build + autoSync: true, // Auto sync before build + autoApi: true, // Auto generate API before build + outDir: 'dist', // Clean this dir before build + } +} +export default tsrpcConf; \ No newline at end of file diff --git a/examples/first-api/frontend/package.json b/examples/first-api/frontend/package.json index c146185..c468ee2 100644 --- a/examples/first-api/frontend/package.json +++ b/examples/first-api/frontend/package.json @@ -7,15 +7,15 @@ "build": "webpack --mode=production" }, "devDependencies": { - "copy-webpack-plugin": "^9.0.0", - "html-webpack-plugin": "^5.3.1", - "ts-loader": "^9.2.3", - "typescript": "^4.3.4", - "webpack": "^5.39.1", - "webpack-cli": "^4.7.2", + "copy-webpack-plugin": "^9.0.1", + "html-webpack-plugin": "^5.3.2", + "ts-loader": "^9.2.6", + "typescript": "^4.4.3", + "webpack": "^5.57.1", + "webpack-cli": "^4.9.0", "webpack-dev-server": "^3.11.2" }, "dependencies": { - "tsrpc-browser": "^3.0.3" + "tsrpc-browser": "^3.0.7" } } diff --git a/examples/first-api/frontend/src/shared b/examples/first-api/frontend/src/shared new file mode 120000 index 0000000..b72cd26 --- /dev/null +++ b/examples/first-api/frontend/src/shared @@ -0,0 +1 @@ +../../backend/src/shared \ No newline at end of file diff --git a/examples/first-api/frontend/src/shared/protocols/PtlHello.ts b/examples/first-api/frontend/src/shared/protocols/PtlHello.ts deleted file mode 100644 index 8a46045..0000000 --- a/examples/first-api/frontend/src/shared/protocols/PtlHello.ts +++ /dev/null @@ -1,8 +0,0 @@ -export interface ReqHello { - name: string -} - -export interface ResHello { - reply: string, - time: Date -} diff --git a/examples/first-api/frontend/src/shared/protocols/serviceProto.ts b/examples/first-api/frontend/src/shared/protocols/serviceProto.ts deleted file mode 100644 index 7f9e724..0000000 --- a/examples/first-api/frontend/src/shared/protocols/serviceProto.ts +++ /dev/null @@ -1,57 +0,0 @@ -import { ServiceProto } from 'tsrpc-proto'; -import { ReqHello, ResHello } from './PtlHello'; - -export interface ServiceType { - api: { - "Hello": { - req: ReqHello, - res: ResHello - } - }, - msg: { - - } -} - -export const serviceProto: ServiceProto = { - "services": [ - { - "id": 0, - "name": "Hello", - "type": "api" - } - ], - "types": { - "PtlHello/ReqHello": { - "type": "Interface", - "properties": [ - { - "id": 0, - "name": "name", - "type": { - "type": "String" - } - } - ] - }, - "PtlHello/ResHello": { - "type": "Interface", - "properties": [ - { - "id": 0, - "name": "reply", - "type": { - "type": "String" - } - }, - { - "id": 1, - "name": "time", - "type": { - "type": "Date" - } - } - ] - } - } -}; \ No newline at end of file diff --git a/examples/layaair/backend/package.json b/examples/layaair/backend/package.json index a0e26be..9be327a 100644 --- a/examples/layaair/backend/package.json +++ b/examples/layaair/backend/package.json @@ -4,20 +4,20 @@ "main": "index.js", "private": true, "scripts": { - "proto": "tsrpc proto -i src/shared/protocols -o src/shared/protocols/serviceProto.ts", - "sync": "tsrpc sync --from src/shared --to ../frontend/src/shared", - "api": "tsrpc api -i src/shared/protocols/serviceProto.ts -o src/api", - "dev": "onchange \"src/**/*.ts\" -i -k -- ts-node \"src/index.ts\"", - "build": "tsrpc build" + "proto": "tsrpc proto --config tsrpc.config.ts", + "sync": "tsrpc sync --config tsrpc.config.ts", + "api": "tsrpc api --config tsrpc.config.ts", + "dev": "tsrpc dev --config tsrpc.config.ts", + "build": "tsrpc build --config tsrpc.config.ts" }, "devDependencies": { - "@types/node": "^15.14.1", + "@types/node": "^15.14.9", "onchange": "^7.1.0", - "ts-node": "^10.0.0", - "tsrpc-cli": "^2.0.3", - "typescript": "^4.3.5" + "ts-node": "^10.2.1", + "tsrpc-cli": "^2.0.8", + "typescript": "^4.4.3" }, "dependencies": { - "tsrpc": "^3.0.4" + "tsrpc": "^3.0.9" } } diff --git a/examples/layaair/backend/tsrpc.config.ts b/examples/layaair/backend/tsrpc.config.ts new file mode 100644 index 0000000..451cb33 --- /dev/null +++ b/examples/layaair/backend/tsrpc.config.ts @@ -0,0 +1,36 @@ +import { TsrpcConfig } from 'tsrpc-cli'; + +const tsrpcConf: TsrpcConfig = { + // Generate ServiceProto + proto: [ + { + ptlDir: 'src/shared/protocols', // Protocol dir + output: 'src/shared/protocols/serviceProto.ts', // Path for generated ServiceProto + apiDir: 'src/api' // API dir + } + ], + // Sync shared code + sync: [ + { + from: 'src/shared', + to: '../frontend/src/shared', + type: 'copy' // Change this to 'copy' if your environment not support symlink + } + ], + // Dev server + dev: { + autoProto: true, // Auto regenerate proto + autoSync: true, // Auto sync when file changed + autoApi: true, // Auto create API when ServiceProto updated + watch: 'src', // Restart dev server when these files changed + entry: 'src/index.ts', // Dev server command: node -r ts-node/register {entry} + }, + // Build config + build: { + autoProto: true, // Auto generate proto before build + autoSync: true, // Auto sync before build + autoApi: true, // Auto generate API before build + outDir: 'dist', // Clean this dir before build + } +} +export default tsrpcConf; \ No newline at end of file diff --git a/examples/layaair/frontend/package.json b/examples/layaair/frontend/package.json index 3dfc337..e3c546f 100644 --- a/examples/layaair/frontend/package.json +++ b/examples/layaair/frontend/package.json @@ -7,17 +7,17 @@ "tsrpc-laya": "index.js" }, "dependencies": { - "core-js": "^3.15.2", + "core-js": "^3.18.2", "k8w-extend-native": "^1.4.5", "k8w-linq-array": "^0.2.7", - "k8w-super-date": "^0.1.2", + "k8w-super-date": "^0.1.3", "k8w-super-object": "^0.3.0", "tsbuffer": "^2.0.4", "tsbuffer-schema": "^2.0.2", "tsbuffer-validator": "^2.0.4", - "tslib": "^2.3.0", - "tsrpc-base-client": "^1.0.6", - "tsrpc-browser": "^3.0.4", + "tslib": "^2.3.1", + "tsrpc-base-client": "^1.0.11", + "tsrpc-browser": "^3.0.7", "tsrpc-proto": "^1.3.4" }, "scripts": { diff --git a/examples/mongodb-crud/backend/package.json b/examples/mongodb-crud/backend/package.json index 4f2fa9b..2fc9dfd 100644 --- a/examples/mongodb-crud/backend/package.json +++ b/examples/mongodb-crud/backend/package.json @@ -4,27 +4,24 @@ "main": "index.js", "private": true, "scripts": { - "watch:proto": "onchange \"src/shared/protocols/**/Ptl*.ts\" -- npm run protoAndSync", - "protoAndSync": "npm run proto && npm run sync", - "proto": "tsrpc proto -i src/shared/protocols -o src/shared/protocols/serviceProto.ts", - "sync": "tsrpc sync --from src/shared --to ../frontend/src/shared", - "api": "tsrpc api -i src/shared/protocols/serviceProto.ts -o src/api", - "dev": "onchange \"src/**/*.ts\" -i -k -- ts-node \"src/index.ts\"", - "test": "mocha test/**/*.test.ts", - "build": "tsrpc build" + "proto": "tsrpc proto --config tsrpc.config.ts", + "sync": "tsrpc sync --config tsrpc.config.ts", + "api": "tsrpc api --config tsrpc.config.ts", + "dev": "tsrpc dev --config tsrpc.config.ts", + "build": "tsrpc build --config tsrpc.config.ts" }, "devDependencies": { - "@types/mocha": "^8.2.2", - "@types/mongodb": "^3.6.18", - "@types/node": "^15.12.4", - "mocha": "^9.0.1", + "@types/mocha": "^8.2.3", + "@types/mongodb": "^3.6.20", + "@types/node": "^15.14.9", + "mocha": "^9.1.2", "onchange": "^7.1.0", - "ts-node": "^10.0.0", - "tsrpc-cli": "^2.0.3", - "typescript": "^4.3.4" + "ts-node": "^10.2.1", + "tsrpc-cli": "^2.0.8", + "typescript": "^4.4.3" }, "dependencies": { - "mongodb": "^3.6.9", - "tsrpc": "^3.0.2" + "mongodb": "^3.7.2", + "tsrpc": "^3.0.9" } -} \ No newline at end of file +} diff --git a/examples/mongodb-crud/backend/tsrpc.config.ts b/examples/mongodb-crud/backend/tsrpc.config.ts new file mode 100644 index 0000000..704baed --- /dev/null +++ b/examples/mongodb-crud/backend/tsrpc.config.ts @@ -0,0 +1,36 @@ +import { TsrpcConfig } from 'tsrpc-cli'; + +const tsrpcConf: TsrpcConfig = { + // Generate ServiceProto + proto: [ + { + ptlDir: 'src/shared/protocols', // Protocol dir + output: 'src/shared/protocols/serviceProto.ts', // Path for generated ServiceProto + apiDir: 'src/api' // API dir + } + ], + // Sync shared code + sync: [ + { + from: 'src/shared', + to: '../frontend/src/shared', + type: 'symlink' // Change this to 'copy' if your environment not support symlink + } + ], + // Dev server + dev: { + autoProto: true, // Auto regenerate proto + autoSync: true, // Auto sync when file changed + autoApi: true, // Auto create API when ServiceProto updated + watch: 'src', // Restart dev server when these files changed + entry: 'src/index.ts', // Dev server command: node -r ts-node/register {entry} + }, + // Build config + build: { + autoProto: true, // Auto generate proto before build + autoSync: true, // Auto sync before build + autoApi: true, // Auto generate API before build + outDir: 'dist', // Clean this dir before build + } +} +export default tsrpcConf; \ No newline at end of file diff --git a/examples/mongodb-crud/frontend/package.json b/examples/mongodb-crud/frontend/package.json index 410cf45..de4a408 100644 --- a/examples/mongodb-crud/frontend/package.json +++ b/examples/mongodb-crud/frontend/package.json @@ -9,14 +9,14 @@ "devDependencies": { "copy-webpack-plugin": "^9.0.1", "html-webpack-plugin": "^5.3.2", - "ts-loader": "^9.2.3", - "typescript": "^4.3.4", - "webpack": "^5.40.0", - "webpack-cli": "^4.7.2", + "ts-loader": "^9.2.6", + "typescript": "^4.4.3", + "webpack": "^5.57.1", + "webpack-cli": "^4.9.0", "webpack-dev-server": "^3.11.2" }, "dependencies": { - "tsrpc-browser": "^3.0.3" + "tsrpc-browser": "^3.0.7" }, "browserslist": [ "defaults" diff --git a/examples/mongodb-crud/frontend/src/shared b/examples/mongodb-crud/frontend/src/shared new file mode 120000 index 0000000..b72cd26 --- /dev/null +++ b/examples/mongodb-crud/frontend/src/shared @@ -0,0 +1 @@ +../../backend/src/shared \ No newline at end of file diff --git a/examples/mongodb-crud/frontend/src/shared/protocols/PtlAddPost.ts b/examples/mongodb-crud/frontend/src/shared/protocols/PtlAddPost.ts deleted file mode 100644 index c4f367e..0000000 --- a/examples/mongodb-crud/frontend/src/shared/protocols/PtlAddPost.ts +++ /dev/null @@ -1,9 +0,0 @@ -import { Post } from "./models/Post"; - -export interface ReqAddPost { - newPost: Omit; -} - -export interface ResAddPost { - insertedId: string; -} \ No newline at end of file diff --git a/examples/mongodb-crud/frontend/src/shared/protocols/PtlDelPost.ts b/examples/mongodb-crud/frontend/src/shared/protocols/PtlDelPost.ts deleted file mode 100644 index 026fec7..0000000 --- a/examples/mongodb-crud/frontend/src/shared/protocols/PtlDelPost.ts +++ /dev/null @@ -1,7 +0,0 @@ -export interface ReqDelPost { - _id: string; -} - -export interface ResDelPost { - -} \ No newline at end of file diff --git a/examples/mongodb-crud/frontend/src/shared/protocols/PtlGetPost.ts b/examples/mongodb-crud/frontend/src/shared/protocols/PtlGetPost.ts deleted file mode 100644 index a6d169f..0000000 --- a/examples/mongodb-crud/frontend/src/shared/protocols/PtlGetPost.ts +++ /dev/null @@ -1,9 +0,0 @@ -import { Post } from "./models/Post"; - -export interface ReqGetPost { - _id: string; -} - -export interface ResGetPost { - post: Post; -} diff --git a/examples/mongodb-crud/frontend/src/shared/protocols/PtlUpdatePost.ts b/examples/mongodb-crud/frontend/src/shared/protocols/PtlUpdatePost.ts deleted file mode 100644 index 20ccc71..0000000 --- a/examples/mongodb-crud/frontend/src/shared/protocols/PtlUpdatePost.ts +++ /dev/null @@ -1,9 +0,0 @@ -import { Post } from "./models/Post"; - -export interface ReqUpdatePost { - update: { _id: string } & Partial>; -} - -export interface ResUpdatePost { - matchedCount: number; -} \ No newline at end of file diff --git a/examples/mongodb-crud/frontend/src/shared/protocols/models/Post.ts b/examples/mongodb-crud/frontend/src/shared/protocols/models/Post.ts deleted file mode 100644 index 67b21e2..0000000 --- a/examples/mongodb-crud/frontend/src/shared/protocols/models/Post.ts +++ /dev/null @@ -1,17 +0,0 @@ -export interface Post { - _id: string; - author: string; - title: string; - content: string; - visitedNum: number; - - create: { - uid: string; - time: Date; - } - - update?: { - uid: string, - time: Date - } -} \ No newline at end of file diff --git a/examples/mongodb-crud/frontend/src/shared/protocols/serviceProto.ts b/examples/mongodb-crud/frontend/src/shared/protocols/serviceProto.ts deleted file mode 100644 index 6b3a764..0000000 --- a/examples/mongodb-crud/frontend/src/shared/protocols/serviceProto.ts +++ /dev/null @@ -1,276 +0,0 @@ -import { ServiceProto } from 'tsrpc-proto'; -import { ReqAddPost, ResAddPost } from './PtlAddPost'; -import { ReqDelPost, ResDelPost } from './PtlDelPost'; -import { ReqGetPost, ResGetPost } from './PtlGetPost'; -import { ReqUpdatePost, ResUpdatePost } from './PtlUpdatePost'; - -export interface ServiceType { - api: { - "AddPost": { - req: ReqAddPost, - res: ResAddPost - }, - "DelPost": { - req: ReqDelPost, - res: ResDelPost - }, - "GetPost": { - req: ReqGetPost, - res: ResGetPost - }, - "UpdatePost": { - req: ReqUpdatePost, - res: ResUpdatePost - } - }, - msg: { - - } -} - -export const serviceProto: ServiceProto = { - "version": 16, - "services": [ - { - "id": 0, - "name": "AddPost", - "type": "api" - }, - { - "id": 1, - "name": "DelPost", - "type": "api" - }, - { - "id": 2, - "name": "GetPost", - "type": "api" - }, - { - "id": 3, - "name": "UpdatePost", - "type": "api" - } - ], - "types": { - "PtlAddPost/ReqAddPost": { - "type": "Interface", - "properties": [ - { - "id": 0, - "name": "newPost", - "type": { - "target": { - "type": "Reference", - "target": "models/Post/Post" - }, - "keys": [ - "_id", - "create", - "update", - "visitedNum" - ], - "type": "Omit" - } - } - ] - }, - "models/Post/Post": { - "type": "Interface", - "properties": [ - { - "id": 0, - "name": "_id", - "type": { - "type": "String" - } - }, - { - "id": 1, - "name": "author", - "type": { - "type": "String" - } - }, - { - "id": 2, - "name": "title", - "type": { - "type": "String" - } - }, - { - "id": 3, - "name": "content", - "type": { - "type": "String" - } - }, - { - "id": 4, - "name": "visitedNum", - "type": { - "type": "Number" - } - }, - { - "id": 5, - "name": "create", - "type": { - "type": "Interface", - "properties": [ - { - "id": 0, - "name": "uid", - "type": { - "type": "String" - } - }, - { - "id": 1, - "name": "time", - "type": { - "type": "Date" - } - } - ] - } - }, - { - "id": 6, - "name": "update", - "type": { - "type": "Interface", - "properties": [ - { - "id": 0, - "name": "uid", - "type": { - "type": "String" - } - }, - { - "id": 1, - "name": "time", - "type": { - "type": "Date" - } - } - ] - }, - "optional": true - } - ] - }, - "PtlAddPost/ResAddPost": { - "type": "Interface", - "properties": [ - { - "id": 0, - "name": "insertedId", - "type": { - "type": "String" - } - } - ] - }, - "PtlDelPost/ReqDelPost": { - "type": "Interface", - "properties": [ - { - "id": 0, - "name": "_id", - "type": { - "type": "String" - } - } - ] - }, - "PtlDelPost/ResDelPost": { - "type": "Interface" - }, - "PtlGetPost/ReqGetPost": { - "type": "Interface", - "properties": [ - { - "id": 0, - "name": "_id", - "type": { - "type": "String" - } - } - ] - }, - "PtlGetPost/ResGetPost": { - "type": "Interface", - "properties": [ - { - "id": 0, - "name": "post", - "type": { - "type": "Reference", - "target": "models/Post/Post" - } - } - ] - }, - "PtlUpdatePost/ReqUpdatePost": { - "type": "Interface", - "properties": [ - { - "id": 0, - "name": "update", - "type": { - "type": "Intersection", - "members": [ - { - "id": 1, - "type": { - "type": "Interface", - "properties": [ - { - "id": 0, - "name": "_id", - "type": { - "type": "String" - } - } - ] - } - }, - { - "id": 3, - "type": { - "type": "Partial", - "target": { - "target": { - "type": "Reference", - "target": "models/Post/Post" - }, - "keys": [ - "title", - "content" - ], - "type": "Pick" - } - } - } - ] - } - } - ] - }, - "PtlUpdatePost/ResUpdatePost": { - "type": "Interface", - "properties": [ - { - "id": 0, - "name": "matchedCount", - "type": { - "type": "Number" - } - } - ] - } - } -}; \ No newline at end of file diff --git a/examples/session-and-cookie/backend/package.json b/examples/session-and-cookie/backend/package.json index b6bf5ee..c851e7f 100644 --- a/examples/session-and-cookie/backend/package.json +++ b/examples/session-and-cookie/backend/package.json @@ -4,22 +4,22 @@ "main": "index.js", "private": true, "scripts": { - "proto": "tsrpc proto -i src/shared/protocols -o src/shared/protocols/serviceProto.ts", - "sync": "tsrpc sync --from src/shared --to ../frontend/src/shared", - "api": "tsrpc api -i src/shared/protocols/serviceProto.ts -o src/api", - "dev": "onchange \"src/**/*.ts\" -i -k -- ts-node \"src/index.ts\"", - "build": "tsrpc build" + "proto": "tsrpc proto --config tsrpc.config.ts", + "sync": "tsrpc sync --config tsrpc.config.ts", + "api": "tsrpc api --config tsrpc.config.ts", + "dev": "tsrpc dev --config tsrpc.config.ts", + "build": "tsrpc build --config tsrpc.config.ts" }, "devDependencies": { - "@types/node": "^15.12.3", - "@types/uuid": "^8.3.0", + "@types/node": "^15.14.9", + "@types/uuid": "^8.3.1", "onchange": "^7.1.0", "ts-node": "^9.1.1", - "tsrpc-cli": "^2.0.3", - "typescript": "^4.3.4" + "tsrpc-cli": "^2.0.8", + "typescript": "^4.4.3" }, "dependencies": { - "tsrpc": "^3.0.2", + "tsrpc": "^3.0.9", "uuid": "^8.3.2" } } diff --git a/examples/session-and-cookie/backend/tsrpc.config.ts b/examples/session-and-cookie/backend/tsrpc.config.ts new file mode 100644 index 0000000..704baed --- /dev/null +++ b/examples/session-and-cookie/backend/tsrpc.config.ts @@ -0,0 +1,36 @@ +import { TsrpcConfig } from 'tsrpc-cli'; + +const tsrpcConf: TsrpcConfig = { + // Generate ServiceProto + proto: [ + { + ptlDir: 'src/shared/protocols', // Protocol dir + output: 'src/shared/protocols/serviceProto.ts', // Path for generated ServiceProto + apiDir: 'src/api' // API dir + } + ], + // Sync shared code + sync: [ + { + from: 'src/shared', + to: '../frontend/src/shared', + type: 'symlink' // Change this to 'copy' if your environment not support symlink + } + ], + // Dev server + dev: { + autoProto: true, // Auto regenerate proto + autoSync: true, // Auto sync when file changed + autoApi: true, // Auto create API when ServiceProto updated + watch: 'src', // Restart dev server when these files changed + entry: 'src/index.ts', // Dev server command: node -r ts-node/register {entry} + }, + // Build config + build: { + autoProto: true, // Auto generate proto before build + autoSync: true, // Auto sync before build + autoApi: true, // Auto generate API before build + outDir: 'dist', // Clean this dir before build + } +} +export default tsrpcConf; \ No newline at end of file diff --git a/examples/session-and-cookie/frontend/package.json b/examples/session-and-cookie/frontend/package.json index 6baf8aa..334dc46 100644 --- a/examples/session-and-cookie/frontend/package.json +++ b/examples/session-and-cookie/frontend/package.json @@ -7,15 +7,15 @@ "build": "webpack --mode=production" }, "devDependencies": { - "copy-webpack-plugin": "^9.0.0", - "html-webpack-plugin": "^5.3.1", - "ts-loader": "^9.2.3", - "typescript": "^4.3.4", - "webpack": "^5.39.1", - "webpack-cli": "^4.7.2", + "copy-webpack-plugin": "^9.0.1", + "html-webpack-plugin": "^5.3.2", + "ts-loader": "^9.2.6", + "typescript": "^4.4.3", + "webpack": "^5.57.1", + "webpack-cli": "^4.9.0", "webpack-dev-server": "^3.11.2" }, "dependencies": { - "tsrpc-browser": "^3.0.3" + "tsrpc-browser": "^3.0.7" } } diff --git a/examples/session-and-cookie/frontend/src/shared b/examples/session-and-cookie/frontend/src/shared new file mode 120000 index 0000000..b72cd26 --- /dev/null +++ b/examples/session-and-cookie/frontend/src/shared @@ -0,0 +1 @@ +../../backend/src/shared \ No newline at end of file diff --git a/examples/session-and-cookie/frontend/src/shared/protocols/PtlClear.ts b/examples/session-and-cookie/frontend/src/shared/protocols/PtlClear.ts deleted file mode 100644 index bd4af9b..0000000 --- a/examples/session-and-cookie/frontend/src/shared/protocols/PtlClear.ts +++ /dev/null @@ -1,9 +0,0 @@ -import { BaseRequest, BaseResponse } from './base'; - -export interface ReqClear extends BaseRequest { - -} - -export interface ResClear extends BaseResponse { - -} \ No newline at end of file diff --git a/examples/session-and-cookie/frontend/src/shared/protocols/PtlSetCookie.ts b/examples/session-and-cookie/frontend/src/shared/protocols/PtlSetCookie.ts deleted file mode 100644 index 394135d..0000000 --- a/examples/session-and-cookie/frontend/src/shared/protocols/PtlSetCookie.ts +++ /dev/null @@ -1,9 +0,0 @@ -import { BaseRequest, BaseResponse } from './base' - -export interface ReqSetCookie extends BaseRequest { - -} - -export interface ResSetCookie extends BaseResponse { - -} \ No newline at end of file diff --git a/examples/session-and-cookie/frontend/src/shared/protocols/PtlSetSession.ts b/examples/session-and-cookie/frontend/src/shared/protocols/PtlSetSession.ts deleted file mode 100644 index a28ff99..0000000 --- a/examples/session-and-cookie/frontend/src/shared/protocols/PtlSetSession.ts +++ /dev/null @@ -1,9 +0,0 @@ -import { BaseRequest, BaseResponse } from './base' - -export interface ReqSetSession extends BaseRequest { - -} - -export interface ResSetSession extends BaseResponse { - -} \ No newline at end of file diff --git a/examples/session-and-cookie/frontend/src/shared/protocols/PtlTest.ts b/examples/session-and-cookie/frontend/src/shared/protocols/PtlTest.ts deleted file mode 100644 index 9bbb40d..0000000 --- a/examples/session-and-cookie/frontend/src/shared/protocols/PtlTest.ts +++ /dev/null @@ -1,10 +0,0 @@ -import { BaseRequest, BaseResponse } from './base'; - -export interface ReqTest extends BaseRequest { - -} - -export interface ResTest extends BaseResponse { - // From Session - testSession?: string -} \ No newline at end of file diff --git a/examples/session-and-cookie/frontend/src/shared/protocols/base.ts b/examples/session-and-cookie/frontend/src/shared/protocols/base.ts deleted file mode 100644 index 390cc0f..0000000 --- a/examples/session-and-cookie/frontend/src/shared/protocols/base.ts +++ /dev/null @@ -1,12 +0,0 @@ -export interface BaseRequest { - __cookie?: Cookie; -} - -export interface BaseResponse { - __cookie?: Cookie; -} - -export interface Cookie { - sessionId?: string, - [key: string]: any -} \ No newline at end of file diff --git a/examples/session-and-cookie/frontend/src/shared/protocols/serviceProto.ts b/examples/session-and-cookie/frontend/src/shared/protocols/serviceProto.ts deleted file mode 100644 index 6f2b855..0000000 --- a/examples/session-and-cookie/frontend/src/shared/protocols/serviceProto.ts +++ /dev/null @@ -1,209 +0,0 @@ -import { ServiceProto } from 'tsrpc-proto'; -import { ReqClear, ResClear } from './PtlClear'; -import { ReqSetCookie, ResSetCookie } from './PtlSetCookie'; -import { ReqSetSession, ResSetSession } from './PtlSetSession'; -import { ReqTest, ResTest } from './PtlTest'; - -export interface ServiceType { - api: { - "Clear": { - req: ReqClear, - res: ResClear - }, - "SetCookie": { - req: ReqSetCookie, - res: ResSetCookie - }, - "SetSession": { - req: ReqSetSession, - res: ResSetSession - }, - "Test": { - req: ReqTest, - res: ResTest - } - }, - msg: { - - } -} - -export const serviceProto: ServiceProto = { - "services": [ - { - "id": 0, - "name": "Clear", - "type": "api" - }, - { - "id": 1, - "name": "SetCookie", - "type": "api" - }, - { - "id": 2, - "name": "SetSession", - "type": "api" - }, - { - "id": 3, - "name": "Test", - "type": "api" - } - ], - "types": { - "PtlClear/ReqClear": { - "type": "Interface", - "extends": [ - { - "id": 0, - "type": { - "type": "Reference", - "target": "base/BaseRequest" - } - } - ] - }, - "base/BaseRequest": { - "type": "Interface", - "properties": [ - { - "id": 0, - "name": "__cookie", - "type": { - "type": "Reference", - "target": "base/Cookie" - }, - "optional": true - } - ] - }, - "base/Cookie": { - "type": "Interface", - "properties": [ - { - "id": 0, - "name": "sessionId", - "type": { - "type": "String" - }, - "optional": true - } - ], - "indexSignature": { - "keyType": "String", - "type": { - "type": "Any" - } - } - }, - "PtlClear/ResClear": { - "type": "Interface", - "extends": [ - { - "id": 0, - "type": { - "type": "Reference", - "target": "base/BaseResponse" - } - } - ] - }, - "base/BaseResponse": { - "type": "Interface", - "properties": [ - { - "id": 0, - "name": "__cookie", - "type": { - "type": "Reference", - "target": "base/Cookie" - }, - "optional": true - } - ] - }, - "PtlSetCookie/ReqSetCookie": { - "type": "Interface", - "extends": [ - { - "id": 0, - "type": { - "type": "Reference", - "target": "base/BaseRequest" - } - } - ] - }, - "PtlSetCookie/ResSetCookie": { - "type": "Interface", - "extends": [ - { - "id": 0, - "type": { - "type": "Reference", - "target": "base/BaseResponse" - } - } - ] - }, - "PtlSetSession/ReqSetSession": { - "type": "Interface", - "extends": [ - { - "id": 0, - "type": { - "type": "Reference", - "target": "base/BaseRequest" - } - } - ] - }, - "PtlSetSession/ResSetSession": { - "type": "Interface", - "extends": [ - { - "id": 0, - "type": { - "type": "Reference", - "target": "base/BaseResponse" - } - } - ] - }, - "PtlTest/ReqTest": { - "type": "Interface", - "extends": [ - { - "id": 0, - "type": { - "type": "Reference", - "target": "base/BaseRequest" - } - } - ] - }, - "PtlTest/ResTest": { - "type": "Interface", - "extends": [ - { - "id": 0, - "type": { - "type": "Reference", - "target": "base/BaseResponse" - } - } - ], - "properties": [ - { - "id": 0, - "name": "testSession", - "type": { - "type": "String" - }, - "optional": true - } - ] - } - } -}; \ No newline at end of file diff --git a/examples/transfer-encryption/backend/package.json b/examples/transfer-encryption/backend/package.json index 801c506..de48fc3 100644 --- a/examples/transfer-encryption/backend/package.json +++ b/examples/transfer-encryption/backend/package.json @@ -4,20 +4,20 @@ "main": "index.js", "private": true, "scripts": { - "proto": "tsrpc proto -i src/shared/protocols -o src/shared/protocols/serviceProto.ts", - "sync": "tsrpc sync --from src/shared --to ../frontend/src/shared", - "api": "tsrpc api -i src/shared/protocols/serviceProto.ts -o src/api", - "dev": "onchange \"src/**/*.ts\" -i -k -- ts-node \"src/index.ts\"", - "build": "tsrpc build" + "proto": "tsrpc proto --config tsrpc.config.ts", + "sync": "tsrpc sync --config tsrpc.config.ts", + "api": "tsrpc api --config tsrpc.config.ts", + "dev": "tsrpc dev --config tsrpc.config.ts", + "build": "tsrpc build --config tsrpc.config.ts" }, "devDependencies": { - "@types/node": "^15.12.5", + "@types/node": "^15.14.9", "onchange": "^7.1.0", - "ts-node": "^10.0.0", - "tsrpc-cli": "^2.0.3", - "typescript": "^4.3.4" + "ts-node": "^10.2.1", + "tsrpc-cli": "^2.0.8", + "typescript": "^4.4.3" }, "dependencies": { - "tsrpc": "^3.0.4" + "tsrpc": "^3.0.9" } } diff --git a/examples/transfer-encryption/backend/tsrpc.config.ts b/examples/transfer-encryption/backend/tsrpc.config.ts new file mode 100644 index 0000000..704baed --- /dev/null +++ b/examples/transfer-encryption/backend/tsrpc.config.ts @@ -0,0 +1,36 @@ +import { TsrpcConfig } from 'tsrpc-cli'; + +const tsrpcConf: TsrpcConfig = { + // Generate ServiceProto + proto: [ + { + ptlDir: 'src/shared/protocols', // Protocol dir + output: 'src/shared/protocols/serviceProto.ts', // Path for generated ServiceProto + apiDir: 'src/api' // API dir + } + ], + // Sync shared code + sync: [ + { + from: 'src/shared', + to: '../frontend/src/shared', + type: 'symlink' // Change this to 'copy' if your environment not support symlink + } + ], + // Dev server + dev: { + autoProto: true, // Auto regenerate proto + autoSync: true, // Auto sync when file changed + autoApi: true, // Auto create API when ServiceProto updated + watch: 'src', // Restart dev server when these files changed + entry: 'src/index.ts', // Dev server command: node -r ts-node/register {entry} + }, + // Build config + build: { + autoProto: true, // Auto generate proto before build + autoSync: true, // Auto sync before build + autoApi: true, // Auto generate API before build + outDir: 'dist', // Clean this dir before build + } +} +export default tsrpcConf; \ No newline at end of file diff --git a/examples/transfer-encryption/frontend/package.json b/examples/transfer-encryption/frontend/package.json index 4dc52af..e391060 100644 --- a/examples/transfer-encryption/frontend/package.json +++ b/examples/transfer-encryption/frontend/package.json @@ -9,14 +9,14 @@ "devDependencies": { "copy-webpack-plugin": "^9.0.1", "html-webpack-plugin": "^5.3.2", - "ts-loader": "^9.2.3", - "typescript": "^4.3.4", - "webpack": "^5.41.0", - "webpack-cli": "^4.7.2", + "ts-loader": "^9.2.6", + "typescript": "^4.4.3", + "webpack": "^5.57.1", + "webpack-cli": "^4.9.0", "webpack-dev-server": "^3.11.2" }, "dependencies": { - "tsrpc-browser": "^3.0.4" + "tsrpc-browser": "^3.0.7" }, "browserslist": [ "defaults" diff --git a/examples/transfer-encryption/frontend/src/shared b/examples/transfer-encryption/frontend/src/shared new file mode 120000 index 0000000..b72cd26 --- /dev/null +++ b/examples/transfer-encryption/frontend/src/shared @@ -0,0 +1 @@ +../../backend/src/shared \ No newline at end of file diff --git a/examples/transfer-encryption/frontend/src/shared/models/EncryptUtil.ts b/examples/transfer-encryption/frontend/src/shared/models/EncryptUtil.ts deleted file mode 100644 index 734b512..0000000 --- a/examples/transfer-encryption/frontend/src/shared/models/EncryptUtil.ts +++ /dev/null @@ -1,17 +0,0 @@ -export class EncryptUtil { - - static encrypt(buf: Uint8Array): Uint8Array { - for (let i = 0; i < buf.length; ++i) { - buf[i] -= 1; - } - return buf; - } - - static decrypt(buf: Uint8Array): Uint8Array { - for (let i = 0; i < buf.length; ++i) { - buf[i] += 1; - } - return buf; - } - -} \ No newline at end of file diff --git a/examples/transfer-encryption/frontend/src/shared/protocols/PtlAddData.ts b/examples/transfer-encryption/frontend/src/shared/protocols/PtlAddData.ts deleted file mode 100644 index 7f442ae..0000000 --- a/examples/transfer-encryption/frontend/src/shared/protocols/PtlAddData.ts +++ /dev/null @@ -1,10 +0,0 @@ -// This is a demo code file -// Feel free to delete it - -export interface ReqAddData { - content: string; -} - -export interface ResAddData { - time: Date -} \ No newline at end of file diff --git a/examples/transfer-encryption/frontend/src/shared/protocols/PtlGetData.ts b/examples/transfer-encryption/frontend/src/shared/protocols/PtlGetData.ts deleted file mode 100644 index 8ac35a7..0000000 --- a/examples/transfer-encryption/frontend/src/shared/protocols/PtlGetData.ts +++ /dev/null @@ -1,13 +0,0 @@ -// This is a demo code file -// Feel free to delete it - -export interface ReqGetData { - -} - -export interface ResGetData { - data: { - content: string, - time: Date - }[] -} \ No newline at end of file diff --git a/examples/transfer-encryption/frontend/src/shared/protocols/serviceProto.ts b/examples/transfer-encryption/frontend/src/shared/protocols/serviceProto.ts deleted file mode 100644 index e7207a9..0000000 --- a/examples/transfer-encryption/frontend/src/shared/protocols/serviceProto.ts +++ /dev/null @@ -1,98 +0,0 @@ -import { ServiceProto } from 'tsrpc-proto'; -import { ReqAddData, ResAddData } from './PtlAddData'; -import { ReqGetData, ResGetData } from './PtlGetData'; - -// This is a demo service proto file (auto generated) -// Feel free to delete it - -export interface ServiceType { - api: { - "AddData": { - req: ReqAddData, - res: ResAddData - }, - "GetData": { - req: ReqGetData, - res: ResGetData - } - }, - msg: { - - } -} - -export const serviceProto: ServiceProto = { - "version": 1, - "services": [ - { - "id": 0, - "name": "AddData", - "type": "api" - }, - { - "id": 1, - "name": "GetData", - "type": "api" - } - ], - "types": { - "PtlAddData/ReqAddData": { - "type": "Interface", - "properties": [ - { - "id": 0, - "name": "content", - "type": { - "type": "String" - } - } - ] - }, - "PtlAddData/ResAddData": { - "type": "Interface", - "properties": [ - { - "id": 0, - "name": "time", - "type": { - "type": "Date" - } - } - ] - }, - "PtlGetData/ReqGetData": { - "type": "Interface" - }, - "PtlGetData/ResGetData": { - "type": "Interface", - "properties": [ - { - "id": 0, - "name": "data", - "type": { - "type": "Array", - "elementType": { - "type": "Interface", - "properties": [ - { - "id": 0, - "name": "content", - "type": { - "type": "String" - } - }, - { - "id": 1, - "name": "time", - "type": { - "type": "Date" - } - } - ] - } - } - } - ] - } - } -}; \ No newline at end of file diff --git a/examples/user-authentication/backend/package.json b/examples/user-authentication/backend/package.json index f5a0f6f..379cbf9 100644 --- a/examples/user-authentication/backend/package.json +++ b/examples/user-authentication/backend/package.json @@ -4,22 +4,22 @@ "main": "index.js", "private": true, "scripts": { - "proto": "tsrpc proto -i src/shared/protocols -o src/shared/protocols/serviceProto.ts", - "sync": "tsrpc sync --from src/shared --to ../frontend/src/shared", - "api": "tsrpc api -i src/shared/protocols/serviceProto.ts -o src/api", - "dev": "onchange \"src/**/*.ts\" -i -k -- ts-node \"src/index.ts\"", - "build": "tsrpc build" + "proto": "tsrpc proto --config tsrpc.config.ts", + "sync": "tsrpc sync --config tsrpc.config.ts", + "api": "tsrpc api --config tsrpc.config.ts", + "dev": "tsrpc dev --config tsrpc.config.ts", + "build": "tsrpc build --config tsrpc.config.ts" }, "devDependencies": { - "@types/node": "^15.12.3", - "@types/uuid": "^8.3.0", + "@types/node": "^15.14.9", + "@types/uuid": "^8.3.1", "onchange": "^7.1.0", "ts-node": "^9.1.1", - "tsrpc-cli": "^2.0.3", - "typescript": "^4.3.4" + "tsrpc-cli": "^2.0.8", + "typescript": "^4.4.3" }, "dependencies": { - "tsrpc": "^3.0.2", + "tsrpc": "^3.0.9", "uuid": "^8.3.2" } } diff --git a/examples/user-authentication/backend/src/shared/protocols/serviceProto.ts b/examples/user-authentication/backend/src/shared/protocols/serviceProto.ts index f3d0c53..b522c5d 100644 --- a/examples/user-authentication/backend/src/shared/protocols/serviceProto.ts +++ b/examples/user-authentication/backend/src/shared/protocols/serviceProto.ts @@ -34,7 +34,7 @@ export interface ServiceType { } export const serviceProto: ServiceProto = { - "version": 2, + "version": 3, "services": [ { "id": 0, @@ -248,6 +248,43 @@ export const serviceProto: ServiceProto = { "type": { "type": "String" } + }, + { + "id": 1, + "name": "user", + "type": { + "type": "Reference", + "target": "../../models/CurrentUser/CurrentUser" + } + } + ] + }, + "../../models/CurrentUser/CurrentUser": { + "type": "Interface", + "properties": [ + { + "id": 0, + "name": "uid", + "type": { + "type": "Number" + } + }, + { + "id": 1, + "name": "username", + "type": { + "type": "String" + } + }, + { + "id": 2, + "name": "roles", + "type": { + "type": "Array", + "elementType": { + "type": "String" + } + } } ] }, diff --git a/examples/user-authentication/backend/tsrpc.config.ts b/examples/user-authentication/backend/tsrpc.config.ts new file mode 100644 index 0000000..704baed --- /dev/null +++ b/examples/user-authentication/backend/tsrpc.config.ts @@ -0,0 +1,36 @@ +import { TsrpcConfig } from 'tsrpc-cli'; + +const tsrpcConf: TsrpcConfig = { + // Generate ServiceProto + proto: [ + { + ptlDir: 'src/shared/protocols', // Protocol dir + output: 'src/shared/protocols/serviceProto.ts', // Path for generated ServiceProto + apiDir: 'src/api' // API dir + } + ], + // Sync shared code + sync: [ + { + from: 'src/shared', + to: '../frontend/src/shared', + type: 'symlink' // Change this to 'copy' if your environment not support symlink + } + ], + // Dev server + dev: { + autoProto: true, // Auto regenerate proto + autoSync: true, // Auto sync when file changed + autoApi: true, // Auto create API when ServiceProto updated + watch: 'src', // Restart dev server when these files changed + entry: 'src/index.ts', // Dev server command: node -r ts-node/register {entry} + }, + // Build config + build: { + autoProto: true, // Auto generate proto before build + autoSync: true, // Auto sync before build + autoApi: true, // Auto generate API before build + outDir: 'dist', // Clean this dir before build + } +} +export default tsrpcConf; \ No newline at end of file diff --git a/examples/user-authentication/frontend/package.json b/examples/user-authentication/frontend/package.json index 57f1485..024ee84 100644 --- a/examples/user-authentication/frontend/package.json +++ b/examples/user-authentication/frontend/package.json @@ -7,15 +7,15 @@ "build": "webpack --mode=production" }, "devDependencies": { - "copy-webpack-plugin": "^9.0.0", - "html-webpack-plugin": "^5.3.1", - "ts-loader": "^9.2.3", - "typescript": "^4.3.4", - "webpack": "^5.39.1", - "webpack-cli": "^4.7.2", + "copy-webpack-plugin": "^9.0.1", + "html-webpack-plugin": "^5.3.2", + "ts-loader": "^9.2.6", + "typescript": "^4.4.3", + "webpack": "^5.57.1", + "webpack-cli": "^4.9.0", "webpack-dev-server": "^3.11.2" }, "dependencies": { - "tsrpc-browser": "^3.0.3" + "tsrpc-browser": "^3.0.7" } } diff --git a/examples/user-authentication/frontend/src/shared b/examples/user-authentication/frontend/src/shared new file mode 120000 index 0000000..b72cd26 --- /dev/null +++ b/examples/user-authentication/frontend/src/shared @@ -0,0 +1 @@ +../../backend/src/shared \ No newline at end of file diff --git a/examples/user-authentication/frontend/src/shared/protocols/action/PtlAdminAction.ts b/examples/user-authentication/frontend/src/shared/protocols/action/PtlAdminAction.ts deleted file mode 100644 index 77a9aea..0000000 --- a/examples/user-authentication/frontend/src/shared/protocols/action/PtlAdminAction.ts +++ /dev/null @@ -1,14 +0,0 @@ -import { BaseRequest, BaseResponse, BaseConf } from '../base' - -export interface ReqAdminAction extends BaseRequest { - -} - -export interface ResAdminAction extends BaseResponse { - result: string -} - -export const conf: BaseConf = { - needLogin: true, - needRoles: ['Admin'] -}; \ No newline at end of file diff --git a/examples/user-authentication/frontend/src/shared/protocols/action/PtlGuestAction.ts b/examples/user-authentication/frontend/src/shared/protocols/action/PtlGuestAction.ts deleted file mode 100644 index 7653d77..0000000 --- a/examples/user-authentication/frontend/src/shared/protocols/action/PtlGuestAction.ts +++ /dev/null @@ -1,13 +0,0 @@ -import { BaseConf, BaseRequest, BaseResponse } from '../base'; - -export interface ReqGuestAction extends BaseRequest { - -} - -export interface ResGuestAction extends BaseResponse { - result: string -} - -export const conf: BaseConf = { - needLogin: false -}; \ No newline at end of file diff --git a/examples/user-authentication/frontend/src/shared/protocols/action/PtlNormalAction.ts b/examples/user-authentication/frontend/src/shared/protocols/action/PtlNormalAction.ts deleted file mode 100644 index f7d54b1..0000000 --- a/examples/user-authentication/frontend/src/shared/protocols/action/PtlNormalAction.ts +++ /dev/null @@ -1,13 +0,0 @@ -import { BaseConf, BaseRequest, BaseResponse } from '../base'; - -export interface ReqNormalAction extends BaseRequest { - -} - -export interface ResNormalAction extends BaseResponse { - result: string -} - -export const conf: BaseConf = { - needLogin: true -}; \ No newline at end of file diff --git a/examples/user-authentication/frontend/src/shared/protocols/base.ts b/examples/user-authentication/frontend/src/shared/protocols/base.ts deleted file mode 100644 index 2b261fd..0000000 --- a/examples/user-authentication/frontend/src/shared/protocols/base.ts +++ /dev/null @@ -1,13 +0,0 @@ -export interface BaseRequest { - __ssoToken?: string; -} - -export interface BaseResponse { - // Init or refresh sso token - __ssoToken?: string; -} - -export interface BaseConf { - needLogin?: boolean, - needRoles?: string[] -} \ No newline at end of file diff --git a/examples/user-authentication/frontend/src/shared/protocols/serviceProto.ts b/examples/user-authentication/frontend/src/shared/protocols/serviceProto.ts deleted file mode 100644 index f3d0c53..0000000 --- a/examples/user-authentication/frontend/src/shared/protocols/serviceProto.ts +++ /dev/null @@ -1,279 +0,0 @@ -import { ServiceProto } from 'tsrpc-proto'; -import { ReqAdminAction, ResAdminAction } from './action/PtlAdminAction'; -import { ReqGuestAction, ResGuestAction } from './action/PtlGuestAction'; -import { ReqNormalAction, ResNormalAction } from './action/PtlNormalAction'; -import { ReqLogin, ResLogin } from './user/PtlLogin'; -import { ReqLogout, ResLogout } from './user/PtlLogout'; - -export interface ServiceType { - api: { - "action/AdminAction": { - req: ReqAdminAction, - res: ResAdminAction - }, - "action/GuestAction": { - req: ReqGuestAction, - res: ResGuestAction - }, - "action/NormalAction": { - req: ReqNormalAction, - res: ResNormalAction - }, - "user/Login": { - req: ReqLogin, - res: ResLogin - }, - "user/Logout": { - req: ReqLogout, - res: ResLogout - } - }, - msg: { - - } -} - -export const serviceProto: ServiceProto = { - "version": 2, - "services": [ - { - "id": 0, - "name": "action/AdminAction", - "type": "api", - "conf": { - "needLogin": true, - "needRoles": [ - "Admin" - ] - } - }, - { - "id": 1, - "name": "action/GuestAction", - "type": "api", - "conf": { - "needLogin": false - } - }, - { - "id": 2, - "name": "action/NormalAction", - "type": "api", - "conf": { - "needLogin": true - } - }, - { - "id": 3, - "name": "user/Login", - "type": "api", - "conf": {} - }, - { - "id": 4, - "name": "user/Logout", - "type": "api", - "conf": {} - } - ], - "types": { - "action/PtlAdminAction/ReqAdminAction": { - "type": "Interface", - "extends": [ - { - "id": 0, - "type": { - "type": "Reference", - "target": "base/BaseRequest" - } - } - ] - }, - "base/BaseRequest": { - "type": "Interface", - "properties": [ - { - "id": 0, - "name": "__ssoToken", - "type": { - "type": "String" - }, - "optional": true - } - ] - }, - "action/PtlAdminAction/ResAdminAction": { - "type": "Interface", - "extends": [ - { - "id": 0, - "type": { - "type": "Reference", - "target": "base/BaseResponse" - } - } - ], - "properties": [ - { - "id": 0, - "name": "result", - "type": { - "type": "String" - } - } - ] - }, - "base/BaseResponse": { - "type": "Interface", - "properties": [ - { - "id": 0, - "name": "__ssoToken", - "type": { - "type": "String" - }, - "optional": true - } - ] - }, - "action/PtlGuestAction/ReqGuestAction": { - "type": "Interface", - "extends": [ - { - "id": 0, - "type": { - "type": "Reference", - "target": "base/BaseRequest" - } - } - ] - }, - "action/PtlGuestAction/ResGuestAction": { - "type": "Interface", - "extends": [ - { - "id": 0, - "type": { - "type": "Reference", - "target": "base/BaseResponse" - } - } - ], - "properties": [ - { - "id": 0, - "name": "result", - "type": { - "type": "String" - } - } - ] - }, - "action/PtlNormalAction/ReqNormalAction": { - "type": "Interface", - "extends": [ - { - "id": 0, - "type": { - "type": "Reference", - "target": "base/BaseRequest" - } - } - ] - }, - "action/PtlNormalAction/ResNormalAction": { - "type": "Interface", - "extends": [ - { - "id": 0, - "type": { - "type": "Reference", - "target": "base/BaseResponse" - } - } - ], - "properties": [ - { - "id": 0, - "name": "result", - "type": { - "type": "String" - } - } - ] - }, - "user/PtlLogin/ReqLogin": { - "type": "Interface", - "extends": [ - { - "id": 0, - "type": { - "type": "Reference", - "target": "base/BaseRequest" - } - } - ], - "properties": [ - { - "id": 0, - "name": "username", - "type": { - "type": "String" - } - }, - { - "id": 1, - "name": "password", - "type": { - "type": "String" - } - } - ] - }, - "user/PtlLogin/ResLogin": { - "type": "Interface", - "extends": [ - { - "id": 0, - "type": { - "type": "Reference", - "target": "base/BaseResponse" - } - } - ], - "properties": [ - { - "id": 0, - "name": "__ssoToken", - "type": { - "type": "String" - } - } - ] - }, - "user/PtlLogout/ReqLogout": { - "type": "Interface", - "extends": [ - { - "id": 0, - "type": { - "type": "Reference", - "target": "base/BaseRequest" - } - } - ] - }, - "user/PtlLogout/ResLogout": { - "type": "Interface", - "extends": [ - { - "id": 0, - "type": { - "type": "Reference", - "target": "base/BaseResponse" - } - } - ] - } - } -}; \ No newline at end of file diff --git a/examples/user-authentication/frontend/src/shared/protocols/user/PtlLogin.ts b/examples/user-authentication/frontend/src/shared/protocols/user/PtlLogin.ts deleted file mode 100644 index ddcd494..0000000 --- a/examples/user-authentication/frontend/src/shared/protocols/user/PtlLogin.ts +++ /dev/null @@ -1,14 +0,0 @@ -import { BaseConf, BaseRequest, BaseResponse } from '../base'; - -export interface ReqLogin extends BaseRequest { - username: string, - password: string -} - -export interface ResLogin extends BaseResponse { - __ssoToken: string; -} - -export const conf: BaseConf = { - -}; \ No newline at end of file diff --git a/examples/user-authentication/frontend/src/shared/protocols/user/PtlLogout.ts b/examples/user-authentication/frontend/src/shared/protocols/user/PtlLogout.ts deleted file mode 100644 index c3b112b..0000000 --- a/examples/user-authentication/frontend/src/shared/protocols/user/PtlLogout.ts +++ /dev/null @@ -1,13 +0,0 @@ -import { BaseRequest, BaseResponse, BaseConf } from '../base' - -export interface ReqLogout extends BaseRequest { - -} - -export interface ResLogout extends BaseResponse { - -} - -export const conf: BaseConf = { - -}; \ No newline at end of file diff --git a/scripts/npm-update.js b/scripts/npm-update.js index 9fc5199..594e4c7 100644 --- a/scripts/npm-update.js +++ b/scripts/npm-update.js @@ -1,13 +1,35 @@ const fs = require('fs'); const path = require('path'); -const { execSync } = require('child_process'); +const { execSync, exec } = require('child_process'); let dirs = fs.readdirSync(path.resolve(__dirname, '../examples')); dirs.forEach(dir => { console.log(dir); - process.chdir(path.resolve(__dirname, '../examples', dir, 'backend')); - execSync('ncu -u -t minor', { stdio: 'inherit' }); - process.chdir(path.resolve(__dirname, '../examples', dir, 'frontend')); - execSync('ncu -u -t minor', { stdio: 'inherit' }); -}) \ No newline at end of file + + if (!isDir(path.resolve(__dirname, '../examples', dir,))) { + return; + } + + let num = 0; + if (isDir(path.resolve(__dirname, '../examples', dir, 'backend'))) { + ++num; + process.chdir(path.resolve(__dirname, '../examples', dir, 'backend')); + execSync('ncu -u -t minor && npm i --registry https://registry.npm.taobao.org', { stdio: 'inherit' }); + } + + if (isDir(path.resolve(__dirname, '../examples', dir, 'frontend'))) { + ++num; + process.chdir(path.resolve(__dirname, '../examples', dir, 'frontend')); + execSync('ncu -u -t minor && npm i --registry https://registry.npm.taobao.org', { stdio: 'inherit' }); + } + + if (!num) { + process.chdir(path.resolve(__dirname, '../examples', dir)); + execSync('ncu -u -t minor && npm i --registry https://registry.npm.taobao.org', { stdio: 'inherit' }); + } +}) + +function isDir(dir) { + return fs.existsSync(dir) && fs.statSync(dir).isDirectory() +} \ No newline at end of file