Skip to content

Commit b4b35ba

Browse files
authored
Feat/service (#11)
* feat: service * chore: server * feat: demo * feat: update service support clientType * chore: ci * chore: rename * chore: ci * chore: ci * fix: lint * fix: lint * Update README.md
1 parent 60d2114 commit b4b35ba

37 files changed

+3017
-914
lines changed
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
name: PREVIEW_PUBLISH
2+
3+
on:
4+
workflow_run:
5+
workflows: ["PULL_REQUEST"]
6+
types:
7+
- completed
8+
9+
jobs:
10+
preview-success:
11+
runs-on: ubuntu-latest
12+
if: >
13+
github.event.workflow_run.event == 'pull_request' &&
14+
github.event.workflow_run.conclusion == 'success'
15+
steps:
16+
- name: download pr artifact
17+
uses: dawidd6/action-download-artifact@v6
18+
with:
19+
workflow: ${{ github.event.workflow_run.workflow_id }}
20+
run_id: ${{ github.event.workflow_run.id }}
21+
name: pr
22+
- name: save PR id
23+
id: pr
24+
run: echo "id=$(<pr-id.txt)" >> $GITHUB_OUTPUT
25+
26+
- name: download preview site artifact
27+
uses: dawidd6/action-download-artifact@v6
28+
with:
29+
workflow: ${{ github.event.workflow_run.workflow_id }}
30+
run_id: ${{ github.event.workflow_run.id }}
31+
name: preview
32+
- run: |
33+
unzip preview.zip
34+
35+
- name: Upload surge service and generate preview URL
36+
id: deploy
37+
run: |
38+
repository=${{github.repository}}
39+
export DEPLOY_DOMAIN=https://preview-pr-${{ steps.pr.outputs.id }}-we-socket.surge.sh
40+
npx surge --project dist --domain $DEPLOY_DOMAIN --token ${{ secrets.SURGE_TOKEN }}
41+
echo the preview URL is $DEPLOY_DOMAIN
42+
echo "url=$DEPLOY_DOMAIN" >> $GITHUB_OUTPUT
43+
44+
- name: update status comment
45+
uses: actions-cool/maintain-one-comment@v3
46+
with:
47+
token: ${{ secrets.GITHUB_TOKEN }}
48+
body: |
49+
<a href="${{steps.deploy.outputs.url}}"><img height="96" alt="完成" src="https://user-images.githubusercontent.com/15634204/150816437-9f5bb788-cd67-4cbc-9897-b82d74e9aa65.png" /></a>
50+
<!-- [工作流地址](${{github.server_url}}/${{github.repository}}/actions/runs/${{github.run_id}}) -->
51+
<!-- AUTO_PREVIEW_HOOK -->
52+
number: ${{ steps.pr.outputs.id }}
53+
body-include: "<!-- AUTO_PREVIEW_HOOK -->"
54+
55+
preview-failed:
56+
runs-on: ubuntu-latest
57+
if: >
58+
github.event.workflow_run.event == 'pull_request' &&
59+
github.event.workflow_run.conclusion == 'failure'
60+
steps:
61+
- name: download pr artifact
62+
uses: dawidd6/action-download-artifact@v6
63+
with:
64+
workflow: ${{ github.event.workflow_run.workflow_id }}
65+
run_id: ${{ github.event.workflow_run.id }}
66+
name: pr
67+
- name: save PR id
68+
id: pr
69+
run: echo "id=$(<pr-id.txt)" >> $GITHUB_OUTPUT
70+
- name: The job failed
71+
uses: actions-cool/maintain-one-comment@v3
72+
with:
73+
token: ${{ secrets.GITHUB_TOKEN }}
74+
body: |
75+
[<img height="96" alt="失败" src="https://user-images.githubusercontent.com/5378891/75333447-1e63a280-58c1-11ea-975d-235367fd1522.png">](${{github.server_url}}/${{github.repository}}/actions/runs/${{github.run_id}})
76+
<!-- AUTO_PREVIEW_HOOK -->
77+
number: ${{ steps.pr.outputs.id }}
78+
body-include: "<!-- AUTO_PREVIEW_HOOK -->"

.github/workflows/pull-request.yml

Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
1+
name: PULL_REQUEST
2+
3+
on:
4+
pull_request:
5+
branches: [develop, main]
6+
types: [opened, synchronize, reopened]
7+
8+
jobs:
9+
lint:
10+
# 在最新版本的 Ubuntu 环境中运行
11+
runs-on: ubuntu-latest
12+
steps:
13+
# 检出代码仓库,并递归初始化子模块
14+
- uses: actions/checkout@v4
15+
with:
16+
submodules: recursive
17+
18+
# 设置 pnpm
19+
- name: Setup pnpm
20+
uses: pnpm/action-setup@v4
21+
22+
# 设置 Node.js 环境,版本为 18
23+
- uses: actions/setup-node@v4
24+
with:
25+
node-version: 18
26+
27+
# 获取 pnpm 的存储目录路径
28+
- name: Get pnpm store directory
29+
id: pnpm-cache
30+
run: |
31+
echo "pnpm_cache_dir=$(pnpm store path)" >> $GITHUB_OUTPUT
32+
33+
# 设置 pnpm 缓存
34+
- uses: actions/cache@v4
35+
name: Setup pnpm cache
36+
with:
37+
# 缓存路径
38+
path: ${{ steps.pnpm-cache.outputs.pnpm_cache_dir }}
39+
# 缓存键
40+
key: ${{ runner.os }}-pnpm-store-${{ hashFiles('**/pnpm-lock.yaml') }}
41+
# 恢复缓存的备用键
42+
restore-keys: |
43+
${{ runner.os }}-pnpm-store-
44+
45+
# 安装依赖
46+
- run: pnpm i
47+
48+
# 运行代码 lint 检查
49+
- run: pnpm run lint
50+
51+
build:
52+
# 在最新版本的 Ubuntu 环境中运行
53+
runs-on: ubuntu-latest
54+
# 如果需要依赖自身任务,可以取消注释(通常不需要)
55+
# needs: build
56+
steps:
57+
- name: Save PR number
58+
run: echo ${{ github.event.number }} > ./pr-id.txt
59+
- name: Upload PR number
60+
uses: actions/upload-artifact@v4
61+
with:
62+
name: pr
63+
path: ./pr-id.txt
64+
# 检出代码仓库,并递归初始化子模块
65+
- uses: actions/checkout@v4
66+
with:
67+
submodules: recursive
68+
69+
# 设置 pnpm
70+
- name: Setup pnpm
71+
uses: pnpm/action-setup@v4
72+
73+
# 设置 Node.js 环境,版本为 18
74+
- uses: actions/setup-node@v4
75+
with:
76+
node-version: 18
77+
78+
# 获取 pnpm 的存储目录路径
79+
- name: Get pnpm store directory
80+
id: pnpm-cache
81+
run: |
82+
echo "pnpm_cache_dir=$(pnpm store path)" >> $GITHUB_OUTPUT
83+
84+
# 设置 pnpm 缓存
85+
- uses: actions/cache@v4
86+
name: Setup pnpm cache
87+
with:
88+
# 缓存路径
89+
path: ${{ steps.pnpm-cache.outputs.pnpm_cache_dir }}
90+
# 缓存键
91+
key: ${{ runner.os }}-pnpm-store-${{ hashFiles('**/pnpm-lock.yaml') }}
92+
# 恢复缓存的备用键
93+
restore-keys: |
94+
${{ runner.os }}-pnpm-store-
95+
96+
# 安装依赖
97+
- run: pnpm i
98+
99+
# 运行构建任务
100+
- name: Build
101+
run: pnpm run build
102+
103+
- run: |
104+
zip -r preview.zip ./packages/client/dist
105+
106+
# 上传站点文件作为构建产物
107+
- name: upload preview site artifact
108+
uses: actions/upload-artifact@v4
109+
with:
110+
# 产物名称
111+
name: preview
112+
# 产物路径
113+
path: preview.zip
114+
# 产物保留天数
115+
retention-days: 5

README.md

Lines changed: 36 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,38 @@
1-
# Vue 3 + TypeScript + Vite
1+
### WeSocket
22

3-
This template should help get you started developing with Vue 3 and TypeScript in Vite. The template uses Vue 3 `<script setup>` SFCs, check out the [script setup docs](https://v3.vuejs.org/api/sfc-script-setup.html#sfc-script-setup) to learn more.
43

5-
Learn more about the recommended Project Setup and IDE Support in the [Vue Docs TypeScript Guide](https://vuejs.org/guide/typescript/overview.html#project-setup).
4+
WeSocket is a Websocket Service Demo with client and management.
5+
6+
# 🎉 Features
7+
8+
- Support one management end to manage multiple clients
9+
- Support client recognition
10+
- Support secondary development and use
11+
12+
# 📦 Installation
13+
14+
```shell
15+
git clone https://github.com/Wesley-Work/WeSocket.git
16+
```
17+
18+
# 🔨 Usage
19+
20+
```shell
21+
pnpm i
22+
23+
pnpm run dev # start client & service
24+
25+
# also you can start client or service separately
26+
27+
pnpm run dev:client # start client
28+
29+
pnpm run dev:service # start service
30+
```
31+
32+
# ⚠️ Warning
33+
#### These codes are just a demo (including basic content such as connecting to WebSocket services, client type classification, and heartbeat detection), which serves as the foundation for my other projects. Currently, I have only developed client connection services. You can develop other programs based on this repository according to your own needs, and of course, you can use this demo as a solution
34+
#### Anyway, if you have any ideas, they can be implemented through code modifications in this repository. Feel free to raise any issues!
35+
36+
# License
37+
38+
The Apache v2 License. Please see [the license file](./LICENSE) for more information.

globals.d.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
/// <reference types="vite/client" />
2+
13
// eslint-disable-next-line no-unused-vars
24
declare const PKG_VERSION: string;
35

@@ -7,3 +9,6 @@ declare module '*.vue' {
79
const component: DefineComponent<{}, {}, any> & Plugin;
810
export default component;
911
}
12+
13+
declare module '*.scss' {}
14+
declare module '*.css' {}

jsx.d.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,20 @@
11
import { HTMLAttributes } from 'vue';
22

3+
declare module '*.vue' {
4+
import type { DefineComponent, Plugin } from 'vue';
5+
const component: DefineComponent<{}, {}, any> & Plugin;
6+
export default component;
7+
}
8+
39
declare global {
410
namespace JSX {
511
interface IntrinsicAttributes {
612
[emit: string]: any;
713
}
14+
15+
interface IntrinsicElements {
16+
[elem: string]: any;
17+
}
818
}
919
}
1020

package.json

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"name": "qas",
2+
"name": "we-socket",
33
"private": true,
44
"packageManager": "pnpm@9.15.9",
55
"engines": {
@@ -10,16 +10,21 @@
1010
"lint": "pnpm lint:tsc && eslint --ext .vue,.js,.ts,.tsx ./packages --max-warnings 0 --cache",
1111
"lint:fix": "eslint --ext .vue,.js,.ts,.tsx ./packages --max-warnings 0 --fix --cache",
1212
"dev:client": "pnpm -C packages/client dev",
13-
"build:client": "pnpm -C packages/client build"
13+
"build:client": "pnpm -C packages/client build",
14+
"dev:service": "pnpm -C packages/service dev",
15+
"start:service": "pnpm -C packages/service start",
16+
"dev": "run-p dev:client dev:service",
17+
"build": "pnpm run build:client"
1418
},
15-
"author": "tdesign",
1619
"license": "MIT",
1720
"dependencies": {
21+
"@we-socket/config": "workspace:^",
22+
"@we-socket/hooks": "workspace:^",
23+
"@we-socket/utils": "workspace:^",
24+
"@we-socket/types": "workspace:^",
1825
"@babel/runtime": "^7.22.6",
1926
"dayjs": "1.11.10",
20-
"lodash-es": "^4.17.21",
21-
"tdesign-icons-vue-next": "^0.3.6",
22-
"tdesign-vue-next": "^1.13.1"
27+
"lodash-es": "^4.17.21"
2328
},
2429
"peerDependencies": {
2530
"vue": ">=3.1.0"
@@ -43,8 +48,6 @@
4348
"@typescript-eslint/parser": "^4.33.0",
4449
"@vitejs/plugin-vue": "^2.3.4",
4550
"@vitejs/plugin-vue-jsx": "^1.3.10",
46-
"@vitest/coverage-v8": "^2.1.8",
47-
"@vitest/ui": "^2.1.8",
4851
"@vue/babel-plugin-jsx": "1.2.2",
4952
"@vue/eslint-config-typescript": "^10.0.0",
5053
"@vue/test-utils": "^2.4.1",
@@ -87,4 +90,4 @@
8790
"eslint --fix --cache"
8891
]
8992
}
90-
}
93+
}

