@brewer/dj-common 1.0.0-beta.0 → 1.0.0-beta.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,11 +1,16 @@
1
1
  {
2
2
  "name": "@brewer/dj-common",
3
- "version": "1.0.0-beta.0",
3
+ "version": "1.0.0-beta.1",
4
4
  "description": "多端通用的公共方法库,支持 PC、H5、APP 等平台",
5
5
  "type": "module",
6
6
  "main": "dist/index.cjs.js",
7
7
  "module": "dist/index.esm.js",
8
8
  "types": "dist/index.d.ts",
9
+ "files": [
10
+ "dist",
11
+ "README.md",
12
+ "LICENSE"
13
+ ],
9
14
  "exports": {
10
15
  ".": {
11
16
  "import": "./dist/index.esm.js",
@@ -1,28 +0,0 @@
1
- {
2
- "permissions": {
3
- "allow": [
4
- "Bash(npm install:*)",
5
- "Bash(npm run build:*)",
6
- "Bash(npx husky init)",
7
- "Bash(git init:*)",
8
- "Bash(git add:*)",
9
- "Bash(git commit:*)",
10
- "Bash(npx eslint:*)",
11
- "Bash(npx lint-staged:*)",
12
- "Bash(npx prettier:*)",
13
- "Bash(git reset:*)",
14
- "Bash(npm run release:dry-run:*)",
15
- "Bash(npm token:*)",
16
- "Bash(node:*)",
17
- "Bash(npm whoami:*)",
18
- "Bash(git checkout:*)",
19
- "Bash(npm run lint)",
20
- "Bash(npx standard-version --prerelease beta)",
21
- "Bash(npm publish:*)",
22
- "Bash(npm view:*)",
23
- "Bash(git push:*)",
24
- "Bash(ls:*)",
25
- "Bash(git tag:*)"
26
- ]
27
- }
28
- }
package/.gitattributes DELETED
@@ -1,19 +0,0 @@
1
- # 强制所有文本文件使用 LF 换行符
2
- * text=auto eol=lf
3
-
4
- # 明确指定文件类型
5
- *.ts text eol=lf
6
- *.js text eol=lf
7
- *.json text eol=lf
8
- *.md text eol=lf
9
- *.yml text eol=lf
10
- *.yaml text eol=lf
11
-
12
- # 二进制文件
13
- *.png binary
14
- *.jpg binary
15
- *.jpeg binary
16
- *.gif binary
17
- *.ico binary
18
- *.woff binary
19
- *.woff2 binary
@@ -1,56 +0,0 @@
1
- name: Release
2
-
3
- on:
4
- push:
5
- tags:
6
- - 'v*' # 当推送 v 开头的 tag 时触发,如 v1.0.0
7
-
8
- jobs:
9
- publish:
10
- runs-on: ubuntu-latest
11
-
12
- permissions:
13
- contents: write # 需要写权限来创建 release
14
-
15
- steps:
16
- - name: 检出代码
17
- uses: actions/checkout@v4
18
- with:
19
- fetch-depth: 0 # 获取完整的 git 历史,用于生成 CHANGELOG
20
-
21
- - name: 设置 Node.js
22
- uses: actions/setup-node@v4
23
- with:
24
- node-version: '22.x'
25
- registry-url: 'https://registry.npmjs.org'
26
- cache: 'npm'
27
-
28
- - name: 指定 npm registry 为官方源
29
- run: npm config set registry https://registry.npmjs.org
30
-
31
- - name: 安装依赖
32
- run: npm install
33
-
34
- - name: 运行 ESLint 检查
35
- run: npm run lint
36
-
37
- - name: 构建项目
38
- run: npm run build
39
-
40
- - name: 发布到 NPM
41
- run: |
42
- if [[ ${{ github.ref }} == refs/tags/*-beta.* ]]; then
43
- npm publish --tag beta --access public
44
- else
45
- npm publish --access public
46
- fi
47
- env:
48
- NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
49
-
50
- - name: 创建 GitHub Release
51
- uses: softprops/action-gh-release@v1
52
- with:
53
- body_path: CHANGELOG.md
54
- generate_release_notes: true
55
- env:
56
- GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
package/.husky/commit-msg DELETED
@@ -1 +0,0 @@
1
- npx --no -- commitlint --edit $1
package/.husky/pre-commit DELETED
@@ -1 +0,0 @@
1
- npx lint-staged
@@ -1,4 +0,0 @@
1
- {
2
- "*.{js,jsx,ts,tsx}": ["eslint --fix", "prettier --write"],
3
- "*.{json,md,yml,yaml}": ["prettier --write"]
4
- }
package/.prettierignore DELETED
@@ -1,4 +0,0 @@
1
- node_modules
2
- dist
3
- *.min.js
4
- package-lock.json
package/.prettierrc DELETED
@@ -1,9 +0,0 @@
1
- {
2
- "semi": false,
3
- "singleQuote": true,
4
- "printWidth": 120,
5
- "tabWidth": 2,
6
- "trailingComma": "es5",
7
- "arrowParens": "always",
8
- "endOfLine": "lf"
9
- }
package/.versionrc.json DELETED
@@ -1,22 +0,0 @@
1
- {
2
- "header": "# 更新日志\n\n所有重要的变更都将记录在此文件中。\n\n",
3
- "types": [
4
- { "type": "feat", "section": "✨ 新功能" },
5
- { "type": "fix", "section": "🐛 Bug 修复" },
6
- { "type": "perf", "section": "⚡ 性能优化" },
7
- { "type": "refactor", "section": "♻️ 代码重构" },
8
- { "type": "docs", "section": "📝 文档更新" },
9
- { "type": "style", "section": "💄 代码格式" },
10
- { "type": "test", "section": "✅ 测试" },
11
- { "type": "build", "section": "📦 构建" },
12
- { "type": "ci", "section": "👷 CI" },
13
- { "type": "chore", "section": "🔧 其他" }
14
- ],
15
- "skip": {
16
- "bump": false,
17
- "changelog": false,
18
- "commit": false,
19
- "tag": false
20
- },
21
- "releaseCommitMessageFormat": "chore(release): {{currentTag}} [skip ci]"
22
- }
@@ -1,23 +0,0 @@
1
- module.exports = {
2
- extends: ['@commitlint/config-conventional'],
3
- rules: {
4
- 'type-enum': [
5
- 2,
6
- 'always',
7
- [
8
- 'feat', // 新功能
9
- 'fix', // 修复 bug
10
- 'docs', // 文档更新
11
- 'style', // 代码格式(不影响代码运行的变动)
12
- 'refactor', // 重构(既不是新增功能,也不是修复 bug)
13
- 'perf', // 性能优化
14
- 'test', // 增加测试
15
- 'build', // 构建过程或辅助工具的变动
16
- 'ci', // CI 配置文件和脚本的变动
17
- 'chore', // 其他不修改 src 或 test 的变动
18
- 'revert', // 回退
19
- ],
20
- ],
21
- 'subject-case': [0], // 不限制主题大小写
22
- },
23
- }
package/docs/README.md DELETED
@@ -1,80 +0,0 @@
1
- # @brewer/dj-common API 文档
2
-
3
- > 多端通用的公共方法库 API 文档
4
-
5
- ## 快速开始
6
-
7
- ```bash
8
- npm install @brewer/dj-common
9
- ```
10
-
11
- ## 模块列表
12
-
13
- ### WebSocket 相关
14
-
15
- - [WebSocketClient](./api/WebSocketClient.md) - 通用 WebSocket 客户端基类
16
- - [MessageSocket](./api/MessageSocket.md) - 业务层 WebSocket 封装
17
-
18
- ## 使用指南
19
-
20
- ### 基础使用
21
-
22
- ```typescript
23
- import { WebSocketClient } from '@brewer/dj-common'
24
-
25
- const client = new WebSocketClient({
26
- heartbeatInterval: 30000,
27
- autoReconnect: true,
28
- })
29
-
30
- client.on('message', (data) => {
31
- console.log('收到消息:', data)
32
- })
33
-
34
- client.connect('ws://localhost:8080')
35
- ```
36
-
37
- ### 类型安全
38
-
39
- 所有模块都提供完整的 TypeScript 类型定义:
40
-
41
- ```typescript
42
- import { WebSocketClient, WebSocketConfig, MessageData } from '@brewer/dj-common'
43
-
44
- const config: WebSocketConfig = {
45
- heartbeatInterval: 30000,
46
- maxReconnectAttempts: 10,
47
- }
48
-
49
- const client = new WebSocketClient(config)
50
-
51
- client.on<{ content: string }>('message', (data) => {
52
- // data 类型为 { content: string }
53
- console.log(data.content)
54
- })
55
- ```
56
-
57
- ## 特性
58
-
59
- - 📘 **TypeScript** - 完整的类型定义
60
- - 📦 **多格式支持** - ESM 和 CommonJS
61
- - 🔌 **按需引入** - Tree-shaking 支持
62
- - 🔧 **可配置** - 灵活的配置选项
63
- - 🔄 **自动重连** - 智能重连机制
64
- - 💓 **心跳检测** - 保持连接活性
65
-
66
- ## 相关链接
67
-
68
- - [GitHub 仓库](https://github.com/beerui/dj-common)
69
- - [NPM 包](https://www.npmjs.com/package/@brewer/dj-common)
70
- - [更新日志](../CHANGELOG.md)
71
- - [开发指南](../DEVELOPMENT.md)
72
- - [测试指南](../TESTING.md)
73
-
74
- ## 贡献
75
-
76
- 欢迎贡献代码!请查看 [开发指南](../DEVELOPMENT.md) 了解如何参与开发。
77
-
78
- ## 许可证
79
-
80
- MIT © BeerUi
package/eslint.config.js DELETED
@@ -1,76 +0,0 @@
1
- import js from '@eslint/js'
2
- import typescript from '@typescript-eslint/eslint-plugin'
3
- import typescriptParser from '@typescript-eslint/parser'
4
- import prettier from 'eslint-plugin-prettier'
5
- import prettierConfig from 'eslint-config-prettier'
6
-
7
- export default [
8
- // 全局忽略文件
9
- {
10
- ignores: ['node_modules/**', 'dist/**', 'examples/**'],
11
- },
12
-
13
- // JavaScript/TypeScript 通用配置
14
- {
15
- files: ['**/*.{js,mjs,cjs,ts}'],
16
- ignores: ['**/*.config.{js,mjs,cjs}'], // 忽略配置文件
17
- languageOptions: {
18
- ecmaVersion: 'latest',
19
- sourceType: 'module',
20
- parser: typescriptParser,
21
- parserOptions: {
22
- project: './tsconfig.json',
23
- },
24
- globals: {
25
- // 浏览器环境
26
- window: 'readonly',
27
- document: 'readonly',
28
- navigator: 'readonly',
29
- // Node.js 环境
30
- process: 'readonly',
31
- __dirname: 'readonly',
32
- __filename: 'readonly',
33
- module: 'readonly',
34
- require: 'readonly',
35
- exports: 'writable',
36
- global: 'readonly',
37
- // ES2021
38
- console: 'readonly',
39
- // 定时器相关(浏览器和 Node.js 都有)
40
- setTimeout: 'readonly',
41
- clearTimeout: 'readonly',
42
- setInterval: 'readonly',
43
- clearInterval: 'readonly',
44
- setImmediate: 'readonly',
45
- clearImmediate: 'readonly',
46
- },
47
- },
48
- plugins: {
49
- '@typescript-eslint': typescript,
50
- prettier: prettier,
51
- },
52
- rules: {
53
- // ESLint 推荐规则
54
- ...js.configs.recommended.rules,
55
- // TypeScript 推荐规则
56
- ...typescript.configs.recommended.rules,
57
- // Prettier 配置
58
- ...prettierConfig.rules,
59
-
60
- // 自定义规则
61
- 'no-console': 'off',
62
- 'no-unused-vars': 'off',
63
- '@typescript-eslint/no-unused-vars': ['warn', { argsIgnorePattern: '^_' }],
64
- '@typescript-eslint/no-explicit-any': 'warn',
65
- 'prettier/prettier': 'warn',
66
- },
67
- },
68
-
69
- // .js 和 .cjs 文件特殊配置
70
- {
71
- files: ['**/*.{js,cjs}'],
72
- rules: {
73
- '@typescript-eslint/no-var-requires': 'off',
74
- },
75
- },
76
- ]
@@ -1,39 +0,0 @@
1
- # dj-common 测试示例
2
-
3
- 这是一个简单的测试项目,用于验证 dj-common 包是否正常工作。
4
-
5
- ## 运行测试
6
-
7
- 在项目根目录(dj-common)执行:
8
-
9
- ```bash
10
- # 1. 构建项目
11
- npm run build
12
-
13
- # 2. 运行测试
14
- node examples/basic-test/index.js
15
- ```
16
-
17
- ## 测试内容
18
-
19
- - ✅ 创建 WebSocketClient 实例
20
- - ✅ 注册消息回调
21
- - ✅ 检查模块导出
22
-
23
- ## 使用 npm link 测试
24
-
25
- 如果想在其他项目中测试:
26
-
27
- ```bash
28
- # 在 dj-common 根目录
29
- npm link
30
-
31
- # 在其他项目中
32
- npm link @brewer/dj-common
33
- ```
34
-
35
- 然后就可以像正常安装的包一样使用了:
36
-
37
- ```javascript
38
- import { WebSocketClient } from '@brewer/dj-common'
39
- ```
@@ -1,56 +0,0 @@
1
- // 基础测试示例
2
- import { WebSocketClient } from '../../dist/index.esm.js'
3
-
4
- console.log('🧪 开始测试 dj-common...\n')
5
-
6
- // 测试 1: 创建实例
7
- console.log('✓ 测试 1: 创建 WebSocketClient 实例')
8
- try {
9
- const client = new WebSocketClient({
10
- heartbeatInterval: 30000,
11
- maxReconnectAttempts: 5,
12
- autoReconnect: true,
13
- })
14
- console.log(' ✅ 实例创建成功')
15
- console.log(' 配置:', {
16
- heartbeatInterval: 30000,
17
- maxReconnectAttempts: 5,
18
- autoReconnect: true,
19
- })
20
- } catch (error) {
21
- console.error(' ❌ 实例创建失败:', error.message)
22
- process.exit(1)
23
- }
24
-
25
- // 测试 2: 注册消息回调
26
- console.log('\n✓ 测试 2: 注册消息回调')
27
- try {
28
- const client = new WebSocketClient()
29
- client.on('test-message', (data) => {
30
- console.log('收到消息:', data)
31
- })
32
- console.log(' ✅ 消息回调注册成功')
33
- } catch (error) {
34
- console.error(' ❌ 消息回调注册失败:', error.message)
35
- process.exit(1)
36
- }
37
-
38
- // 测试 3: 检查类型导出
39
- console.log('\n✓ 测试 3: 检查导出')
40
- try {
41
- console.log(' ✅ WebSocketClient 已导出')
42
- console.log(' 类型:', typeof WebSocketClient)
43
- } catch (error) {
44
- console.error(' ❌ 导出检查失败:', error.message)
45
- process.exit(1)
46
- }
47
-
48
- console.log('\n🎉 所有测试通过!\n')
49
- console.log('💡 提示:')
50
- console.log(' - 要测试 WebSocket 连接,需要启动一个 WebSocket 服务器')
51
- console.log(' - 然后取消注释下面的连接代码\n')
52
-
53
- // 实际连接测试(需要 WebSocket 服务器)
54
- // console.log('✓ 测试 4: 连接 WebSocket 服务器')
55
- // const client = new WebSocketClient()
56
- // client.connect('ws://localhost:8080')
@@ -1,10 +0,0 @@
1
- {
2
- "name": "@brewer/dj-common-test",
3
- "version": "1.0.0",
4
- "private": true,
5
- "description": "Test example for @brewer/dj-common",
6
- "type": "module",
7
- "scripts": {
8
- "test": "node index.js"
9
- }
10
- }
@@ -1,98 +0,0 @@
1
- #!/bin/bash
2
-
3
- # 发布脚本 - 自动化 npm 包发布流程
4
-
5
- set -e
6
-
7
- echo "🚀 开始发布流程..."
8
- echo ""
9
-
10
- # 1. 检查是否在 git 仓库中
11
- if [ ! -d ".git" ]; then
12
- echo "❌ 错误: 当前目录不是 git 仓库"
13
- exit 1
14
- fi
15
-
16
- # 2. 检查是否有未提交的更改
17
- if [[ -n $(git status -s) ]]; then
18
- echo "❌ 错误: 有未提交的更改,请先提交或暂存"
19
- git status -s
20
- exit 1
21
- fi
22
-
23
- # 3. 确保在主分支
24
- CURRENT_BRANCH=$(git rev-parse --abbrev-ref HEAD)
25
- if [ "$CURRENT_BRANCH" != "main" ] && [ "$CURRENT_BRANCH" != "master" ]; then
26
- echo "⚠️ 警告: 当前不在 main/master 分支"
27
- read -p "是否继续? (y/N) " -n 1 -r
28
- echo
29
- if [[ ! $REPLY =~ ^[Yy]$ ]]; then
30
- exit 1
31
- fi
32
- fi
33
-
34
- # 4. 拉取最新代码
35
- echo "📥 拉取最新代码..."
36
- git pull origin $CURRENT_BRANCH || true
37
- echo ""
38
-
39
- # 5. 运行代码检查
40
- echo "🔍 运行代码检查..."
41
- npm run lint
42
- echo ""
43
-
44
- # 6. 运行构建
45
- echo "📦 构建项目..."
46
- npm run build
47
- echo ""
48
-
49
- # 7. 选择版本类型
50
- echo "请选择版本更新类型:"
51
- echo " 1) patch (bug 修复) - 1.0.0 -> 1.0.1"
52
- echo " 2) minor (新功能) - 1.0.0 -> 1.1.0"
53
- echo " 3) major (破坏性更新) - 1.0.0 -> 2.0.0"
54
- echo " 4) custom (自定义)"
55
- echo ""
56
- read -p "请输入选项 (1-4): " version_type
57
-
58
- case $version_type in
59
- 1)
60
- npm run release:patch
61
- ;;
62
- 2)
63
- npm run release:minor
64
- ;;
65
- 3)
66
- npm run release:major
67
- ;;
68
- 4)
69
- read -p "请输入版本号 (如 1.2.3): " custom_version
70
- npm run release -- --release-as $custom_version
71
- ;;
72
- *)
73
- echo "❌ 无效的选项"
74
- exit 1
75
- ;;
76
- esac
77
-
78
- echo ""
79
-
80
- # 8. 推送到远程仓库
81
- echo "📤 推送到远程仓库..."
82
- git push --follow-tags origin $CURRENT_BRANCH
83
- echo ""
84
-
85
- # 9. 发布到 npm
86
- read -p "是否发布到 npm? (y/N) " -n 1 -r
87
- echo
88
- if [[ $REPLY =~ ^[Yy]$ ]]; then
89
- echo "📦 发布到 npm..."
90
- npm publish
91
- echo ""
92
- echo "✅ 发布成功!"
93
- else
94
- echo "⏭️ 跳过 npm 发布"
95
- fi
96
-
97
- echo ""
98
- echo "🎉 发布流程完成!"
package/tsconfig.json DELETED
@@ -1,25 +0,0 @@
1
- {
2
- "compilerOptions": {
3
- "target": "ES2020",
4
- "module": "ESNext",
5
- "lib": ["ES2020", "DOM"],
6
- "declaration": true,
7
- "declarationMap": true,
8
- "outDir": "./dist",
9
- "rootDir": "./src",
10
- "removeComments": false,
11
- "strict": true,
12
- "esModuleInterop": true,
13
- "skipLibCheck": true,
14
- "forceConsistentCasingInFileNames": true,
15
- "moduleResolution": "node",
16
- "resolveJsonModule": true,
17
- "isolatedModules": true,
18
- "noUnusedLocals": true,
19
- "noUnusedParameters": true,
20
- "noImplicitReturns": true,
21
- "noFallthroughCasesInSwitch": true
22
- },
23
- "include": ["src/**/*"],
24
- "exclude": ["node_modules", "dist", "**/*.spec.ts"]
25
- }