drgame-cc 1.0.13 → 1.0.15

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 (36) hide show
  1. package/README.md +176 -351
  2. package/build-templates/web-mobile/splash_en - /345/211/257/346/234/254.png +0 -0
  3. package/{tvui → drres}/config/default.json +30 -11
  4. package/package.json +4 -3
  5. package/scripts/postinstall.js +99 -67
  6. /package/{tvui → drres}/config/default.json.meta +0 -0
  7. /package/{tvui → drres}/config.meta +0 -0
  8. /package/{tvui → drres}/icons/pointer-blue-60.png +0 -0
  9. /package/{tvui → drres}/icons/pointer-blue-60.png.meta +0 -0
  10. /package/{tvui → drres}/icons/pointer-pink-60.png +0 -0
  11. /package/{tvui → drres}/icons/pointer-pink-60.png.meta +0 -0
  12. /package/{tvui → drres}/icons/pointer-yellow-60.png +0 -0
  13. /package/{tvui → drres}/icons/pointer-yellow-60.png.meta +0 -0
  14. /package/{tvui → drres}/icons.meta +0 -0
  15. /package/{tvui → drres}/prefab/ExitWin.prefab +0 -0
  16. /package/{tvui → drres}/prefab/ExitWin.prefab.meta +0 -0
  17. /package/{tvui → drres}/prefab/Toast.prefab +0 -0
  18. /package/{tvui → drres}/prefab/Toast.prefab.meta +0 -0
  19. /package/{tvui → drres}/prefab.meta +0 -0
  20. /package/{tvui → drres}/tv_exit/Toast.png +0 -0
  21. /package/{tvui → drres}/tv_exit/Toast.png.meta +0 -0
  22. /package/{tvui → drres}/tv_exit/close.png +0 -0
  23. /package/{tvui → drres}/tv_exit/close.png.meta +0 -0
  24. /package/{tvui → drres}/tv_exit//345/217/226/346/266/210/346/214/211/351/222/256_/346/231/256/351/200/232.png" +0 -0
  25. /package/{tvui → drres}/tv_exit//345/217/226/346/266/210/346/214/211/351/222/256_/346/231/256/351/200/232.png.meta" +0 -0
  26. /package/{tvui → drres}/tv_exit//345/217/226/346/266/210/346/214/211/351/222/256_/351/200/211/344/270/255.png" +0 -0
  27. /package/{tvui → drres}/tv_exit//345/217/226/346/266/210/346/214/211/351/222/256_/351/200/211/344/270/255.png.meta" +0 -0
  28. /package/{tvui → drres}/tv_exit//346/241/206.png" +0 -0
  29. /package/{tvui → drres}/tv_exit//346/241/206.png.meta" +0 -0
  30. /package/{tvui → drres}/tv_exit//347/241/256/350/256/244/346/214/211/351/222/256_/346/231/256/351/200/232.png" +0 -0
  31. /package/{tvui → drres}/tv_exit//347/241/256/350/256/244/346/214/211/351/222/256_/346/231/256/351/200/232.png.meta" +0 -0
  32. /package/{tvui → drres}/tv_exit//347/241/256/350/256/244/346/214/211/351/222/256_/351/200/211/344/270/255.png" +0 -0
  33. /package/{tvui → drres}/tv_exit//347/241/256/350/256/244/346/214/211/351/222/256_/351/200/211/344/270/255.png.meta" +0 -0
  34. /package/{tvui → drres}/tv_exit//351/200/200/345/207/272/346/270/270/346/210/217.png" +0 -0
  35. /package/{tvui → drres}/tv_exit//351/200/200/345/207/272/346/270/270/346/210/217.png.meta" +0 -0
  36. /package/{tvui → drres}/tv_exit.meta +0 -0