packages/client/index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<meta charset="UTF-8" />
55
<link rel="icon" type="image/svg+xml" href="/vite.svg" />
66
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
7-
<title>Vite + Vue + TS</title>
7+
<title>WeSocket</title>
88
</head>
99
<body>
1010
<div id="app"></div>

packages/client/package.json

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,34 @@
11
{
2-
"name": "qas-client",
2+
"name": "client",
33
"private": true,
44
"version": "0.0.0",
55
"type": "module",
66
"scripts": {
77
"dev": "vite",
8-
"build": "vue-tsc -b && vite build",
8+
"build": "vite build",
99
"preview": "vite preview"
1010
},
1111
"dependencies": {
12-
"vue": "^3.5.13"
12+
"@vue/runtime-dom": "^3.5.13",
13+
"@vueuse/core": "^10.2.1",
14+
"pixi.js": "^8.9.2",
15+
"tdesign-icons-vue-next": "^0.3.6",
16+
"tdesign-vue-next": "^1.13.1",
17+
"vue": "^3.5.13",
18+
"vue-router": "^4.5.1"
1319
},
1420
"devDependencies": {
15-
"@vitejs/plugin-vue": "^5.2.3",
21+
"@types/nprogress": "^0.2.3",
22+
"@vitejs/plugin-vue": "^5.2.1",
23+
"@vitejs/plugin-vue-jsx": "^4.1.2",
24+
"@vue/compiler-sfc": "^3.5.13",
25+
"@vue/runtime-core": "^3.5.13",
1626
"@vue/tsconfig": "^0.7.0",
27+
"sass-embedded": "^1.89.1",
1728
"typescript": "~5.8.3",
18-
"vite": "^6.3.5",
19-
"vue-tsc": "^2.2.8"
29+
"vite": "^6.2.0",
30+
"vite-plugin-pwa": "^0.21.2",
31+
"vite-plugin-tdoc": "^2.0.4",
32+
"vue-tsc": "^2.2.4"
2033
}
2134
}

0 commit comments

Comments
 (0)