cajonzero 0.1.2 → 0.2.0

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/LICENSE CHANGED
@@ -1,21 +1,21 @@
1
- MIT License
2
-
3
- Copyright (c) 2026 Toby Lai
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining a copy
6
- of this software and associated documentation files (the "Software"), to deal
7
- in the Software without restriction, including without limitation the rights
8
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- copies of the Software, and to permit persons to whom the Software is
10
- furnished to do so, subject to the following conditions:
11
-
12
- The above copyright notice and this permission notice shall be included in all
13
- copies or substantial portions of the Software.
14
-
15
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
- SOFTWARE.
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Toby Lai
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,7 +1,7 @@
1
1
  # cajonzero
2
2
 
3
3
  运行在 Cloudflare 上的 BOX3 游玩端引擎:内置账号系统,每个房间是一个
4
- Durable Object,地图存放在 OSS/CDN。
4
+ Durable Object,地图默认随 worker 作为静态资源部署(也可改 CDN)。
5
5
 
6
6
  ## 安装
7
7
 
@@ -26,47 +26,69 @@ npm run demo # http://127.0.0.1:8787
26
26
  npx cj0 create my-server
27
27
  cd my-server
28
28
  npm install
29
- npx cj0 setup # 交互配置 ENV:vars 写 wrangler.jsonc,密钥写 .dev.vars
29
+ npx cj0 setup # 交互配置 ENV + KV namespace
30
30
  npm run dev
31
31
  ```
32
32
 
33
33
  ## 部署
34
34
 
35
35
  ```bash
36
- npx wrangler kv namespace create CAJONZERO_KV # 把返回的 id 填进 wrangler.jsonc
36
+ npx cj0 setup # vars/密钥/KV(可自动创建 KV namespace)
37
37
  npx wrangler secret put CAJONZERO_SESSION_SECRET # 会话签名密钥
38
38
  npx wrangler secret put BOX_PLAY_ADMIN_TOKEN # 管理后台令牌
39
39
  npm run deploy
40
40
  ```
41
41
 
42
- ## 配置地图
43
-
44
- 地图文件单独上传,不随 worker 打包。把解包后的 `.boxplay` 目录上传到
45
- OSS/S3/CDN(需允许 CORS),然后在 `cajonzero/maps.json` 中登记:
46
-
47
- ```json
48
- {
49
- "version": 1,
50
- "maps": [
51
- {
52
- "slug": "race",
53
- "root": "https://<你的 CDN>/box3/race/",
54
- "worldId": "<世界 id>",
55
- "name": "显示名"
56
- }
57
- ]
58
- }
42
+ `cj0 setup` 会把 KV namespace id 写进 `wrangler.jsonc`;如果当时没有登录
43
+ wrangler,也可以手动运行 `npx wrangler kv namespace create <name> --update-config --binding CAJONZERO_KV`。
44
+
45
+ ## 导入地图
46
+
47
+ 地图在本地从 `.boxplay` 导入,写进项目的 `public/`,随 worker 一次部署:
48
+
49
+ ```bash
50
+ npx cj0 add ./race.boxplay # 解包到 public/maps/race/
51
+ npx cj0 update race ./race-v2.boxplay # 覆盖已有 slug
52
+ npx cj0 list # catalog + 本地导入状态
53
+ npx cj0 remove race # 删除地图、私有脚本、catalog
59
54
  ```
60
55
 
61
- `root` 必须以 `/` 结尾;更新地图后刷新 CDN 缓存或改用带版本的路径。
62
- 房间参数、地图拉取策略等配置位于 `cajonzero/config.json`。
56
+ `add/update` 会一次性完成:
57
+
58
+ 1. 公开地图资源写到 `public/maps/<slug>/`(`bundle.json`、`worlds/...`);
59
+ 2. 在本地解析世界图,写出 `public/maps/<slug>/seed.json.gz`,房间启动只读这一个文件;
60
+ 3. **服务端脚本**写到 `cajonzero/private/<slug>.json.gz`,不会进入公开的
61
+ `public/`;客户端脚本仍会保留在地图目录里;
62
+ 4. 在 `cajonzero/maps.json` 写入 `"root": "/maps/<slug>/"`,并把服端脚本文件记录为
63
+ `"scriptsFile": "cajonzero/private/<slug>.json.gz"`(该目录会提交,CF 构建时 `cj0 deploy` 可上传)。
64
+
65
+ `seed` 在 `add/update` 时构建,不再有独立的 build/seed 步骤。`cj0 update` 默认保留
66
+ 你手工改成 CDN 绝对地址的 `root`;`--reset-root` 可恢复为 `/maps/<slug>/`。
67
+
68
+ ### 使用独立 CDN
69
+
70
+ 如果不想把地图放进 worker 的静态资源,把对应条目的 `root` 改成
71
+ `https://<你的 CDN>/box3/race/` 即可(需允许 CORS)。运行时会自动走 HTTP 读取;
72
+ `seed.json.gz` 也放在同一个 root 下即可。
73
+
74
+ > Worker 静态资源限制:免费版 20,000 文件 / 单文件 25 MiB,付费版 100,000 文件。
75
+ > 超出时改用 CDN。
76
+
77
+ 房间参数、地图拉取策略等配置位于 `cajonzero/config.json`。服务端脚本由
78
+ `cj0 deploy` 上传到 KV(`CAJONZERO_SCRIPTS`,缺省回退 `CAJONZERO_KV`)。
63
79
 
64
80
  ## 常用命令
65
81
 
66
82
  ```bash
67
- cj0 create <folder> # 生成部署项目
68
- cj0 setup [--config <file>] # 交互配置必需/可选的 ENV
69
- cj0 serve [--port <port>] [--host <host>] # 本地启动
70
- npm test # 运行测试
71
- npm run ci:gates # 完整检查(类型/测试/构建)
83
+ cj0 create <folder> # 生成部署项目(并同步 UI 到 public/)
84
+ cj0 setup [--config <file>] # 配置 ENV + KV namespace(id)
85
+ cj0 add <file.boxplay> [--slug <slug>] # 导入地图
86
+ cj0 update <slug> <file.boxplay> # 替换地图
87
+ cj0 list [--json] # 查看地图 catalog
88
+ cj0 remove <slug> # 删除地图
89
+ cj0 sync [--config <file>] # 把包内 UI 同步到 public/
90
+ cj0 deploy [--config <file>] # 同步 UI + 上传脚本 + wrangler deploy
91
+ cj0 serve [--port <port>] [--host <host>] # 本地启动
92
+ npm test # 运行测试
93
+ npm run ci:gates # 完整检查(类型/测试/构建)
72
94
  ```