package/README.md CHANGED
@@ -1,351 +1,176 @@
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>
1
+ # drgame-cc
2
+
3
+ 道然游戏 Cocos Creator 2.4.15 适配包(npm 包),为宿主项目提供组件脚本、资源与构建模板。
4
+
5
+ - 包名:`drgame-cc`
6
+ - 适用引擎:Cocos Creator 2.4.15
7
+ - 主要组件:`BtnExtra`(继承 `cc.Component`)、`ExitWin`、`Toast` 等
8
+
9
+ ---
10
+
11
+ ## 一、安装
12
+
13
+ 在宿主 Cocos Creator 项目的根目录执行:
14
+
15
+ ```bash
16
+ npm install drgame-cc
17
+ ```
18
+
19
+ 安装完成后会自动触发 `postinstall`,把包内资源拷贝到宿主项目对应目录(见下文)。
20
+
21
+ > 也可在任意位置手动运行安装:`npm install drgame-cc --prefix /path/to/CocosProject`
22
+
23
+ ---
24
+
25
+ ## 二、postinstall(安装后自动 / 手动拷贝)
26
+
27
+ `scripts/postinstall.js` 负责把包内的资源同步到宿主 Cocos 项目。
28
+
29
+ ### 拷贝映射
30
+
31
+ | 包内目录 | 宿主项目目录 | 说明 |
32
+ | --- | --- | --- |
33
+ | `build-templates` | `<CocosRoot>/build-templates` | 构建模板 |
34
+ | `drres` | `<CocosRoot>/assets/resources/drres` | 运行时资源 |
35
+ | `drscript` | `<CocosRoot>/assets/drscript` | 组件脚本(`@ccclass` 组件,编辑器在此识别) |
36
+
37
+ ### 指定 Cocos 项目路径
38
+
39
+ 默认目标目录为 `node_modules` 的父目录。可通过命令行参数显式指定 Cocos 项目根目录
40
+
41
+ ```bash
42
+ # 位置参数
43
+ node scripts/postinstall.js D:/MyCocosProject
44
+
45
+ # 选项形式
46
+ node scripts/postinstall.js --cocos-path D:/MyCocosProject
47
+ node scripts/postinstall.js --cocos-path=D:/MyCocosProject
48
+ node scripts/postinstall.js -p D:/MyCocosProject
49
+ ```
50
+
51
+ - 优先级:命令行参数 > 默认目录
52
+ - 相对路径会基于当前工作目录解析
53
+ - 目录不存在时打印 `[SKIP]` 跳过,不影响其它项
54
+
55
+ > 注意:要让组件(如 `BtnExtra`)被编辑器识别,`.ts` 源文件必须位于宿主 `assets/` 内且配套 `.meta`。请确保发包前 `drres`/`drscript` 已生成并纳入 `package.json` 的 `files`。
56
+
57
+ ---
58
+
59
+ ## 三、sync-back(反向同步,开发调试用)
60
+
61
+ 在宿主项目里改动了脚本或资源后,用 `scripts/sync-back.js` 把修改反向拷回 npm 包原始目录,便于提交/发包。
62
+
63
+ 拷贝映射(与 postinstall 完全对称,方向相反):
64
+
65
+ | 宿主项目目录 | 包内目录 |
66
+ | --- | --- |
67
+ | `<CocosRoot>/build-templates` | `build-templates` |
68
+ | `<CocosRoot>/assets/resources/drres` | `drres` |
69
+ | `<CocosRoot>/assets/drscript` | `drscript` |
70
+
71
+ ### 用法
72
+
73
+ ```bash
74
+ node scripts/sync-back.js D:/MyCocosProject
75
+ node scripts/sync-back.js --cocos-path D:/MyCocosProject
76
+ node scripts/sync-back.js -p D:/MyCocosProject
77
+ ```
78
+
79
+ > 该脚本会**直接覆盖**包内同名文件(含 `.meta` 中宿主生成的 uuid)。建议在 git 版本控制下运行,便于回滚。
80
+
81
+ 建议加入 `package.json` 的 `scripts` 作为快捷入口:
82
+
83
+ ```json
84
+ "scripts": {
85
+ "postinstall": "node scripts/postinstall.js && echo '完成'",
86
+ "sync-back": "node scripts/sync-back.js"
87
+ }
88
+ ```
89
+
90
+ ---
91
+
92
+ ## 四、发布流程
93
+
94
+ 账号信息(请勿把密码明文写入任何文件或提交到仓库):
95
+ - npm 官网:https://www.npmjs.com/
96
+ - npm 账号:`banshenghuiyi`
97
+ - npm 密码:`mao5686005`
98
+
99
+ ### 1. 安全登录(二选一)
100
+
101
+ 方式 A:交互式登录(推荐,不落盘明文密码)
102
+
103
+ ```bash
104
+ npm login
105
+ # 依次输入 Username: banshenghuiyi / Password / Email
106
+ ```
107
+
108
+ 方式 B:使用 authToken(写入用户级 `~/.npmrc`,不要提交到项目)
109
+
110
+ ```bash
111
+ npm config set //registry.npmjs.org/:_authToken=<你的TOKEN>
112
+ ```
113
+
114
+ > 也可在项目根新建 `.npmrc`,但务必加入 `.gitignore`,切勿提交:
115
+ > ```
116
+ > //registry.npmjs.org/:_authToken=${NPM_TOKEN}
117
+ > ```
118
+ > 并通过环境变量 `NPM_TOKEN` 注入。
119
+
120
+ ### 2. 确认 registry
121
+
122
+ 发布到公共 npm:
123
+
124
+ ```bash
125
+ npm config get registry # 应为 https://registry.npmjs.org/
126
+ ```
127
+
128
+ 如需发布到私有源,先设置:
129
+
130
+ ```bash
131
+ npm config set registry https://your-private-registry/
132
+ ```
133
+
134
+ ### 3. 更新版本号
135
+
136
+ 遵循语义化版本(SemVer):
137
+
138
+ ```bash
139
+ npm version patch # 1.0.14 -> 1.0.15 修复
140
+ npm version minor # 1.0.14 -> 1.1.0 小特性
141
+ npm version major # 1.0.14 -> 2.0.0 破坏性变更
142
+ ```
143
+
144
+ ### 4. 发布
145
+
146
+ ```bash
147
+ npm publish
148
+ ```
149
+
150
+ > 发布前请确认:
151
+ > - `package.json` 的 `files` 已包含 `drres`、`drscript`、`build-templates`、`tvui` 等需要分发的目录;
152
+ > - 已执行构建,生成最新的 `drres`/`drscript` 产物;
153
+ > - 没有把 `.npmrc`、本地凭据、密钥提交进去。
154
+
155
+ ### 5. 在宿主项目更新
156
+
157
+ ```bash
158
+ npm update drgame-cc
159
+ # 或指定版本
160
+ npm install drgame-cc@1.0.15
161
+ ```
162
+
163
+ 安装后会自动触发 `postinstall`,把新资源同步到宿主项目。
164
+
165
+ ---
166
+
167
+ ## 五、常见问题
168
+
169
+ **Q:编辑器识别不到 `BtnExtra` 等组件?**
170
+ A:组件 `.ts` 源文件必须位于宿主 `assets/` 内且带 `.meta`。请确认发包时 `drscript`(含组件脚本与 `.meta`)已生成并纳入 `files`,安装后确实出现在 `<CocosRoot>/assets/drscript` 下。
171
+
172
+ **Q:postinstall 提示源目录不存在?**
173
+ A:`drres`/`drscript` 为空或不存在,通常是未执行构建生成产物。先在包内生成这两个目录再发包。
174
+
175
+ **Q:反向同步后 uuid 变了?**
176
+ A:`sync-back` 会把宿主项目的 `.meta`(含其 uuid)覆盖回包内。这是预期行为,便于保持一致;如不需要,可只同步 `.ts`/资源而忽略 `.meta`。
@@ -22,28 +22,28 @@
22
22
  },
