Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
78 changes: 78 additions & 0 deletions .github/workflows/preview-publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
name: PREVIEW_PUBLISH

on:
workflow_run:
workflows: ["PULL_REQUEST"]
types:
- completed

jobs:
preview-success:
runs-on: ubuntu-latest
if: >
github.event.workflow_run.event == 'pull_request' &&
github.event.workflow_run.conclusion == 'success'
steps:
- name: download pr artifact
uses: dawidd6/action-download-artifact@v6
with:
workflow: ${{ github.event.workflow_run.workflow_id }}
run_id: ${{ github.event.workflow_run.id }}
name: pr
- name: save PR id
id: pr
run: echo "id=$(<pr-id.txt)" >> $GITHUB_OUTPUT

- name: download preview site artifact
uses: dawidd6/action-download-artifact@v6
with:
workflow: ${{ github.event.workflow_run.workflow_id }}
run_id: ${{ github.event.workflow_run.id }}
name: preview
- run: |
unzip preview.zip

- name: Upload surge service and generate preview URL
id: deploy
run: |
repository=${{github.repository}}
export DEPLOY_DOMAIN=https://preview-pr-${{ steps.pr.outputs.id }}-we-socket.surge.sh
npx surge --project dist --domain $DEPLOY_DOMAIN --token ${{ secrets.SURGE_TOKEN }}
echo the preview URL is $DEPLOY_DOMAIN
echo "url=$DEPLOY_DOMAIN" >> $GITHUB_OUTPUT

- name: update status comment
uses: actions-cool/maintain-one-comment@v3
with:
token: ${{ secrets.GITHUB_TOKEN }}
body: |
<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>
<!-- [工作流地址](${{github.server_url}}/${{github.repository}}/actions/runs/${{github.run_id}}) -->
<!-- AUTO_PREVIEW_HOOK -->
number: ${{ steps.pr.outputs.id }}
body-include: "<!-- AUTO_PREVIEW_HOOK -->"

preview-failed:
runs-on: ubuntu-latest
if: >
github.event.workflow_run.event == 'pull_request' &&
github.event.workflow_run.conclusion == 'failure'
steps:
- name: download pr artifact
uses: dawidd6/action-download-artifact@v6
with:
workflow: ${{ github.event.workflow_run.workflow_id }}
run_id: ${{ github.event.workflow_run.id }}
name: pr
- name: save PR id
id: pr
run: echo "id=$(<pr-id.txt)" >> $GITHUB_OUTPUT
- name: The job failed
uses: actions-cool/maintain-one-comment@v3
with:
token: ${{ secrets.GITHUB_TOKEN }}
body: |
[<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}})
<!-- AUTO_PREVIEW_HOOK -->
number: ${{ steps.pr.outputs.id }}
body-include: "<!-- AUTO_PREVIEW_HOOK -->"
115 changes: 115 additions & 0 deletions .github/workflows/pull-request.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
name: PULL_REQUEST

on:
pull_request:
branches: [develop, main]
types: [opened, synchronize, reopened]

jobs:
lint:
# 在最新版本的 Ubuntu 环境中运行
runs-on: ubuntu-latest
steps:
# 检出代码仓库,并递归初始化子模块
- uses: actions/checkout@v4
with:
submodules: recursive

# 设置 pnpm
- name: Setup pnpm
uses: pnpm/action-setup@v4

# 设置 Node.js 环境,版本为 18
- uses: actions/setup-node@v4
with:
node-version: 18

# 获取 pnpm 的存储目录路径
- name: Get pnpm store directory
id: pnpm-cache
run: |
echo "pnpm_cache_dir=$(pnpm store path)" >> $GITHUB_OUTPUT

# 设置 pnpm 缓存
- uses: actions/cache@v4
name: Setup pnpm cache
with:
# 缓存路径
path: ${{ steps.pnpm-cache.outputs.pnpm_cache_dir }}
# 缓存键
key: ${{ runner.os }}-pnpm-store-${{ hashFiles('**/pnpm-lock.yaml') }}
# 恢复缓存的备用键
restore-keys: |
${{ runner.os }}-pnpm-store-

# 安装依赖
- run: pnpm i

# 运行代码 lint 检查
- run: pnpm run lint

build:
# 在最新版本的 Ubuntu 环境中运行
runs-on: ubuntu-latest
# 如果需要依赖自身任务,可以取消注释(通常不需要)
# needs: build
steps:
- name: Save PR number
run: echo ${{ github.event.number }} > ./pr-id.txt
- name: Upload PR number
uses: actions/upload-artifact@v4
with:
name: pr
path: ./pr-id.txt
# 检出代码仓库,并递归初始化子模块
- uses: actions/checkout@v4
with:
submodules: recursive

# 设置 pnpm
- name: Setup pnpm
uses: pnpm/action-setup@v4

# 设置 Node.js 环境,版本为 18
- uses: actions/setup-node@v4
with:
node-version: 18

# 获取 pnpm 的存储目录路径
- name: Get pnpm store directory
id: pnpm-cache
run: |
echo "pnpm_cache_dir=$(pnpm store path)" >> $GITHUB_OUTPUT

# 设置 pnpm 缓存
- uses: actions/cache@v4
name: Setup pnpm cache
with:
# 缓存路径
path: ${{ steps.pnpm-cache.outputs.pnpm_cache_dir }}
# 缓存键
key: ${{ runner.os }}-pnpm-store-${{ hashFiles('**/pnpm-lock.yaml') }}
# 恢复缓存的备用键
restore-keys: |
${{ runner.os }}-pnpm-store-

# 安装依赖
- run: pnpm i

# 运行构建任务
- name: Build
run: pnpm run build

- run: |
zip -r preview.zip ./packages/client/dist

