castle-web-cli 0.4.229 → 0.4.230
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/dist/agent-prompts.d.ts +2 -0
- package/dist/agent-prompts.js +16 -8
- package/dist/agent.d.ts +2 -0
- package/dist/agent.js +21 -21
- package/dist/api.d.ts +28 -2
- package/dist/api.js +74 -16
- package/dist/castle-host/host.d.ts +91 -0
- package/dist/castle-host/host.js +779 -3
- package/dist/castleJson.d.ts +44 -0
- package/dist/castleJson.js +131 -0
- package/dist/check.js +27 -1
- package/dist/contentPack.d.ts +49 -0
- package/dist/contentPack.js +273 -0
- package/dist/devExperiments.d.ts +21 -0
- package/dist/devExperiments.js +139 -0
- package/dist/devHub.d.ts +55 -0
- package/dist/devHub.js +187 -0
- package/dist/devSessionChild.js +3 -1
- package/dist/devSessionServer.d.ts +14 -1
- package/dist/devSessionServer.js +229 -44
- package/dist/experimentAssignment.d.ts +15 -0
- package/dist/experimentAssignment.js +41 -0
- package/dist/importCheckHook.d.ts +40 -0
- package/dist/importCheckHook.js +171 -0
- package/dist/importRegression.d.ts +15 -0
- package/dist/importRegression.js +100 -0
- package/dist/importTrust.d.ts +2 -0
- package/dist/importTrust.js +27 -0
- package/dist/importUpdateHook.d.ts +18 -0
- package/dist/importUpdateHook.js +31 -8
- package/dist/importUpdateHookRunner.js +19 -7
- package/dist/imports.d.ts +16 -0
- package/dist/imports.js +141 -31
- package/dist/index.js +3 -1
- package/dist/init.d.ts +3 -0
- package/dist/init.js +125 -8
- package/dist/install.js +4 -1
- package/dist/localPaths.js +4 -0
- package/dist/login.js +2 -2
- package/dist/platformDoc.js +3 -8
- package/dist/playPagePolicy.js +3 -1
- package/dist/remix.js +5 -0
- package/dist/routerTaskReport.d.ts +28 -0
- package/dist/routerTaskReport.js +56 -0
- package/dist/save-deck.d.ts +18 -0
- package/dist/save-deck.js +142 -6
- package/dist/serve.d.ts +8 -0
- package/dist/serve.js +94 -13
- package/dist/serverBundle.d.ts +1 -1
- package/dist/serverBundle.js +5 -1
- package/dist/webSourceSync.d.ts +2 -0
- package/dist/webSourceSync.js +2 -0
- package/kits/base/CLAUDE.md +2 -3
- package/kits/base/castle.json +1 -1
- package/kits/base/sdk/README.md +258 -52
- package/kits/base/sdk/agent.js +4 -4
- package/kits/base/sdk/avatar.d.ts +12 -0
- package/kits/base/sdk/avatar.js +23 -0
- package/kits/base/sdk/castle.d.ts +5 -0
- package/kits/base/sdk/castle.js +3 -0
- package/kits/base/sdk/commands.d.ts +208 -0
- package/kits/base/sdk/commands.js +16 -0
- package/kits/base/sdk/context.d.ts +6 -0
- package/kits/base/sdk/experiments.d.ts +15 -0
- package/kits/base/sdk/experiments.js +83 -0
- package/kits/base/sdk/hub.d.ts +85 -0
- package/kits/base/sdk/hub.js +107 -0
- package/kits/base/sdk/multiplayer.d.ts +45 -1
- package/kits/base/sdk/multiplayer.js +106 -4
- package/kits/base/sdk/server/hub.d.ts +169 -0
- package/kits/base/sdk/server/hub.js +125 -0
- package/kits/base/sdk/server/platformHandle.d.ts +42 -1
- package/kits/base/sdk/server/storage.d.ts +55 -2
- package/kits/base/sdk/server/wrapper.d.ts +32 -2
- package/kits/base/sdk/server/wrapper.js +90 -11
- package/kits/base/sdk/transport.d.ts +2 -1
- package/kits/base/sdk/transport.js +13 -1
- package/kits/hub-game/.prettierrc +5 -0
- package/kits/hub-game/CLAUDE.md +146 -0
- package/kits/hub-game/blueprints/avatar-0.scene +28 -0
- package/kits/hub-game/blueprints/avatar-1.scene +28 -0
- package/kits/hub-game/blueprints/avatar-2.scene +28 -0
- package/kits/hub-game/blueprints/avatar-3.scene +28 -0
- package/kits/hub-game/blueprints/bean/avatar-0.scene +28 -0
- package/kits/hub-game/blueprints/bean/avatar-1.scene +28 -0
- package/kits/hub-game/blueprints/bean/avatar-2.scene +28 -0
- package/kits/hub-game/blueprints/bean/avatar-3.scene +28 -0
- package/kits/hub-game/blueprints/blocky/avatar-0.scene +28 -0
- package/kits/hub-game/blueprints/blocky/avatar-1.scene +28 -0
- package/kits/hub-game/blueprints/blocky/avatar-2.scene +28 -0
- package/kits/hub-game/blueprints/blocky/avatar-3.scene +28 -0
- package/kits/hub-game/blueprints/pixel/avatar-0.scene +28 -0
- package/kits/hub-game/blueprints/pixel/avatar-1.scene +28 -0
- package/kits/hub-game/blueprints/pixel/avatar-2.scene +28 -0
- package/kits/hub-game/blueprints/pixel/avatar-3.scene +28 -0
- package/kits/hub-game/castle.json +96 -0
- package/kits/hub-game/code/client/attention.js +133 -0
- package/kits/hub-game/code/client/avatar.js +288 -0
- package/kits/hub-game/code/client/cabinets.js +90 -0
- package/kits/hub-game/code/client/chat.js +135 -0
- package/kits/hub-game/code/client/chrome.js +1001 -0
- package/kits/hub-game/code/client/doorFrame.js +15 -0
- package/kits/hub-game/code/client/firstJoin.js +14 -0
- package/kits/hub-game/code/client/grab.js +241 -0
- package/kits/hub-game/code/client/hookLayer.js +230 -0
- package/kits/hub-game/code/client/idle.js +326 -0
- package/kits/hub-game/code/client/keys.js +48 -0
- package/kits/hub-game/code/client/pack.js +232 -0
- package/kits/hub-game/code/client/packFormat.js +397 -0
- package/kits/hub-game/code/client/say.js +127 -0
- package/kits/hub-game/code/client/sha256.js +80 -0
- package/kits/hub-game/code/client/sound.js +147 -0
- package/kits/hub-game/code/client/state.js +131 -0
- package/kits/hub-game/code/client/talk.js +259 -0
- package/kits/hub-game/code/client/together.js +365 -0
- package/kits/hub-game/code/client/wear.js +149 -0
- package/kits/hub-game/code/server/actors.js +627 -0
- package/kits/hub-game/code/server/blocks.js +103 -0
- package/kits/hub-game/code/server/cabinets.js +309 -0
- package/kits/hub-game/code/server/game.js +137 -0
- package/kits/hub-game/code/server/grab.js +247 -0
- package/kits/hub-game/code/server/history.js +96 -0
- package/kits/hub-game/code/server/hub.js +1904 -0
- package/kits/hub-game/code/server/idle.js +412 -0
- package/kits/hub-game/code/server/index.js +64 -0
- package/kits/hub-game/code/server/labels.js +59 -0
- package/kits/hub-game/code/server/manifest.js +527 -0
- package/kits/hub-game/code/server/npcs.js +745 -0
- package/kits/hub-game/code/server/party.js +381 -0
- package/kits/hub-game/code/server/place.js +43 -0
- package/kits/hub-game/code/server/say.js +83 -0
- package/kits/hub-game/code/server/wear.js +142 -0
- package/kits/hub-game/code/systems/hub.js +2230 -0
- package/kits/hub-game/docs/content-pack.md +151 -0
- package/kits/hub-game/docs/contract.md +1139 -0
- package/kits/hub-game/docs/style.md +137 -0
- package/kits/hub-game/drawings/blocky/castle-eye.sprite +58 -0
- package/kits/hub-game/drawings/blocky/dash.sprite +59 -0
- package/kits/hub-game/drawings/blocky/pom.sprite +59 -0
- package/kits/hub-game/drawings/blocky/tabby.sprite +59 -0
- package/kits/hub-game/drawings/pixel/castle-arm.sprite +13 -0
- package/kits/hub-game/drawings/pixel/castle-body.sprite +23 -0
- package/kits/hub-game/drawings/pixel/castle-leg.sprite +12 -0
- package/kits/hub-game/drawings/pixel/kai-arm.sprite +14 -0
- package/kits/hub-game/drawings/pixel/kai-head.sprite +24 -0
- package/kits/hub-game/drawings/pixel/kai-leg.sprite +15 -0
- package/kits/hub-game/drawings/pixel/kai-torso.sprite +18 -0
- package/kits/hub-game/drawings/pixel/mimi-arm.sprite +13 -0
- package/kits/hub-game/drawings/pixel/mimi-head.sprite +23 -0
- package/kits/hub-game/drawings/pixel/mimi-leg.sprite +15 -0
- package/kits/hub-game/drawings/pixel/mimi-torso.sprite +18 -0
- package/kits/hub-game/drawings/pixel/nox-arm.sprite +13 -0
- package/kits/hub-game/drawings/pixel/nox-head.sprite +21 -0
- package/kits/hub-game/drawings/pixel/nox-leg.sprite +14 -0
- package/kits/hub-game/drawings/pixel/nox-torso.sprite +18 -0
- package/kits/hub-game/eslint.config.js +20 -0
- package/kits/hub-game/fonts.generated.js +9 -0
- package/kits/hub-game/index.html +22 -0
- package/kits/hub-game/main.jsx +6 -0
- package/kits/hub-game/models/avatar-0.pxmodel +21 -0
- package/kits/hub-game/models/avatar-1.pxmodel +24 -0
- package/kits/hub-game/models/avatar-2.pxmodel +27 -0
- package/kits/hub-game/models/avatar-3.pxmodel +22 -0
- package/kits/hub-game/models/bean/avatar-0.pxmodel +19 -0
- package/kits/hub-game/models/bean/avatar-1.pxmodel +24 -0
- package/kits/hub-game/models/bean/avatar-2.pxmodel +22 -0
- package/kits/hub-game/models/bean/avatar-3.pxmodel +24 -0
- package/kits/hub-game/models/blocky/avatar-0.pxmodel +21 -0
- package/kits/hub-game/models/blocky/avatar-1.pxmodel +30 -0
- package/kits/hub-game/models/blocky/avatar-2.pxmodel +28 -0
- package/kits/hub-game/models/blocky/avatar-3.pxmodel +27 -0
- package/kits/hub-game/models/pixel/avatar-0.pxmodel +24 -0
- package/kits/hub-game/models/pixel/avatar-1.pxmodel +16 -0
- package/kits/hub-game/models/pixel/avatar-2.pxmodel +19 -0
- package/kits/hub-game/models/pixel/avatar-3.pxmodel +23 -0
- package/kits/hub-game/package-lock.json +365 -0
- package/kits/hub-game/package.json +32 -0
- package/kits/hub-game/scenes/main.scene +318 -0
- package/kits/hub-game/scripts/check.mjs +339 -0
- package/kits/hub-game/scripts/fixtures/sdk-stub.mjs +3 -0
- package/kits/hub-game/scripts/gen-avatars-bean.mjs +748 -0
- package/kits/hub-game/scripts/gen-avatars-blocky.mjs +607 -0
- package/kits/hub-game/scripts/gen-avatars-pixel.mjs +771 -0
- package/kits/hub-game/scripts/gen-avatars.mjs +621 -0
- package/kits/hub-game/scripts/pack.mjs +192 -0
- package/kits/hub-game/scripts/test-actors.mjs +666 -0
- package/kits/hub-game/scripts/test-attention.mjs +103 -0
- package/kits/hub-game/scripts/test-avatar.mjs +472 -0
- package/kits/hub-game/scripts/test-ban-join.mjs +194 -0
- package/kits/hub-game/scripts/test-blocks.mjs +351 -0
- package/kits/hub-game/scripts/test-chat.mjs +98 -0
- package/kits/hub-game/scripts/test-classic.mjs +590 -0
- package/kits/hub-game/scripts/test-door-jump.mjs +131 -0
- package/kits/hub-game/scripts/test-door.mjs +56 -0
- package/kits/hub-game/scripts/test-grab.mjs +331 -0
- package/kits/hub-game/scripts/test-hub-ops.mjs +835 -0
- package/kits/hub-game/scripts/test-hub-trip.mjs +1310 -0
- package/kits/hub-game/scripts/test-idle.mjs +518 -0
- package/kits/hub-game/scripts/test-interest.mjs +413 -0
- package/kits/hub-game/scripts/test-keys.mjs +50 -0
- package/kits/hub-game/scripts/test-manifest.mjs +224 -0
- package/kits/hub-game/scripts/test-no-forms.mjs +16 -0
- package/kits/hub-game/scripts/test-npcs.mjs +714 -0
- package/kits/hub-game/scripts/test-pack.mjs +424 -0
- package/kits/hub-game/scripts/test-party.mjs +286 -0
- package/kits/hub-game/scripts/test-say.mjs +149 -0
- package/kits/hub-game/scripts/test-together.mjs +183 -0
- package/kits/hub-game/theme.style +3 -0
- package/kits/multiplayer-3d/castle.json +5 -5
- package/kits/multiplayer-3d/code/client/avatars.js +101 -1
- package/kits/multiplayer-3d/code/server/players.js +4 -1
- package/kits/multiplayer-3d/code/server/sceneBodies.js +27 -6
- package/kits/multiplayer-3d/code/server/world.js +20 -7
- package/kits/multiplayer-3d/code/systems/multiplayer.js +222 -11
- package/kits/physics-2d/castle.json +2 -2
- package/kits/physics-2d/engine/art.js +13 -0
- package/kits/physics-2d/engine/assets.js +4 -2
- package/kits/physics-2d/engine/scene.js +25 -5
- package/kits/physics-3d/CLAUDE.md +6 -1
- package/kits/physics-3d/castle.json +3 -3
- package/kits/physics-3d/engine3d/Scene3DPlayer.jsx +32 -4
- package/kits/physics-3d/engine3d/artobjects.js +2 -2
- package/kits/physics-3d/engine3d/materials.js +29 -1
- package/kits/physics-3d/engine3d/world3d.js +65 -1
- package/kits/physics-3d/systems/physics3d.js +5 -2
- package/kits/real-time/castle.json +2 -2
- package/kits/real-time/code/client/connection.js +77 -7
- package/kits/real-time/code/client/gameHooks.js +63 -3
- package/kits/real-time/code/client/messages.js +7 -0
- package/kits/real-time/code/server/gameHooks.js +24 -0
- package/kits/real-time/code/server/session.js +390 -22
- package/package.json +2 -2
|
@@ -0,0 +1,318 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "Flag Dash",
|
|
3
|
+
"ground": {
|
|
4
|
+
"color": "#3f6b3a"
|
|
5
|
+
},
|
|
6
|
+
"actors": [
|
|
7
|
+
{
|
|
8
|
+
"id": "rail-w",
|
|
9
|
+
"components": {
|
|
10
|
+
"Transform": {
|
|
11
|
+
"x": -5,
|
|
12
|
+
"y": 0.6,
|
|
13
|
+
"z": -12,
|
|
14
|
+
"rotationY": 0
|
|
15
|
+
},
|
|
16
|
+
"Shape": {
|
|
17
|
+
"kind": "box",
|
|
18
|
+
"width": 0.4,
|
|
19
|
+
"height": 1.2,
|
|
20
|
+
"depth": 44,
|
|
21
|
+
"color": "#4b4f58",
|
|
22
|
+
"roughness": 0.85
|
|
23
|
+
},
|
|
24
|
+
"Solid": {}
|
|
25
|
+
}
|
|
26
|
+
},
|
|
27
|
+
{
|
|
28
|
+
"id": "rail-e",
|
|
29
|
+
"components": {
|
|
30
|
+
"Transform": {
|
|
31
|
+
"x": 5,
|
|
32
|
+
"y": 0.6,
|
|
33
|
+
"z": -12,
|
|
34
|
+
"rotationY": 0
|
|
35
|
+
},
|
|
36
|
+
"Shape": {
|
|
37
|
+
"kind": "box",
|
|
38
|
+
"width": 0.4,
|
|
39
|
+
"height": 1.2,
|
|
40
|
+
"depth": 44,
|
|
41
|
+
"color": "#4b4f58",
|
|
42
|
+
"roughness": 0.85
|
|
43
|
+
},
|
|
44
|
+
"Solid": {}
|
|
45
|
+
}
|
|
46
|
+
},
|
|
47
|
+
{
|
|
48
|
+
"id": "rail-s",
|
|
49
|
+
"components": {
|
|
50
|
+
"Transform": {
|
|
51
|
+
"x": 0,
|
|
52
|
+
"y": 0.6,
|
|
53
|
+
"z": 10,
|
|
54
|
+
"rotationY": 0
|
|
55
|
+
},
|
|
56
|
+
"Shape": {
|
|
57
|
+
"kind": "box",
|
|
58
|
+
"width": 10.4,
|
|
59
|
+
"height": 1.2,
|
|
60
|
+
"depth": 0.4,
|
|
61
|
+
"color": "#4b4f58",
|
|
62
|
+
"roughness": 0.85
|
|
63
|
+
},
|
|
64
|
+
"Solid": {}
|
|
65
|
+
}
|
|
66
|
+
},
|
|
67
|
+
{
|
|
68
|
+
"id": "track",
|
|
69
|
+
"components": {
|
|
70
|
+
"Transform": {
|
|
71
|
+
"x": 0,
|
|
72
|
+
"y": 0.01,
|
|
73
|
+
"z": -12,
|
|
74
|
+
"rotationY": 0
|
|
75
|
+
},
|
|
76
|
+
"Shape": {
|
|
77
|
+
"kind": "box",
|
|
78
|
+
"width": 9.6,
|
|
79
|
+
"height": 0.02,
|
|
80
|
+
"depth": 44,
|
|
81
|
+
"color": "#a5683f",
|
|
82
|
+
"roughness": 0.85
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
},
|
|
86
|
+
{
|
|
87
|
+
"id": "start-line",
|
|
88
|
+
"components": {
|
|
89
|
+
"Transform": {
|
|
90
|
+
"x": 0,
|
|
91
|
+
"y": 0.03,
|
|
92
|
+
"z": 4,
|
|
93
|
+
"rotationY": 0
|
|
94
|
+
},
|
|
95
|
+
"Shape": {
|
|
96
|
+
"kind": "box",
|
|
97
|
+
"width": 9.6,
|
|
98
|
+
"height": 0.02,
|
|
99
|
+
"depth": 0.3,
|
|
100
|
+
"color": "#f4f1e8",
|
|
101
|
+
"roughness": 0.85
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
},
|
|
105
|
+
{
|
|
106
|
+
"id": "start-gate",
|
|
107
|
+
"components": {
|
|
108
|
+
"Transform": {
|
|
109
|
+
"x": 0,
|
|
110
|
+
"y": 0.7,
|
|
111
|
+
"z": 3.6,
|
|
112
|
+
"rotationY": 0
|
|
113
|
+
},
|
|
114
|
+
"Shape": {
|
|
115
|
+
"kind": "box",
|
|
116
|
+
"width": 9.6,
|
|
117
|
+
"height": 1.4,
|
|
118
|
+
"depth": 0.3,
|
|
119
|
+
"color": "#d9534f",
|
|
120
|
+
"roughness": 0.85
|
|
121
|
+
},
|
|
122
|
+
"Solid": {}
|
|
123
|
+
}
|
|
124
|
+
},
|
|
125
|
+
{
|
|
126
|
+
"id": "goal",
|
|
127
|
+
"components": {
|
|
128
|
+
"Transform": {
|
|
129
|
+
"x": 0,
|
|
130
|
+
"y": 0.05,
|
|
131
|
+
"z": -30,
|
|
132
|
+
"rotationY": 0
|
|
133
|
+
},
|
|
134
|
+
"Shape": {
|
|
135
|
+
"kind": "box",
|
|
136
|
+
"width": 9.6,
|
|
137
|
+
"height": 0.06,
|
|
138
|
+
"depth": 4,
|
|
139
|
+
"color": "#f2c94c",
|
|
140
|
+
"roughness": 0.85
|
|
141
|
+
},
|
|
142
|
+
"HubGoal": {
|
|
143
|
+
"depth": 4
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
},
|
|
147
|
+
{
|
|
148
|
+
"id": "goal-post-l",
|
|
149
|
+
"components": {
|
|
150
|
+
"Transform": {
|
|
151
|
+
"x": -4.5,
|
|
152
|
+
"y": 1.5,
|
|
153
|
+
"z": -30,
|
|
154
|
+
"rotationY": 0
|
|
155
|
+
},
|
|
156
|
+
"Shape": {
|
|
157
|
+
"kind": "box",
|
|
158
|
+
"width": 0.3,
|
|
159
|
+
"height": 3,
|
|
160
|
+
"depth": 0.3,
|
|
161
|
+
"color": "#e8e2d0",
|
|
162
|
+
"roughness": 0.85
|
|
163
|
+
},
|
|
164
|
+
"Solid": {}
|
|
165
|
+
}
|
|
166
|
+
},
|
|
167
|
+
{
|
|
168
|
+
"id": "goal-post-r",
|
|
169
|
+
"components": {
|
|
170
|
+
"Transform": {
|
|
171
|
+
"x": 4.5,
|
|
172
|
+
"y": 1.5,
|
|
173
|
+
"z": -30,
|
|
174
|
+
"rotationY": 0
|
|
175
|
+
},
|
|
176
|
+
"Shape": {
|
|
177
|
+
"kind": "box",
|
|
178
|
+
"width": 0.3,
|
|
179
|
+
"height": 3,
|
|
180
|
+
"depth": 0.3,
|
|
181
|
+
"color": "#e8e2d0",
|
|
182
|
+
"roughness": 0.85
|
|
183
|
+
},
|
|
184
|
+
"Solid": {}
|
|
185
|
+
}
|
|
186
|
+
},
|
|
187
|
+
{
|
|
188
|
+
"id": "goal-banner",
|
|
189
|
+
"components": {
|
|
190
|
+
"Transform": {
|
|
191
|
+
"x": 0,
|
|
192
|
+
"y": 3.1,
|
|
193
|
+
"z": -30,
|
|
194
|
+
"rotationY": 0
|
|
195
|
+
},
|
|
196
|
+
"Shape": {
|
|
197
|
+
"kind": "box",
|
|
198
|
+
"width": 9.3,
|
|
199
|
+
"height": 0.5,
|
|
200
|
+
"depth": 0.2,
|
|
201
|
+
"color": "#f2c94c",
|
|
202
|
+
"roughness": 0.85
|
|
203
|
+
},
|
|
204
|
+
"Lookable": {
|
|
205
|
+
"text": "Goal!"
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
},
|
|
209
|
+
{
|
|
210
|
+
"id": "block-0",
|
|
211
|
+
"components": {
|
|
212
|
+
"Transform": {
|
|
213
|
+
"x": -2,
|
|
214
|
+
"y": 0.5,
|
|
215
|
+
"z": -10,
|
|
216
|
+
"rotationY": 0
|
|
217
|
+
},
|
|
218
|
+
"Shape": {
|
|
219
|
+
"kind": "box",
|
|
220
|
+
"width": 2,
|
|
221
|
+
"height": 1,
|
|
222
|
+
"depth": 1,
|
|
223
|
+
"color": "#6f8fb3",
|
|
224
|
+
"roughness": 0.85
|
|
225
|
+
},
|
|
226
|
+
"Solid": {}
|
|
227
|
+
}
|
|
228
|
+
},
|
|
229
|
+
{
|
|
230
|
+
"id": "block-1",
|
|
231
|
+
"components": {
|
|
232
|
+
"Transform": {
|
|
233
|
+
"x": 2.5,
|
|
234
|
+
"y": 0.5,
|
|
235
|
+
"z": -16,
|
|
236
|
+
"rotationY": 0
|
|
237
|
+
},
|
|
238
|
+
"Shape": {
|
|
239
|
+
"kind": "box",
|
|
240
|
+
"width": 2,
|
|
241
|
+
"height": 1,
|
|
242
|
+
"depth": 1,
|
|
243
|
+
"color": "#6f8fb3",
|
|
244
|
+
"roughness": 0.85
|
|
245
|
+
},
|
|
246
|
+
"Solid": {}
|
|
247
|
+
}
|
|
248
|
+
},
|
|
249
|
+
{
|
|
250
|
+
"id": "block-2",
|
|
251
|
+
"components": {
|
|
252
|
+
"Transform": {
|
|
253
|
+
"x": -1,
|
|
254
|
+
"y": 0.5,
|
|
255
|
+
"z": -22,
|
|
256
|
+
"rotationY": 0
|
|
257
|
+
},
|
|
258
|
+
"Shape": {
|
|
259
|
+
"kind": "box",
|
|
260
|
+
"width": 3,
|
|
261
|
+
"height": 1,
|
|
262
|
+
"depth": 1,
|
|
263
|
+
"color": "#6f8fb3",
|
|
264
|
+
"roughness": 0.85
|
|
265
|
+
},
|
|
266
|
+
"Solid": {}
|
|
267
|
+
}
|
|
268
|
+
},
|
|
269
|
+
{
|
|
270
|
+
"id": "arrival",
|
|
271
|
+
"components": {
|
|
272
|
+
"Transform": {
|
|
273
|
+
"x": 0,
|
|
274
|
+
"y": 0.02,
|
|
275
|
+
"z": 7,
|
|
276
|
+
"rotationY": 180
|
|
277
|
+
},
|
|
278
|
+
"Shape": {
|
|
279
|
+
"kind": "cylinder",
|
|
280
|
+
"radius": 1.2,
|
|
281
|
+
"height": 0.02,
|
|
282
|
+
"color": "#7fc9b8",
|
|
283
|
+
"roughness": 0.6
|
|
284
|
+
}
|
|
285
|
+
}
|
|
286
|
+
},
|
|
287
|
+
{
|
|
288
|
+
"id": "player",
|
|
289
|
+
"components": {
|
|
290
|
+
"Transform": {
|
|
291
|
+
"x": 0,
|
|
292
|
+
"y": 1,
|
|
293
|
+
"z": 7,
|
|
294
|
+
"rotationY": 180
|
|
295
|
+
},
|
|
296
|
+
"Shape": {
|
|
297
|
+
"kind": "capsule",
|
|
298
|
+
"radius": 0.35,
|
|
299
|
+
"height": 1.4,
|
|
300
|
+
"color": "#cf8acb",
|
|
301
|
+
"roughness": 0.4
|
|
302
|
+
},
|
|
303
|
+
"Body": {
|
|
304
|
+
"type": "dynamic",
|
|
305
|
+
"lockRotations": true,
|
|
306
|
+
"friction": 0,
|
|
307
|
+
"gravityScale": 2
|
|
308
|
+
},
|
|
309
|
+
"Solid": {},
|
|
310
|
+
"Model": {
|
|
311
|
+
"file": "imports/castle.physics-3d/models/player.pxmodel",
|
|
312
|
+
"yOffset": -0.7
|
|
313
|
+
},
|
|
314
|
+
"Player": {}
|
|
315
|
+
}
|
|
316
|
+
}
|
|
317
|
+
]
|
|
318
|
+
}
|
|
@@ -0,0 +1,339 @@
|
|
|
1
|
+
// The hub-game publish check (castle.json `onCheck`): run by `castle-web check`
|
|
2
|
+
// and before `save-deck` publishes, against the deck that imports this kit (or
|
|
3
|
+
// against the kit itself, as `self`). It holds what HUB.md's "Publish-time
|
|
4
|
+
// checks" can hold without a person: the manifest against the contract, the
|
|
5
|
+
// Tier 0 rule that a hub game ships no client code, no player character of its
|
|
6
|
+
// own, no `Portal.open`, and the scene budgets. Curation is the rest.
|
|
7
|
+
|
|
8
|
+
import fs from 'node:fs';
|
|
9
|
+
import path from 'node:path';
|
|
10
|
+
import { MAIN_PLACE, readManifest } from '../code/server/manifest.js';
|
|
11
|
+
|
|
12
|
+
const KIT_ALIAS = 'castle.hub-game';
|
|
13
|
+
const SERVER_MAIN = `imports/${KIT_ALIAS}/code/server/index.js`;
|
|
14
|
+
|
|
15
|
+
// What a deck may hold outside `code/server/` that is code: tooling that never
|
|
16
|
+
// reaches the client bundle. `fonts.generated.js` is the Theme editor's and is
|
|
17
|
+
// allowed only byte for byte as that editor writes it (`isGeneratedFonts`),
|
|
18
|
+
// since the engine imports it into the client.
|
|
19
|
+
const ALLOWED_CODE = [/^scripts\//, /^[^/]+\.config\.(js|mjs|cjs)$/];
|
|
20
|
+
// `forks/` is NOT skipped: a fork replaces kit code in the client bundle.
|
|
21
|
+
const SKIP_DIRS = new Set(['imports', 'node_modules', '.castle', 'dist', '.git']);
|
|
22
|
+
// The one script a hub game's page may load.
|
|
23
|
+
const KIT_ENTRY = new Set([`/imports/${KIT_ALIAS}/main.jsx`, `./imports/${KIT_ALIAS}/main.jsx`, `imports/${KIT_ALIAS}/main.jsx`]);
|
|
24
|
+
const CODE_FILE = /\.(js|jsx|mjs|cjs|ts|tsx)$/;
|
|
25
|
+
|
|
26
|
+
// Scene budgets: the most a place's scene may hold, so a door never mounts
|
|
27
|
+
// content the phone in the M0 test could not draw.
|
|
28
|
+
const SCENE_BYTES_MAX = 1024 * 1024;
|
|
29
|
+
const SCENE_ACTORS_MAX = 1500;
|
|
30
|
+
// A place's sounds (v1.6, `idle.sounds`) are bundled into the deck's page,
|
|
31
|
+
// inline once it is published, and into its content pack (`audio`, whose
|
|
32
|
+
// validator holds the same caps, packFormat.js): each file and all of them
|
|
33
|
+
// together are kept small.
|
|
34
|
+
const SOUND_BYTES_MAX = 256 * 1024;
|
|
35
|
+
const SOUNDS_BYTES_MAX = 1024 * 1024;
|
|
36
|
+
|
|
37
|
+
// `self` is the CLI's word that this is the kit checked as itself, never an
|
|
38
|
+
// import's alias (an import can be added under any name).
|
|
39
|
+
export default async function check({ deckDir, self = false }) {
|
|
40
|
+
const errors = [];
|
|
41
|
+
const warnings = [];
|
|
42
|
+
const castleJson = readJson(path.join(deckDir, 'castle.json'));
|
|
43
|
+
if (!castleJson) {
|
|
44
|
+
return { errors: ['castle.json is missing or not JSON.'], warnings };
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
const { errors: manifestErrors, manifest } = readManifest(castleJson, (scene) =>
|
|
48
|
+
fs.existsSync(path.join(deckDir, scene)),
|
|
49
|
+
);
|
|
50
|
+
errors.push(...manifestErrors);
|
|
51
|
+
|
|
52
|
+
const main = castleJson.server?.main;
|
|
53
|
+
const wantMain = self ? 'code/server/index.js' : SERVER_MAIN;
|
|
54
|
+
if (main !== wantMain) {
|
|
55
|
+
errors.push(`server.main must be ${wantMain}: a hub game runs the kit's server, with its own hooks in code/server/game.js.`);
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
if (!self) {
|
|
59
|
+
const html = readText(path.join(deckDir, 'index.html')) ?? '';
|
|
60
|
+
const scripts = [...html.matchAll(/<script\b([^>]*)>([\s\S]*?)<\/script>/gi)];
|
|
61
|
+
const ok =
|
|
62
|
+
scripts.length === 1 &&
|
|
63
|
+
KIT_ENTRY.has(scriptSrc(scripts[0][1])) &&
|
|
64
|
+
!scripts[0][2].trim() &&
|
|
65
|
+
!/<script\b/i.test(html.replace(scripts[0][0], '')) &&
|
|
66
|
+
!/\son[a-z]+\s*=/i.test(html) &&
|
|
67
|
+
!/<(iframe|object|embed|link\b[^>]*rel=["']?(modulepreload|import))/i.test(html);
|
|
68
|
+
if (!ok) {
|
|
69
|
+
errors.push(`index.html must load the kit's entry (/imports/${KIT_ALIAS}/main.jsx) and nothing else that runs.`);
|
|
70
|
+
}
|
|
71
|
+
for (const file of walk(deckDir)) {
|
|
72
|
+
const rel = file.split(path.sep).join('/');
|
|
73
|
+
if (rel === 'fonts.generated.js') {
|
|
74
|
+
if (!isGeneratedFonts(readText(path.join(deckDir, file)) ?? '')) {
|
|
75
|
+
errors.push('fonts.generated.js is not what the Theme editor writes; a hub game may not change it by hand.');
|
|
76
|
+
}
|
|
77
|
+
continue;
|
|
78
|
+
}
|
|
79
|
+
if (/^(code\/(client|systems)|client|systems|behaviors|forks)\//.test(rel)) {
|
|
80
|
+
errors.push(`${rel}: a hub game ships no client code (Tier 0); its rules are server hooks in code/server/.`);
|
|
81
|
+
} else if (CODE_FILE.test(rel) && !rel.startsWith('code/server/') && !ALLOWED_CODE.some((re) => re.test(rel))) {
|
|
82
|
+
errors.push(`${rel}: code outside code/server/ would run in the town's iframe, which Tier 0 forbids.`);
|
|
83
|
+
}
|
|
84
|
+
if (rel === 'blueprints/other-player.scene') {
|
|
85
|
+
errors.push('blueprints/other-player.scene: a hub game never draws a player; the kit draws every player as their avatar.');
|
|
86
|
+
}
|
|
87
|
+
if (CODE_FILE.test(rel) && /\bPortal\s*\.\s*open\b/.test(readText(path.join(deckDir, file)) ?? '')) {
|
|
88
|
+
errors.push(`${rel}: a hub game may not call Portal.open; players leave through the hub's door.`);
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
if (manifest) {
|
|
94
|
+
for (const [id, place] of Object.entries(manifest.places)) {
|
|
95
|
+
checkScene(deckDir, id, place, errors, warnings);
|
|
96
|
+
checkDeckDoors(deckDir, castleJson, place, errors);
|
|
97
|
+
if (place.sign?.model && !fs.existsSync(path.join(deckDir, place.sign.model))) {
|
|
98
|
+
errors.push(`${where(id)}.sign.model names ${place.sign.model}, which this deck does not have.`);
|
|
99
|
+
}
|
|
100
|
+
if (!place.result && id !== MAIN_PLACE) {
|
|
101
|
+
warnings.push(`${where(id)} declares no result: players leaving it bring nothing back to the town.`);
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
checkSounds(deckDir, manifest, errors, warnings);
|
|
105
|
+
const placeFiles = listDir(path.join(deckDir, 'code', 'server', 'places'));
|
|
106
|
+
for (const file of placeFiles) {
|
|
107
|
+
const id = file.replace(/\.js$/, '');
|
|
108
|
+
if (!manifest.places[id] || id === MAIN_PLACE) {
|
|
109
|
+
errors.push(`code/server/places/${file}: no place "${id}" in hub.places.`);
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
return { errors, warnings };
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
// Whether a fonts module is exactly what the Theme editor writes: the font
|
|
117
|
+
// names are read out of it and the editor's text (physics-2d's
|
|
118
|
+
// `fontsGeneratedSource`, and the single-font form it wrote before) is
|
|
119
|
+
// rebuilt around them, then compared whole. Nothing a hand edit adds -- code
|
|
120
|
+
// hidden in a comment by a line separator included -- survives the comparison.
|
|
121
|
+
function isGeneratedFonts(text) {
|
|
122
|
+
const name = /^[A-Za-z0-9]+$/;
|
|
123
|
+
const primary = /^export const deckFont = '([A-Za-z0-9]+)';$/m.exec(text)?.[1];
|
|
124
|
+
const listed = /^export const deckFonts = \[(.*)\];$/m.exec(text)?.[1];
|
|
125
|
+
const candidates = [
|
|
126
|
+
`// Generated by the Theme editor. Do not edit.
|
|
127
|
+
//
|
|
128
|
+
// This deck has no font of its own; text renders in the default sans stack.
|
|
129
|
+
export const deckFont = null;
|
|
130
|
+
export const deckFonts = [];
|
|
131
|
+
export const installDeckFonts = [];
|
|
132
|
+
`,
|
|
133
|
+
];
|
|
134
|
+
if (primary) {
|
|
135
|
+
candidates.push(`// Generated by the Theme editor. Do not edit -- picking a font rewrites it.
|
|
136
|
+
//
|
|
137
|
+
// \`theme.style\` records that this deck's font is ${primary}; this module is what
|
|
138
|
+
// puts ${primary}'s bytes in the published bundle. It has to name the face in a
|
|
139
|
+
// static import: reaching it through the name in \`theme.style\` instead would
|
|
140
|
+
// inline all nine Castle faces into the deck, since no bundler can tell which
|
|
141
|
+
// one a runtime lookup reads.
|
|
142
|
+
export { install${primary} as installDeckFont } from 'castle-web-fonts';
|
|
143
|
+
export const deckFont = '${primary}';
|
|
144
|
+
`);
|
|
145
|
+
}
|
|
146
|
+
if (primary && listed !== undefined) {
|
|
147
|
+
const list = listed.split(', ').map((item) => /^'([A-Za-z0-9]+)'$/.exec(item)?.[1] ?? null);
|
|
148
|
+
if (list.length && list.every((n) => n && name.test(n))) {
|
|
149
|
+
const installers = list.map((n) => `install${n}`).join(', ');
|
|
150
|
+
candidates.push(`// Generated by the Theme editor / Text font picker. Do not edit.
|
|
151
|
+
//
|
|
152
|
+
// \`theme.style\` records the deck's primary font as ${primary}; Text actors
|
|
153
|
+
// may use additional faces. This module is what puts their bytes in the
|
|
154
|
+
// published bundle — each face must be named in a static import so the bundler
|
|
155
|
+
// can tree-shake the rest.
|
|
156
|
+
import { ${installers} } from 'castle-web-fonts';
|
|
157
|
+
export { install${primary} as installDeckFont };
|
|
158
|
+
export const deckFont = '${primary}';
|
|
159
|
+
export const deckFonts = [${list.map((n) => `'${n}'`).join(', ')}];
|
|
160
|
+
export const installDeckFonts = [${installers}];
|
|
161
|
+
`);
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
return candidates.includes(text);
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
function checkScene(deckDir, id, place, errors, warnings) {
|
|
168
|
+
const file = path.join(deckDir, place.scene);
|
|
169
|
+
const text = readText(file);
|
|
170
|
+
if (text === null) {
|
|
171
|
+
return;
|
|
172
|
+
}
|
|
173
|
+
if (Buffer.byteLength(text) > SCENE_BYTES_MAX) {
|
|
174
|
+
errors.push(`${place.scene} is over ${SCENE_BYTES_MAX / 1024} KB.`);
|
|
175
|
+
}
|
|
176
|
+
let scene;
|
|
177
|
+
try {
|
|
178
|
+
scene = JSON.parse(text);
|
|
179
|
+
} catch {
|
|
180
|
+
errors.push(`${place.scene} is not JSON.`);
|
|
181
|
+
return;
|
|
182
|
+
}
|
|
183
|
+
const actors = Array.isArray(scene.actors) ? scene.actors : [];
|
|
184
|
+
if (actors.length > SCENE_ACTORS_MAX) {
|
|
185
|
+
errors.push(`${place.scene} has ${actors.length} actors; a place holds at most ${SCENE_ACTORS_MAX}.`);
|
|
186
|
+
}
|
|
187
|
+
if (place.arrival.actor && !actors.some((a) => a.id === place.arrival.actor)) {
|
|
188
|
+
errors.push(`${where(id)}.arrival.actor "${place.arrival.actor}" is not an actor of ${place.scene}.`);
|
|
189
|
+
}
|
|
190
|
+
// A seat stays where it was authored (v1.6): one that can move is refused.
|
|
191
|
+
for (const actor of actors) {
|
|
192
|
+
const type = actor?.components?.Body?.type;
|
|
193
|
+
if (actor?.components?.HubSeat && (type === 'dynamic' || type === 'kinematic')) {
|
|
194
|
+
errors.push(`${place.scene}: seat "${actor.id}" has a ${type} Body; a seat cannot move.`);
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
const players = actors.filter((a) => a.components?.Player || blueprintHasPlayer(deckDir, a.blueprint));
|
|
198
|
+
if (players.length !== 1) {
|
|
199
|
+
warnings.push(`${place.scene} has ${players.length} Player actors; a place has one, which every player is drawn from.`);
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
// Every place's declared sounds are files of this deck, each and all of them
|
|
204
|
+
// within budget. They ride in the content pack's `audio` too, so a game
|
|
205
|
+
// reached through a door sounds there (a town on an engine older than `audio`
|
|
206
|
+
// ignores it, and the game is silent there).
|
|
207
|
+
function checkSounds(deckDir, manifest, errors, warnings) {
|
|
208
|
+
const sizes = new Map();
|
|
209
|
+
for (const [id, place] of Object.entries(manifest.places)) {
|
|
210
|
+
const sounds = place.idle?.sounds ?? [];
|
|
211
|
+
for (const file of sounds) {
|
|
212
|
+
let size = null;
|
|
213
|
+
try {
|
|
214
|
+
size = fs.statSync(path.join(deckDir, file)).size;
|
|
215
|
+
} catch {
|
|
216
|
+
errors.push(`${where(id)}.idle.sounds names ${file}, which this deck does not have.`);
|
|
217
|
+
continue;
|
|
218
|
+
}
|
|
219
|
+
if (size > SOUND_BYTES_MAX) {
|
|
220
|
+
errors.push(`${file} is ${Math.round(size / 1024)} KB; a place's sound is at most ${SOUND_BYTES_MAX / 1024} KB.`);
|
|
221
|
+
}
|
|
222
|
+
sizes.set(file, size);
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
const total = [...sizes.values()].reduce((a, b) => a + b, 0);
|
|
226
|
+
if (total > SOUNDS_BYTES_MAX) {
|
|
227
|
+
errors.push(`the places' sounds come to ${Math.round(total / 1024)} KB; at most ${SOUNDS_BYTES_MAX / 1024} KB in all.`);
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
// A door to another local deck (`to: "deck:<name>"`, the deck castle.json's
|
|
232
|
+
// `devDecks` names) says the destination's title and player counts in its
|
|
233
|
+
// props, which is what a production town reads; on the dev serve the town reads
|
|
234
|
+
// the destination's own castle.json. A door whose props have drifted from that
|
|
235
|
+
// castle.json would behave one way in dev and another once published, so the
|
|
236
|
+
// check refuses it (v1.1).
|
|
237
|
+
const DOOR_FIELDS = ['title', 'minPlayers', 'maxPlayers', 'lateJoin'];
|
|
238
|
+
|
|
239
|
+
function checkDeckDoors(deckDir, castleJson, place, errors) {
|
|
240
|
+
const devDecks = castleJson.devDecks && typeof castleJson.devDecks === 'object' ? castleJson.devDecks : {};
|
|
241
|
+
const scene = readJson(path.join(deckDir, place.scene));
|
|
242
|
+
for (const actor of Array.isArray(scene?.actors) ? scene.actors : []) {
|
|
243
|
+
// A door may take its props from a blueprint, as the engine merges them.
|
|
244
|
+
const template = typeof actor?.blueprint === 'string' ? readJson(path.join(deckDir, actor.blueprint.replace(/^@/, '')))?.actors?.[0]?.components?.HubDoor : null;
|
|
245
|
+
const own = actor?.components?.HubDoor;
|
|
246
|
+
const props = template || own ? { ...(template ?? {}), ...(own ?? {}) } : null;
|
|
247
|
+
const name = typeof props?.to === 'string' ? /^deck:([A-Za-z0-9_-]{1,40})$/.exec(props.to)?.[1] : null;
|
|
248
|
+
const dir = name && typeof devDecks[name] === 'string' ? path.resolve(deckDir, devDecks[name]) : null;
|
|
249
|
+
const json = dir ? readJson(path.join(dir, 'castle.json')) : null;
|
|
250
|
+
const dest = json ? readManifest(json, () => true).manifest?.places[MAIN_PLACE] : null;
|
|
251
|
+
if (!dest) {
|
|
252
|
+
continue;
|
|
253
|
+
}
|
|
254
|
+
for (const field of DOOR_FIELDS) {
|
|
255
|
+
if (props[field] !== dest[field]) {
|
|
256
|
+
errors.push(
|
|
257
|
+
`${place.scene}: door "${props.id}" says ${field} ${JSON.stringify(props[field])}, but ${devDecks[name]}/castle.json says ${JSON.stringify(dest[field])}.`,
|
|
258
|
+
);
|
|
259
|
+
}
|
|
260
|
+
}
|
|
261
|
+
}
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
// The `src` a script tag loads, read from its attributes one by one the way a
|
|
265
|
+
// browser does (so `data-src` is not `src`); null when there is not exactly
|
|
266
|
+
// one, or when the tag carries anything but `type="module"` beside it.
|
|
267
|
+
function scriptSrc(attrs) {
|
|
268
|
+
const seen = new Map();
|
|
269
|
+
const re = /\s*([^\s"'>/=]+)(?:\s*=\s*(?:"([^"]*)"|'([^']*)'|([^\s"'=<>`]+)))?/gy;
|
|
270
|
+
let at = 0;
|
|
271
|
+
let m;
|
|
272
|
+
while ((m = re.exec(attrs))) {
|
|
273
|
+
at = re.lastIndex;
|
|
274
|
+
const nameLower = m[1].toLowerCase();
|
|
275
|
+
if (seen.has(nameLower)) {
|
|
276
|
+
return null;
|
|
277
|
+
}
|
|
278
|
+
seen.set(nameLower, m[2] ?? m[3] ?? m[4] ?? '');
|
|
279
|
+
}
|
|
280
|
+
if (attrs.slice(at).trim()) {
|
|
281
|
+
return null;
|
|
282
|
+
}
|
|
283
|
+
const names = [...seen.keys()];
|
|
284
|
+
if (!names.every((n) => n === 'src' || n === 'type') || seen.get('type') !== 'module') {
|
|
285
|
+
return null;
|
|
286
|
+
}
|
|
287
|
+
return seen.get('src') ?? null;
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
function blueprintHasPlayer(deckDir, ref) {
|
|
291
|
+
if (typeof ref !== 'string') {
|
|
292
|
+
return false;
|
|
293
|
+
}
|
|
294
|
+
const bp = readJson(path.join(deckDir, ref.replace(/^@/, '')));
|
|
295
|
+
return Boolean(bp?.actors?.[0]?.components?.Player);
|
|
296
|
+
}
|
|
297
|
+
|
|
298
|
+
function where(id) {
|
|
299
|
+
return id === MAIN_PLACE ? 'hub' : `hub.places.${id}`;
|
|
300
|
+
}
|
|
301
|
+
|
|
302
|
+
function* walk(root, rel = '') {
|
|
303
|
+
for (const entry of listDir(path.join(root, rel), true)) {
|
|
304
|
+
if (SKIP_DIRS.has(entry.name) && !rel) {
|
|
305
|
+
continue;
|
|
306
|
+
}
|
|
307
|
+
const child = rel ? path.join(rel, entry.name) : entry.name;
|
|
308
|
+
if (entry.isDirectory()) {
|
|
309
|
+
yield* walk(root, child);
|
|
310
|
+
} else if (entry.isFile()) {
|
|
311
|
+
yield child;
|
|
312
|
+
}
|
|
313
|
+
}
|
|
314
|
+
}
|
|
315
|
+
|
|
316
|
+
function listDir(dir, withTypes = false) {
|
|
317
|
+
try {
|
|
318
|
+
return fs.readdirSync(dir, { withFileTypes: withTypes });
|
|
319
|
+
} catch {
|
|
320
|
+
return [];
|
|
321
|
+
}
|
|
322
|
+
}
|
|
323
|
+
|
|
324
|
+
function readText(file) {
|
|
325
|
+
try {
|
|
326
|
+
return fs.readFileSync(file, 'utf8');
|
|
327
|
+
} catch {
|
|
328
|
+
return null;
|
|
329
|
+
}
|
|
330
|
+
}
|
|
331
|
+
|
|
332
|
+
function readJson(file) {
|
|
333
|
+
const text = readText(file);
|
|
334
|
+
try {
|
|
335
|
+
return text === null ? null : JSON.parse(text);
|
|
336
|
+
} catch {
|
|
337
|
+
return null;
|
|
338
|
+
}
|
|
339
|
+
}
|