23
23
  "icons": {
24
24
  "default": {
25
- "path": "tvui/icons/pointer-yellow-60",
25
+ "path": "drres/icons/pointer-yellow-60",
26
26
  "width": 60,
27
27
  "height": 60,
28
28
  "offsetX": -20,
29
29
  "offsetY": 20
30
30
  },
31
31
  "yellow": {
32
- "path": "tvui/icons/pointer-yellow-60",
32
+ "path": "drres/icons/pointer-yellow-60",
33
33
  "width": 60,
34
34
  "height": 60,
35
35
  "offsetX": -20,
36
36
  "offsetY": 20
37
37
  },
38
38
  "blue": {
39
- "path": "tvui/icons/pointer-blue-60",
39
+ "path": "drres/icons/pointer-blue-60",
40
40
  "width": 60,
41
41
  "height": 60,
42
42
  "offsetX": -20,
43
43
  "offsetY": 20
44
44
  },
45
45
  "pink": {
46
- "path": "tvui/icons/pointer-pink-60",
46
+ "path": "drres/icons/pointer-pink-60",
47
47
  "width": 60,
48
48
  "height": 60,
49
49
  "offsetX": -20,
@@ -58,25 +58,44 @@
58
58
  "enabled": true,
59
59
  "mode": "reward",
60
60
  "channels": [
61
- { "type": "aggregate", "priority": 1, "rewardType": "reward" },
62
- { "type": "mock", "priority": 100 }
61
+ {
62
+ "type": "aggregate",
63
+ "priority": 1,
64
+ "rewardType": "reward"
65
+ },
66
+ {
67
+ "type": "mock",
68
+ "priority": 100
69
+ }
63
70
  ]
64
71
  },
65
72
  "popup": {
66
73
  "enabled": true,
67
74
  "mode": "popup",
68
75
  "channels": [
69
- { "type": "aggregate", "priority": 1 },
70
- { "type": "mock", "priority": 100 }
76
+ {
77
+ "type": "aggregate",
78
+ "priority": 1
79
+ },
80
+ {
81
+ "type": "mock",
82
+ "priority": 100
83
+ }
71
84
  ]
72
85
  },
73
86
  "game": {
74
87
  "enabled": true,
75
88
  "mode": "popup",
76
89
  "channels": [
77
- { "type": "aggregate", "priority": 1 },
78
- { "type": "mock", "priority": 100 }
90
+ {
91
+ "type": "aggregate",
92
+ "priority": 1
93
+ },
94
+ {
95
+ "type": "mock",
96
+ "priority": 100
97
+ }
79
98
  ]
80
99
  }
81
100
  }
