drgame-cc 1.0.12 → 1.0.13

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.
Files changed (2) hide show
  1. package/README.md +351 -0
  2. package/package.json +1 -1
package/README.md ADDED
@@ -0,0 +1,351 @@
1
+ # drgame-cc
2
+
3
+ **道然游戏 Cocos Creator 适配包** - 专为 Cocos Creator 项目设计的资源管理与构建优化工具
4
+
5
+ [![npm version](https://img.shields.io/npm/v/drgame-cc.svg)](https://www.npmjs.com/package/drgame-cc)
6
+ [![license](https://img.shields.io/npm/l/drgame-cc.svg)](https://github.com/your-repo/drgame-cc/blob/main/LICENSE)
7
+ [![node](https://img.shields.io/node/v/drgame-cc.svg)](https://nodejs.org)
8
+
9
+ ## 📖 项目简介
10
+
11
+ drgame-cc 是一个用于 **Cocos Creator 项目**的 npm 工具包,提供以下核心功能:
12
+
13
+ - ✅ **自动资源管理**:安装时自动将 UI 组件和构建模板同步到你的 Cocos Creator 项目
14
+ - ✅ **TVUI 组件库**:内置电视游戏 UI 组件,开箱即用
15
+ - ✅ **构建模板优化**:预配置 Web Mobile 构建模板,包含 HLS 视频支持、启动画面等
16
+ - ✅ **TypeScript 支持**:完整的类型定义,开发体验友好
17
+ - ✅ **CLI 工具**:提供命令行接口,方便集成到自动化流程
18
+
19
+ ## 🚀 快速开始
20
+
21
+ ### 环境要求
22
+
23
+ - **Node.js**: >= 18.0.0
24
+ - **npm**: >= 8.0.0
25
+ - **Cocos Creator**: 2.4.x+
26
+
27
+ ### 安装
28
+
29
+ ```bash
30
+ # 在你的 Cocos Creator 项目根目录执行
31
+ npm install drgame-cc
32
+ ```
33
+
34
+ ### 手动触发资源拷贝
35
+
36
+ 由于 npm v10+ 的安全机制限制,postinstall 脚本可能需要手动执行:
37
+
38
+ ```bash
39
+ cd node_modules/drgame-cc
40
+ node scripts/postinstall.js
41
+ ```
42
+
43
+ 成功后会看到:
44
+ ```
45
+ ✅ 开始拷贝资源
46
+ 📦 宿主项目: /path/to/your/project
47
+ 📦 目标目录: /path/to/your/project
48
+ ✅ build-templates 拷贝完成
49
+ ✅ tvui 拷贝完成
50
+ 🎉 资源拷贝完成!
51
+ ```
52
+
53
+ ## 📁 项目结构
54
+
55
+ ```
56
+ drgame-cc/
57
+ ├── bin/ # 命令行工具
58
+ │ ├── drgame.js # 主入口
59
+ │ └── drgame.d.ts # 类型定义
60
+ ├── build-templates/ # Cocos Creator 构建模板
61
+ │ └── web-mobile/ # Web Mobile 平台模板
62
+ │ ├── src/hls.min.js # HLS 流媒体支持
63
+ │ ├── index.html # 入口 HTML
64
+ │ └── main.js # 主逻辑
65
+ ├── tvui/ # TV UI 组件资源
66
+ ├── scripts/
67
+ │ └── postinstall.js # 安装后脚本(自动拷贝资源)
68
+ ├── gulpfile.js # Gulp 构建配置
69
+ ├── tsconfig.json # TypeScript 配置
70
+ └── package.json # 包配置
71
+ ```
72
+
73
+ ## ⚙️ 功能详解
74
+
75
+ ### 1. TVUI 组件系统
76
+
77
+ 安装后,TVUI 组件会自动复制到 `assets/resources/tvui` 目录,包含:
78
+
79
+ - 预制体组件
80
+ - UI 样式资源
81
+ - 图标素材
82
+
83
+ 在 Cocos Creator 中使用:
84
+ ```typescript
85
+ import { SomeComponent } from 'drgame-cc';
86
+ ```
87
+
88
+ ### 2. Web Mobile 构建模板
89
+
90
+ 内置优化的 Web Mobile 构建模板,特性包括:
91
+
92
+ - **HLS 视频支持**:内置 hls.min.js,支持 HTTP Live Streaming
93
+ - **自定义启动画面**:中英文启动页支持
94
+ - **加载动画**:进度条动画效果
95
+ - **响应式布局**:移动端适配样式
96
+
97
+ 模板位置:`build-templates/web-mobile/`
98
+
99
+ ### 3. 环境变量配置
100
+
101
+ 可通过 `.env` 文件自定义配置(仅本地开发用,不会发布):
102
+
103
+ ```env
104
+ # Cocos Creator 项目根目录(相对于当前目录)
105
+ COCOS_CREATOR_ROOT=../my-cocos-project
106
+ ```
107
+
108
+ > ⚠️ **注意**:`.env` 文件已加入 `.npmignore`,不会发布到 npm
109
+
110
+ ## 🛠️ 开发指南
111
+
112
+ ### 本地开发设置
113
+
114
+ ```bash
115
+ # 1. 克隆仓库
116
+ git clone <repository-url>
117
+ cd drgame-cc
118
+
119
+ # 2. 安装依赖
120
+ npm install
121
+
122
+ # 3. 构建 TypeScript
123
+ npm run build
124
+
125
+ # 4. 运行测试
126
+ npm test
127
+ ```
128
+
129
+ ### 可用的 npm Scripts
130
+
131
+ | 命令 | 说明 |
132
+ |------|------|
133
+ | `npm run build` | 编译 TypeScript 并拷贝资源 |
134
+ | `npm run buildJs` | 仅编译 JavaScript |
135
+ | `npm run buildDts` | 仅生成类型定义 |
136
+ | `npm run copyResources` | 拷贝资源到 Cocos Creator 项目 |
137
+
138
+ ### 开发流程
139
+
140
+ 1. **修改代码**
141
+ ```bash
142
+ # 编辑 src/ 目录下的 TypeScript 文件
143
+ ```
144
+
145
+ 2. **实时编译(推荐)**
146
+ ```bash
147
+ # 使用 tsc --watch 实时编译
148
+ npx tsc --watch
149
+ ```
150
+
151
+ 3. **测试修改**
152
+ ```bash
153
+ # 在测试项目中链接本地版本
154
+ cd /path/to/test-project
155
+ npm link ../drgame-cc
156
+
157
+ # 或者直接引用本地路径
158
+ # 在 package.json 中:
159
+ # "drgame-cc": "file:../drgame-cc"
160
+ ```
161
+
162
+ 4. **手动运行 postinstall 测试**
163
+ ```bash
164
+ node scripts/postinstall.js
165
+ ```
166
+
167
+ ## 📦 发布指南
168
+
169
+ ### 发布前检查清单
170
+
171
+ - [ ] 更新 `package.json` 中的版本号
172
+ - [ ] 更新 CHANGELOG.md(如有)
173
+ - [ ] 运行测试确保功能正常
174
+ - [ ] 确保 `.env` 不会被发布(已配置 `.npmignore`)
175
+ - [ ] 检查 `files` 字段只包含必要文件
176
+
177
+ ### 发布步骤
178
+
179
+ ```bash
180
+ # 1. 更新版本号(遵循语义化版本)
181
+ npm version patch # 补丁版本:1.0.x -> 1.0.(x+1)
182
+ npm version minor # 次版本:1.x.y -> 1.(x+1).0
183
+ npm version major # 主版本:x.y.z -> (x+1).0.0
184
+
185
+ # 2. 登录 npm(首次需要)
186
+ npm login
187
+
188
+ # 3. 干跑测试(查看将要发布的文件列表)
189
+ npm pack --dry-run
190
+
191
+ # 4. 正式发布
192
+ npm publish
193
+
194
+ # 5. 打 tag(可选)
195
+ git push origin main --tags
196
+ ```
197
+
198
+ ### 版本号规则
199
+
200
+ 我们遵循 [语义化版本](https://semver.org/lang/zh-CN/)规范:
201
+
202
+ - **MAJOR**:不兼容的 API 修改
203
+ - **MINOR**:向下兼容的功能性新增
204
+ - **PATCH**:向下兼容的问题修正
205
+
206
+ 示例:
207
+ ```
208
+ 1.0.12 -> 1.0.13 (patch: 修复 bug)
209
+ 1.0.12 -> 1.1.0 (minor: 新增功能)
210
+ 1.0.12 -> 2.0.0 (major: 重构或 breaking changes)
211
+ ```
212
+
213
+ ### 发布内容验证
214
+
215
+ 发布的 npm 包将包含以下文件(见 `package.json` 的 `files` 字段):
216
+
217
+ ```
218
+ drgame-cc-1.0.12.tgz
219
+ ├── tvui/**/* # TVUI 组件资源
220
+ ├── build-templates/**/* # 构建模板
221
+ ├── scripts/postinstall.js # 安装脚本
222
+ └── bin/**/* # CLI 工具
223
+ ```
224
+
225
+ **不会包含的内容**:
226
+ - ❌ `.env` / `.env.*` (环境变量配置)
227
+ - ❌ `node_modules/` (依赖)
228
+ - ❌ `dist/` / `*.tsbuildinfo` (编译产物)
229
+ - ❌ `src/` (源码)
230
+ - ❌ `.vscode/` / `.idea/` (编辑器配置)
231
+
232
+ ## 🔧 故障排除
233
+
234
+ ### 问题 1:postinstall 未自动执行
235
+
236
+ **症状**:安装成功但没有拷贝资源
237
+
238
+ **原因**:npm v10+ 默认阻止自动执行 install scripts
239
+
240
+ **解决方案**:
241
+ ```bash
242
+ # 方法 1:批准脚本
243
+ npm approve-scripts drgame-cc
244
+
245
+ # 方法 2:手动执行
246
+ cd node_modules/drgame-cc
247
+ node scripts/postinstall.js
248
+ ```
249
+
250
+ ### 问题 2:找不到目标目录
251
+
252
+ **症状**:报错 `ENOENT: no such file or directory`
253
+
254
+ **解决方案**:
255
+ ```bash
256
+ # 创建 .env 文件并配置正确路径
257
+ echo "COCOS_CREATOR_ROOT=/absolute/path/to/cocos" > .env
258
+ ```
259
+
260
+ ### 问题 3:权限错误 (EPERM)
261
+
262
+ **症状**:Windows 上删除 node_modules 失败
263
+
264
+ **解决方案**:
265
+ ```powershell
266
+ # 以管理员身份运行 PowerShell
267
+ # 或使用 rimraf
268
+ npx rimraf node_modules
269
+ npm install
270
+ ```
271
+
272
+ ### 问题 4:TypeScript 编译错误
273
+
274
+ **症状**:`Cannot find module 'xxx'`
275
+
276
+ **解决方案**:
277
+ ```bash
278
+ # 清除缓存重新安装
279
+ rm -rf node_modules package-lock.json
280
+ npm install
281
+
282
+ # 检查 TypeScript 版本
283
+ npx tsc --version # 应该是 5.9.3
284
+ ```
285
+
286
+ ## 📚 API 文档
287
+
288
+ ### CLI 使用
289
+
290
+ ```bash
291
+ # 查看帮助
292
+ drgame-cc --help
293
+
294
+ # 拷贝资源
295
+ drgame-cc copy
296
+ ```
297
+
298
+ ### TypeScript 接口
299
+
300
+ ```typescript
301
+ // 导入主模块
302
+ import { SomeClass } from 'drgame-cc';
303
+
304
+ // 类型定义自动支持
305
+ const instance: SomeClass = new SomeClass();
306
+ ```
307
+
308
+ 详细 API 文档请参考 `bin/dgame.d.ts`。
309
+
310
+ ## 🤝 贡献指南
311
+
312
+ 欢迎贡献代码!请遵循以下流程:
313
+
314
+ 1. Fork 本仓库
315
+ 2. 创建特性分支 (`git checkout -b feature/amazing-feature`)
316
+ 3. 提交更改 (`git commit -m 'Add some amazing feature'`)
317
+ 4. 推送到分支 (`git push origin feature/amazing-feature`)
318
+ 5. 提交 Pull Request
319
+
320
+ ### 代码规范
321
+
322
+ - 使用 TypeScript 编写代码
323
+ - 遵循 ESLint 配置(项目已配置)
324
+ - 提交信息使用 Conventional Commits 规范
325
+
326
+ ## 📄 许可证
327
+
328
+ 本项目基于 [MIT License](LICENSE) 开源。
329
+
330
+ ## 🙏 致谢
331
+
332
+ - [Cocos Creator](https://www.cocos.com/) - 游戏引擎
333
+ - [Gulp](https://gulpjs.com/) - 构建工具
334
+ - [TypeScript](https://www.typescriptlang.org/) - 编程语言
335
+
336
+ ---
337
+
338
+ ## 📞 联系方式
339
+
340
+ - **问题反馈**:[GitHub Issues](https://github.com/your-repo/drgame-cc/issues)
341
+ - **功能建议**:[GitHub Discussions](https://github.com/your-repo/drgame-cc/discussions)
342
+
343
+ ---
344
+
345
+ <div align="center">
346
+
347
+ **⭐ 如果这个项目对你有帮助,请给一个 Star!⭐**
348
+
349
+ Made with ❤️ by [道然游戏](https://your-company.com)
350
+
351
+ </div>
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "drgame-cc",
3
- "version": "1.0.12",
3
+ "version": "1.0.13",
4
4
  "description": "道然游戏适配包",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",