# 上传站点文件作为构建产物
- name: upload preview site artifact
uses: actions/upload-artifact@v4
with:
# 产物名称
name: preview
# 产物路径
path: preview.zip
# 产物保留天数
retention-days: 5
39 changes: 36 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,38 @@
# Vue 3 + TypeScript + Vite
### WeSocket

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.

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).
WeSocket is a Websocket Service Demo with client and management.

# 🎉 Features

- Support one management end to manage multiple clients
- Support client recognition
- Support secondary development and use

# 📦 Installation

```shell
git clone https://github.com/Wesley-Work/WeSocket.git
```

# 🔨 Usage

```shell
pnpm i

pnpm run dev # start client & service

# also you can start client or service separately

pnpm run dev:client # start client

pnpm run dev:service # start service
```

# ⚠️ Warning
#### 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
#### Anyway, if you have any ideas, they can be implemented through code modifications in this repository. Feel free to raise any issues!

# License

The Apache v2 License. Please see [the license file](./LICENSE) for more information.
5 changes: 5 additions & 0 deletions globals.d.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
/// <reference types="vite/client" />

// eslint-disable-next-line no-unused-vars
declare const PKG_VERSION: string;

Expand All @@ -7,3 +9,6 @@ declare module '*.vue' {
const component: DefineComponent<{}, {}, any> & Plugin;
export default component;
}

declare module '*.scss' {}
declare module '*.css' {}
10 changes: 10 additions & 0 deletions jsx.d.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,20 @@
import { HTMLAttributes } from 'vue';

declare module '*.vue' {
import type { DefineComponent, Plugin } from 'vue';
const component: DefineComponent<{}, {}, any> & Plugin;
export default component;
}

declare global {
namespace JSX {
interface IntrinsicAttributes {
[emit: string]: any;
}

interface IntrinsicElements {
[elem: string]: any;
}
}
}

Expand Down
21 changes: 12 additions & 9 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "qas",
"name": "we-socket",
"private": true,
"packageManager": "pnpm@9.15.9",
"engines": {
Expand All @@ -10,16 +10,21 @@
"lint": "pnpm lint:tsc && eslint --ext .vue,.js,.ts,.tsx ./packages --max-warnings 0 --cache",
"lint:fix": "eslint --ext .vue,.js,.ts,.tsx ./packages --max-warnings 0 --fix --cache",
"dev:client": "pnpm -C packages/client dev",
"build:client": "pnpm -C packages/client build"
"build:client": "pnpm -C packages/client build",
"dev:service": "pnpm -C packages/service dev",
"start:service": "pnpm -C packages/service start",
"dev": "run-p dev:client dev:service",
"build": "pnpm run build:client"
},
"author": "tdesign",
"license": "MIT",
"dependencies": {
"@we-socket/config": "workspace:^",
"@we-socket/hooks": "workspace:^",
"@we-socket/utils": "workspace:^",
"@we-socket/types": "workspace:^",
"@babel/runtime": "^7.22.6",
"dayjs": "1.11.10",
"lodash-es": "^4.17.21",
"tdesign-icons-vue-next": "^0.3.6",
"tdesign-vue-next": "^1.13.1"
"lodash-es": "^4.17.21"
},
"peerDependencies": {
"vue": ">=3.1.0"
Expand All @@ -43,8 +48,6 @@
"@typescript-eslint/parser": "^4.33.0",
"@vitejs/plugin-vue": "^2.3.4",
"@vitejs/plugin-vue-jsx": "^1.3.10",
"@vitest/coverage-v8": "^2.1.8",
"@vitest/ui": "^2.1.8",
"@vue/babel-plugin-jsx": "1.2.2",
"@vue/eslint-config-typescript": "^10.0.0",
"@vue/test-utils": "^2.4.1",
Expand Down Expand Up @@ -87,4 +90,4 @@
"eslint --fix --cache"
]
}
}
}
2 changes: 1 addition & 1 deletion packages/client/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<meta charset="UTF-8" />
<link rel="icon" type="image/svg+xml" href="/vite.svg" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Vite + Vue + TS</title>
<title>WeSocket</title>
</head>
<body>
<div id="app"></div>
Expand Down
25 changes: 19 additions & 6 deletions packages/client/package.json
Original file line number Diff line number Diff line change
@@ -1,21 +1,34 @@
{
"name": "qas-client",
"name": "client",
"private": true,
"version": "0.0.0",
"type": "module",
"scripts": {
"dev": "vite",
"build": "vue-tsc -b && vite build",
"build": "vite build",
"preview": "vite preview"
},
"dependencies": {
"vue": "^3.5.13"
"@vue/runtime-dom": "^3.5.13",
"@vueuse/core": "^10.2.1",
"pixi.js": "^8.9.2",
"tdesign-icons-vue-next": "^0.3.6",
"tdesign-vue-next": "^1.13.1",
"vue": "^3.5.13",
"vue-router": "^4.5.1"
},
"devDependencies": {
"@vitejs/plugin-vue": "^5.2.3",
"@types/nprogress": "^0.2.3",
"@vitejs/plugin-vue": "^5.2.1",
"@vitejs/plugin-vue-jsx": "^4.1.2",
"@vue/compiler-sfc": "^3.5.13",
"@vue/runtime-core": "^3.5.13",
"@vue/tsconfig": "^0.7.0",
"sass-embedded": "^1.89.1",
"typescript": "~5.8.3",
"vite": "^6.3.5",
"vue-tsc": "^2.2.8"
"vite": "^6.2.0",
"vite-plugin-pwa": "^0.21.2",
"vite-plugin-tdoc": "^2.0.4",
"vue-tsc": "^2.2.4"
}
}
Loading