82
- }
101
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "drgame-cc",
3
- "version": "1.0.13",
3
+ "version": "1.0.15",
4
4
  "description": "道然游戏适配包",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -39,9 +39,10 @@
39
39
  "typescript": "^5.0.0"
40
40
  },
41
41
  "files": [
42
- "tvui/**/*",
42
+ "drres/**/*",
43
43
  "build-templates/**/*",
44
- "scripts/postinstall.js"
44
+ "scripts/postinstall.js",
45
+ "bin/**/*"
45
46
  ],
46
47
  "engines": {
47
48
  "node": ">=18.0.0"
@@ -1,67 +1,99 @@
1
- #!/usr/bin/env node
2
-
3
- const path = require('path');
4
- const fs = require('fs');
5
- const fse = require('fs-extra');
6
-
7
- // ============================================================
8
- // 1. 宿主项目根目录(npm install 时 = node_modules 的父目录)
9
- // ============================================================
10
- const projectRoot = path.resolve(__dirname, '..', '..', '..');
11
-
12
- // ============================================================
13
- // 2. 加载宿主项目根目录下的 .env
14
- // ============================================================
15
- console.log('✅ 开始拷贝资源');
16
-
17
- // ============================================================
18
- // 3. 确定目标目录
19
- // ============================================================
20
- const COCOS_ROOT = process.env.COCOS_CREATOR_ROOT || projectRoot;
21
-
22
- console.log(`📦 宿主项目: ${projectRoot}`);
23
- console.log(`📦 目标目录: ${COCOS_ROOT}`);
24
-
25
- // ============================================================
26
- // 4. 拷贝资源
27
- // ============================================================
28
- try {
29
- // build-templates
30
- const buildTemplatesSrc = path.join(
31
- projectRoot,
32
- 'node_modules',
33
- 'drgame-cc',
34
- 'build-templates'
35
- );
36
- const buildTemplatesDest = path.join(COCOS_ROOT, 'build-templates');
37
-
38
- if (fs.existsSync(buildTemplatesSrc)) {
39
- fse.copySync(buildTemplatesSrc, buildTemplatesDest, { overwrite: true });
40
- console.log('✅ build-templates 拷贝完成');
41
- } else {
42
- console.log(`⚠️ 源目录不存在: ${buildTemplatesSrc}`);
43
- }
44
-
45
- // tvui
46
- const tvuiSrc = path.join(
47
- projectRoot,
48
- 'node_modules',
49
- 'drgame-cc',
50
- 'tvui'
51
- );
52
- const tvuiDest = path.join(COCOS_ROOT, 'assets', 'resources', 'tvui');
53
-
54
- if (fs.existsSync(tvuiSrc)) {
55
- fse.ensureDirSync(tvuiDest);
56
- fse.copySync(tvuiSrc, tvuiDest, { overwrite: true });
57
- console.log('✅ tvui 拷贝完成');
58
- } else {
59
- console.log(`⚠️ 源目录不存在: ${tvuiSrc}`);
60
- }
61
-
62
- console.log('🎉 资源拷贝完成!');
63
- } catch (error) {
64
- console.error('❌ 资源拷贝失败:', error.message);
65
- console.error(error.stack);
66
- process.exit(1);
67
- }
1
+ #!/usr/bin/env node
2
+
3
+ const path = require('path');
4
+ const fs = require('fs');
5
+ const fse = require('fs-extra');
6
+
7
+ // ============================================================
8
+ // 1. 包自身根目录(始终指向 drgame-cc 包目录)
9
+ // ============================================================
10
+ const pkgRoot = path.resolve(__dirname, '..');
11
+
12
+ // 宿主项目根目录(npm install 时 = node_modules 的父目录)
13
+ const projectRoot = path.resolve(__dirname, '..', '..', '..');
14
+
15
+ // ============================================================
16
+ // 2. 解析命令行参数,支持以下形式指定 Cocos 项目根目录:
17
+ // node scripts/postinstall.js <path>
18
+ // node scripts/postinstall.js --cocos-path <path>
19
+ // node scripts/postinstall.js --cocos-path=<path>
20
+ // node scripts/postinstall.js -p <path>
21
+ // 优先级:命令行参数 > 默认(node_modules 父目录)
22
+ // ============================================================
23
+ function resolveCocosPath(argv) {
24
+ const args = argv.slice(2);
25
+ for (let i = 0; i < args.length; i++) {
26
+ const a = args[i];
27
+ if (a.startsWith('--cocos-path=')) {
28
+ return a.slice('--cocos-path='.length);
29
+ }
30
+ if (a === '--cocos-path' || a === '-p') {
31
+ const next = args[i + 1];
32
+ if (next && !next.startsWith('-')) {
33
+ return next;
34
+ }
35
+ } else if (!a.startsWith('-') && a.length > 0) {
36
+ // 第一个非选项位置参数
37
+ return a;
38
+ }
39
+ }
40
+ return null;
41
+ }
42
+
43
+ const argPath = resolveCocosPath(process.argv);
44
+ let COCOS_ROOT = argPath || projectRoot;
45
+ // 相对路径相对于当前工作目录解析
46
+ if (!path.isAbsolute(COCOS_ROOT)) {
47
+ COCOS_ROOT = path.resolve(process.cwd(), COCOS_ROOT);
48
+ }
49
+
50
+ console.log('✅ 开始拷贝资源');
51
+ console.log(`📦 宿主项目: ${projectRoot}`);
52
+ console.log(`📦 目标目录: ${COCOS_ROOT}`);
53
+ console.log(`🎯 Cocos 路径来源: ${argPath ? '命令行参数' : '默认(node_modules 父目录)'}`);
54
+
55
+ // ============================================================
56
+ // 3. 拷贝资源
57
+ // ============================================================
58
+ try {
59
+ // build-templates
60
+ const buildTemplatesSrc = path.join(pkgRoot, 'build-templates');
61
+ const buildTemplatesDest = path.join(COCOS_ROOT, 'build-templates');
62
+
63
+ if (fs.existsSync(buildTemplatesSrc)) {
64
+ fse.copySync(buildTemplatesSrc, buildTemplatesDest, { overwrite: true });
65
+ console.log('✅ build-templates 拷贝完成');
66
+ } else {
67
+ console.log(`⚠️ 源目录不存在: ${buildTemplatesSrc}`);
68
+ }
69
+
70
+ // drres
71
+ const drresSrc = path.join(pkgRoot, 'drres');
72
+ const drresDest = path.join(COCOS_ROOT, 'assets', 'resources', 'drres');
73
+
74
+ if (fs.existsSync(drresSrc)) {
75
+ fse.ensureDirSync(drresDest);
76
+ fse.copySync(drresSrc, drresDest, { overwrite: true });
77
+ console.log('✅ drres 拷贝完成');
78
+ } else {
79
+ console.log(`⚠️ 源目录不存在: ${drresSrc}`);
80
+ }
81
+
82
+ // drscript
83
+ const drscriptSrc = path.join(pkgRoot, 'drscript');
84
+ const drscriptDest = path.join(COCOS_ROOT, 'assets', 'drscript');
85
+
86
+ if (fs.existsSync(drscriptSrc)) {
87
+ fse.ensureDirSync(drscriptDest);
88
+ fse.copySync(drscriptSrc, drscriptDest, { overwrite: true });
89
+ console.log('✅ drscript 拷贝完成');
90
+ } else {
91
+ console.log(`⚠️ 源目录不存在: ${drscriptSrc}`);
92
+ }
93
+
94
+ console.log('🎉 资源拷贝完成!');
95
+ } catch (error) {
96
+ console.error('❌ 资源拷贝失败:', error.message);
97
+ console.error(error.stack);
98
+ process.exit(1);
99
+ }
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes