vibedgames 0.8.1 → 0.10.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/README.md +17 -8
- package/assets/align-framing.py +242 -0
- package/assets/render-model.py +406 -0
- package/assets/tilemap-editor.html +630 -0
- package/dist/THIRD_PARTY_NOTICES.txt +59 -7
- package/dist/chunk-2KVQJKIZ.js +6495 -0
- package/dist/chunk-2SBBKY5C.js +16993 -0
- package/dist/chunk-2ZKS7V72.js +170 -0
- package/dist/{chunk-RAUJA3OY.js → chunk-3HGBIUM5.js} +21 -18
- package/dist/chunk-3UGGMFJJ.js +22 -0
- package/dist/{chunk-I6O4HIDY.js → chunk-42K3BJJH.js} +163 -131
- package/dist/chunk-43P4U7CB.js +104 -0
- package/dist/chunk-4FJXCS3K.js +741 -0
- package/dist/{chunk-NC5XCGYU.js → chunk-4UU622RK.js} +6 -5
- package/dist/{chunk-2QBYTIMH.js → chunk-5535KDYI.js} +1 -1
- package/dist/chunk-5YPLKGY3.js +87 -0
- package/dist/chunk-6KXXZXSO.js +475 -0
- package/dist/chunk-7RPLQWR2.js +91 -0
- package/dist/{chunk-C2IRIRAA.js → chunk-A556KALN.js} +15 -14
- package/dist/{chunk-N3XAUFKH.js → chunk-ABTUEIRC.js} +576 -301
- package/dist/{chunk-PEUP4MZR.js → chunk-AWJNAGPE.js} +6 -3
- package/dist/{chunk-QGEITHUP.js → chunk-BN3Q7UEC.js} +22 -19
- package/dist/chunk-BZOMEG3X.js +412 -0
- package/dist/{chunk-ZYCSYJWX.js → chunk-COSLGSVO.js} +14 -24
- package/dist/{chunk-PQDBCZRT.js → chunk-CTY2WZQK.js} +204 -158
- package/dist/{chunk-CU7UY5YJ.js → chunk-D2RF35HJ.js} +1 -1
- package/dist/chunk-DB7WVFS7.js +80 -0
- package/dist/chunk-DOOQUFPG.js +73 -0
- package/dist/chunk-E3FJUPLT.js +177 -0
- package/dist/chunk-E7NDOZ27.js +428 -0
- package/dist/chunk-F42QKWBB.js +39 -0
- package/dist/chunk-FXXVXDTW.js +168 -0
- package/dist/{chunk-VFFOT7KD.js → chunk-G66HRVDW.js} +1 -1
- package/dist/{chunk-CAKBGDCY.js → chunk-GKDUYJ7R.js} +5 -0
- package/dist/chunk-GLEW7VJQ.js +45 -0
- package/dist/{chunk-MGIASPED.js → chunk-H2C4QUTG.js} +9 -8
- package/dist/{chunk-HCMTSR7E.js → chunk-HRKVAXNN.js} +21 -17
- package/dist/{chunk-TLRL6FHW.js → chunk-HSMG6U7J.js} +10 -9
- package/dist/chunk-HX5Q63UA.js +48 -0
- package/dist/chunk-HYOXGNWS.js +53 -0
- package/dist/chunk-I5LELJSK.js +22 -0
- package/dist/{chunk-6FZPPUQH.js → chunk-JN4WZCR7.js} +5 -4
- package/dist/{chunk-QJZ72MSY.js → chunk-K36EOII3.js} +7 -6
- package/dist/chunk-KAGVI3CE.js +62 -0
- package/dist/chunk-KJK5CB6E.js +58 -0
- package/dist/chunk-KLFBAFXD.js +25 -0
- package/dist/{chunk-7MKUR7Y3.js → chunk-LONQWRTR.js} +112 -81
- package/dist/chunk-LORGE2NB.js +2484 -0
- package/dist/{chunk-HKA5LBYW.js → chunk-MEAO33XW.js} +22 -19
- package/dist/{chunk-PM5UOIKR.js → chunk-MR5KIFI7.js} +22 -21
- package/dist/{chunk-GCX5KQ6A.js → chunk-N2UHAQXC.js} +18 -11
- package/dist/chunk-NCX6LYNJ.js +117 -0
- package/dist/chunk-OGX4DKIS.js +215 -0
- package/dist/chunk-OPUCUUID.js +41 -0
- package/dist/chunk-Q2QC6KAZ.js +132 -0
- package/dist/{chunk-2GL2WJZX.js → chunk-Q3XQPNF6.js} +14 -14
- package/dist/{chunk-RYFO3ZPO.js → chunk-Q5NZNXJE.js} +15 -12
- package/dist/{chunk-JT2AU24K.js → chunk-QARXJGI5.js} +1 -1
- package/dist/chunk-QLCVLCPM.js +126 -0
- package/dist/chunk-R2WVORGD.js +91 -0
- package/dist/chunk-RKS7SI5L.js +64 -0
- package/dist/{chunk-4BGCA3W7.js → chunk-RPJR3S5S.js} +32 -18
- package/dist/chunk-RPSUFZAG.js +3307 -0
- package/dist/chunk-RRI23NK2.js +40 -0
- package/dist/chunk-S7HYWITX.js +57 -0
- package/dist/chunk-SBXCK2I2.js +48 -0
- package/dist/chunk-SUSX3QIA.js +62 -0
- package/dist/{chunk-PHEDW6C7.js → chunk-SXYQL4GK.js} +16 -7
- package/dist/{chunk-ZI6PKVXG.js → chunk-TMPBGXT4.js} +6 -5
- package/dist/chunk-TXOE5UY5.js +72 -0
- package/dist/chunk-U6DTE5IX.js +124 -0
- package/dist/chunk-UPHB5HWO.js +115 -0
- package/dist/chunk-UQ7VO6B3.js +91 -0
- package/dist/chunk-VB4WLJR2.js +47 -0
- package/dist/{chunk-FNYBZNW2.js → chunk-VIEKOGKG.js} +21 -3
- package/dist/{chunk-QIVCBUYD.js → chunk-VZEJ2ZHE.js} +18 -18
- package/dist/chunk-X75Y7LUW.js +126 -0
- package/dist/{chunk-Z4Z24FWO.js → chunk-YNCYMWER.js} +8 -5
- package/dist/chunk-ZHLPE6LI.js +71 -0
- package/dist/index.js +48 -34
- package/package.json +32 -16
- package/templates/none/src/main.ts +4 -0
- package/templates/none/vite.config.ts +0 -2
- package/templates/phaser/src/main.ts +0 -1
- package/templates/phaser/src/scenes/game-scene.ts +10 -8
- package/templates/phaser/vite.config.ts +0 -2
- package/templates/react-r3f/src/app.tsx +3 -1
- package/templates/react-r3f/src/main.tsx +1 -0
- package/templates/react-r3f/vite.config.ts +0 -2
- package/templates/threejs/src/main.ts +10 -1
- package/templates/threejs/vite.config.ts +0 -2
- package/LICENSE +0 -21
- package/dist/chunk-AYJQVZXY.js +0 -39
- package/dist/chunk-J6PKNPI2.js +0 -26
- package/dist/chunk-MJQSHP3Y.js +0 -415
- package/dist/chunk-MYFLYNPO.js +0 -68
|
@@ -1,14 +1,12 @@
|
|
|
1
1
|
import type { GameObjects, Input } from "phaser";
|
|
2
2
|
import { Scene } from "phaser";
|
|
3
3
|
|
|
4
|
-
// World pixels per second.
|
|
5
4
|
const SPEED = 240;
|
|
6
5
|
const SIZE = 48;
|
|
7
6
|
|
|
8
7
|
type Direction = "up" | "down" | "left" | "right";
|
|
9
8
|
|
|
10
|
-
const clamp = (value: number, min: number, max: number)
|
|
11
|
-
Math.min(max, Math.max(min, value));
|
|
9
|
+
const clamp = (value: number, min: number, max: number) => Math.min(max, Math.max(min, value));
|
|
12
10
|
|
|
13
11
|
/** A square you drive with the arrow keys or WASD. Replace it with your game. */
|
|
14
12
|
export class GameScene extends Scene {
|
|
@@ -19,7 +17,7 @@ export class GameScene extends Scene {
|
|
|
19
17
|
super("game");
|
|
20
18
|
}
|
|
21
19
|
|
|
22
|
-
create()
|
|
20
|
+
create() {
|
|
23
21
|
const { width, height } = this.scale;
|
|
24
22
|
const font = { color: "#ffffff", fontFamily: "system-ui, sans-serif" };
|
|
25
23
|
this.add.text(width / 2, 48, "__VG_SLUG__", { ...font, fontSize: "32px" }).setOrigin(0.5);
|
|
@@ -34,6 +32,7 @@ export class GameScene extends Scene {
|
|
|
34
32
|
this.player = this.add.rectangle(width / 2, height / 2, SIZE, SIZE, 0x5b_e3_ff);
|
|
35
33
|
|
|
36
34
|
const { keyboard } = this.input;
|
|
35
|
+
|
|
37
36
|
if (keyboard) {
|
|
38
37
|
this.keys = {
|
|
39
38
|
down: [keyboard.addKey("DOWN"), keyboard.addKey("S")],
|
|
@@ -44,19 +43,22 @@ export class GameScene extends Scene {
|
|
|
44
43
|
}
|
|
45
44
|
}
|
|
46
45
|
|
|
47
|
-
override update(_time: number, delta: number)
|
|
46
|
+
override update(_time: number, delta: number) {
|
|
48
47
|
const { keys, player } = this;
|
|
48
|
+
|
|
49
49
|
if (!keys || !player) {
|
|
50
50
|
return;
|
|
51
51
|
}
|
|
52
|
-
|
|
53
|
-
|
|
52
|
+
|
|
53
|
+
const held = (direction: Direction) => (keys[direction].some((key) => key.isDown) ? 1 : 0);
|
|
54
|
+
|
|
54
55
|
const dx = held("right") - held("left");
|
|
55
56
|
const dy = held("down") - held("up");
|
|
57
|
+
|
|
56
58
|
if (dx === 0 && dy === 0) {
|
|
57
59
|
return;
|
|
58
60
|
}
|
|
59
|
-
|
|
61
|
+
|
|
60
62
|
const step = (SPEED * delta) / 1000 / Math.hypot(dx, dy);
|
|
61
63
|
const half = SIZE / 2;
|
|
62
64
|
player.x = clamp(player.x + dx * step, half, this.scale.width - half);
|
|
@@ -1,7 +1,5 @@
|
|
|
1
1
|
import { defineConfig } from "vite";
|
|
2
2
|
|
|
3
|
-
// A relative base keeps built asset URLs relative, so the bundle works wherever it is
|
|
4
|
-
// hosted — including {slug}.vibedgames.com after `vg deploy ./dist`.
|
|
5
3
|
export default defineConfig({
|
|
6
4
|
base: "./",
|
|
7
5
|
server: { port: 5173 },
|
|
@@ -3,17 +3,19 @@ import { Canvas, useFrame } from "@react-three/fiber";
|
|
|
3
3
|
import { useRef } from "react";
|
|
4
4
|
import type { Mesh } from "three";
|
|
5
5
|
|
|
6
|
-
// Replace the cube with your game.
|
|
7
6
|
const SpinningCube = () => {
|
|
8
7
|
const ref = useRef<Mesh>(null);
|
|
9
8
|
useFrame((_state, delta) => {
|
|
10
9
|
const mesh = ref.current;
|
|
10
|
+
|
|
11
11
|
if (!mesh) {
|
|
12
12
|
return;
|
|
13
13
|
}
|
|
14
|
+
|
|
14
15
|
mesh.rotation.x += delta * 0.5;
|
|
15
16
|
mesh.rotation.y += delta;
|
|
16
17
|
});
|
|
18
|
+
|
|
17
19
|
return (
|
|
18
20
|
<mesh ref={ref}>
|
|
19
21
|
<boxGeometry args={[1, 1, 1]} />
|
|
@@ -1,8 +1,6 @@
|
|
|
1
1
|
import react from "@vitejs/plugin-react";
|
|
2
2
|
import { defineConfig } from "vite";
|
|
3
3
|
|
|
4
|
-
// A relative base keeps built asset URLs relative, so the bundle works wherever it is
|
|
5
|
-
// hosted — including {slug}.vibedgames.com after `vg deploy ./dist`.
|
|
6
4
|
export default defineConfig({
|
|
7
5
|
base: "./",
|
|
8
6
|
plugins: [react()],
|
|
@@ -11,24 +11,33 @@ import {
|
|
|
11
11
|
} from "three";
|
|
12
12
|
|
|
13
13
|
const scene = new Scene();
|
|
14
|
+
|
|
14
15
|
scene.background = new Color("#0e1020");
|
|
15
16
|
|
|
16
17
|
const camera = new PerspectiveCamera(60, window.innerWidth / window.innerHeight, 0.1, 100);
|
|
18
|
+
|
|
17
19
|
camera.position.set(0, 1.5, 4);
|
|
20
|
+
|
|
18
21
|
camera.lookAt(0, 0, 0);
|
|
19
22
|
|
|
20
23
|
const renderer = new WebGLRenderer({ antialias: true });
|
|
24
|
+
|
|
21
25
|
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
|
|
26
|
+
|
|
22
27
|
renderer.setSize(window.innerWidth, window.innerHeight);
|
|
28
|
+
|
|
23
29
|
document.body.append(renderer.domElement);
|
|
24
30
|
|
|
25
31
|
scene.add(new AmbientLight(0xff_ff_ff, 0.4));
|
|
32
|
+
|
|
26
33
|
const sun = new DirectionalLight(0xff_ff_ff, 2);
|
|
34
|
+
|
|
27
35
|
sun.position.set(3, 5, 2);
|
|
36
|
+
|
|
28
37
|
scene.add(sun);
|
|
29
38
|
|
|
30
|
-
// Replace the cube with your game.
|
|
31
39
|
const cube = new Mesh(new BoxGeometry(1, 1, 1), new MeshStandardMaterial({ color: "#5be3ff" }));
|
|
40
|
+
|
|
32
41
|
scene.add(cube);
|
|
33
42
|
|
|
34
43
|
window.addEventListener("resize", () => {
|
|
@@ -1,7 +1,5 @@
|
|
|
1
1
|
import { defineConfig } from "vite";
|
|
2
2
|
|
|
3
|
-
// A relative base keeps built asset URLs relative, so the bundle works wherever it is
|
|
4
|
-
// hosted — including {slug}.vibedgames.com after `vg deploy ./dist`.
|
|
5
3
|
export default defineConfig({
|
|
6
4
|
base: "./",
|
|
7
5
|
server: { port: 5173 },
|
package/LICENSE
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
MIT License
|
|
2
|
-
|
|
3
|
-
Copyright (c) 2023 Kaiyu Hsu
|
|
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/dist/chunk-AYJQVZXY.js
DELETED
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
import { createRequire as __createRequire } from "node:module";
|
|
2
|
-
import { dirname as __pathDirname } from "node:path";
|
|
3
|
-
import { fileURLToPath as __fileURLToPath } from "node:url";
|
|
4
|
-
const require = __createRequire(import.meta.url);
|
|
5
|
-
var __filename = __fileURLToPath(import.meta.url);
|
|
6
|
-
var __dirname = __pathDirname(__filename);
|
|
7
|
-
import {
|
|
8
|
-
require_cross_spawn
|
|
9
|
-
} from "./chunk-2QBYTIMH.js";
|
|
10
|
-
import {
|
|
11
|
-
__toESM
|
|
12
|
-
} from "./chunk-CAKBGDCY.js";
|
|
13
|
-
|
|
14
|
-
// src/lib/run.ts
|
|
15
|
-
var import_cross_spawn = __toESM(require_cross_spawn(), 1);
|
|
16
|
-
var isMissingCommand = (result) => result.code !== 0 && /ENOENT|not found|not recognized/iu.test(result.output);
|
|
17
|
-
var run = (cmd, args) => (
|
|
18
|
-
// oxlint-disable-next-line promise/avoid-new -- child_process.spawn is event-based
|
|
19
|
-
new Promise((resolve) => {
|
|
20
|
-
const chunks = [];
|
|
21
|
-
const child = (0, import_cross_spawn.default)(cmd, args, { stdio: ["ignore", "pipe", "pipe"] });
|
|
22
|
-
const collect = (c) => {
|
|
23
|
-
chunks.push(c);
|
|
24
|
-
};
|
|
25
|
-
child.stdout?.on("data", collect);
|
|
26
|
-
child.stderr?.on("data", collect);
|
|
27
|
-
child.on("error", (err) => resolve({ code: 1, output: `${err.message}
|
|
28
|
-
` }));
|
|
29
|
-
child.on(
|
|
30
|
-
"close",
|
|
31
|
-
(code) => resolve({ code: code ?? 1, output: Buffer.concat(chunks).toString("utf-8") })
|
|
32
|
-
);
|
|
33
|
-
})
|
|
34
|
-
);
|
|
35
|
-
|
|
36
|
-
export {
|
|
37
|
-
isMissingCommand,
|
|
38
|
-
run
|
|
39
|
-
};
|
package/dist/chunk-J6PKNPI2.js
DELETED
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
import { createRequire as __createRequire } from "node:module";
|
|
2
|
-
import { dirname as __pathDirname } from "node:path";
|
|
3
|
-
import { fileURLToPath as __fileURLToPath } from "node:url";
|
|
4
|
-
const require = __createRequire(import.meta.url);
|
|
5
|
-
var __filename = __fileURLToPath(import.meta.url);
|
|
6
|
-
var __dirname = __pathDirname(__filename);
|
|
7
|
-
|
|
8
|
-
// src/lib/types.ts
|
|
9
|
-
var isJsonObject = (value) => (
|
|
10
|
-
// Object() is the identity only on objects; arrays are split off explicitly.
|
|
11
|
-
Object(value) === value && !Array.isArray(value)
|
|
12
|
-
);
|
|
13
|
-
var isJsonString = (value) => (
|
|
14
|
-
// String() is the identity only on strings.
|
|
15
|
-
String(value) === value
|
|
16
|
-
);
|
|
17
|
-
var isJsonNumber = (value) => (
|
|
18
|
-
// JSON cannot encode NaN/Infinity, so isFinite matches every JSON number.
|
|
19
|
-
Number.isFinite(value)
|
|
20
|
-
);
|
|
21
|
-
|
|
22
|
-
export {
|
|
23
|
-
isJsonObject,
|
|
24
|
-
isJsonString,
|
|
25
|
-
isJsonNumber
|
|
26
|
-
};
|
package/dist/chunk-MJQSHP3Y.js
DELETED
|
@@ -1,415 +0,0 @@
|
|
|
1
|
-
import { createRequire as __createRequire } from "node:module";
|
|
2
|
-
import { dirname as __pathDirname } from "node:path";
|
|
3
|
-
import { fileURLToPath as __fileURLToPath } from "node:url";
|
|
4
|
-
const require = __createRequire(import.meta.url);
|
|
5
|
-
var __filename = __fileURLToPath(import.meta.url);
|
|
6
|
-
var __dirname = __pathDirname(__filename);
|
|
7
|
-
import {
|
|
8
|
-
packSource
|
|
9
|
-
} from "./chunk-I6O4HIDY.js";
|
|
10
|
-
import "./chunk-VFFOT7KD.js";
|
|
11
|
-
import {
|
|
12
|
-
SLUG_RE,
|
|
13
|
-
findProjectRoot,
|
|
14
|
-
projectConfigPath,
|
|
15
|
-
readProjectConfig,
|
|
16
|
-
writeProjectConfig
|
|
17
|
-
} from "./chunk-ZI6PKVXG.js";
|
|
18
|
-
import {
|
|
19
|
-
createClient
|
|
20
|
-
} from "./chunk-PQDBCZRT.js";
|
|
21
|
-
import "./chunk-Z4Z24FWO.js";
|
|
22
|
-
import "./chunk-PEUP4MZR.js";
|
|
23
|
-
import {
|
|
24
|
-
isJsonOutput,
|
|
25
|
-
outputArgs,
|
|
26
|
-
writeStructured
|
|
27
|
-
} from "./chunk-ZYCSYJWX.js";
|
|
28
|
-
import {
|
|
29
|
-
assertKnownFlags
|
|
30
|
-
} from "./chunk-RZ4DIJQW.js";
|
|
31
|
-
import "./chunk-RYFO3ZPO.js";
|
|
32
|
-
import {
|
|
33
|
-
consola
|
|
34
|
-
} from "./chunk-CU7UY5YJ.js";
|
|
35
|
-
import {
|
|
36
|
-
isJsonString
|
|
37
|
-
} from "./chunk-J6PKNPI2.js";
|
|
38
|
-
import {
|
|
39
|
-
defineCommand
|
|
40
|
-
} from "./chunk-MBXCVCC4.js";
|
|
41
|
-
import "./chunk-CAKBGDCY.js";
|
|
42
|
-
|
|
43
|
-
// src/commands/deploy.ts
|
|
44
|
-
import { existsSync, readFileSync as readFileSync3, rmSync } from "node:fs";
|
|
45
|
-
import { tmpdir } from "node:os";
|
|
46
|
-
import path2 from "node:path";
|
|
47
|
-
|
|
48
|
-
// src/lib/manifest.ts
|
|
49
|
-
import { createHash } from "node:crypto";
|
|
50
|
-
import { readFileSync, readdirSync, statSync } from "node:fs";
|
|
51
|
-
import path from "node:path";
|
|
52
|
-
var IGNORED_TOP_LEVEL = /* @__PURE__ */ new Set([
|
|
53
|
-
"node_modules",
|
|
54
|
-
".git",
|
|
55
|
-
".turbo",
|
|
56
|
-
".cache",
|
|
57
|
-
".DS_Store",
|
|
58
|
-
"vibedgames.json"
|
|
59
|
-
]);
|
|
60
|
-
var CONTENT_TYPES = new Map(
|
|
61
|
-
Object.entries({
|
|
62
|
-
avif: "image/avif",
|
|
63
|
-
cjs: "application/javascript; charset=utf-8",
|
|
64
|
-
css: "text/css; charset=utf-8",
|
|
65
|
-
gif: "image/gif",
|
|
66
|
-
glb: "model/gltf-binary",
|
|
67
|
-
gltf: "model/gltf+json",
|
|
68
|
-
htm: "text/html; charset=utf-8",
|
|
69
|
-
html: "text/html; charset=utf-8",
|
|
70
|
-
ico: "image/x-icon",
|
|
71
|
-
jpeg: "image/jpeg",
|
|
72
|
-
jpg: "image/jpeg",
|
|
73
|
-
js: "application/javascript; charset=utf-8",
|
|
74
|
-
json: "application/json; charset=utf-8",
|
|
75
|
-
m4a: "audio/mp4",
|
|
76
|
-
map: "application/json; charset=utf-8",
|
|
77
|
-
mjs: "application/javascript; charset=utf-8",
|
|
78
|
-
mp3: "audio/mpeg",
|
|
79
|
-
mp4: "video/mp4",
|
|
80
|
-
ogg: "audio/ogg",
|
|
81
|
-
otf: "font/otf",
|
|
82
|
-
png: "image/png",
|
|
83
|
-
svg: "image/svg+xml",
|
|
84
|
-
ttf: "font/ttf",
|
|
85
|
-
txt: "text/plain; charset=utf-8",
|
|
86
|
-
wasm: "application/wasm",
|
|
87
|
-
wav: "audio/wav",
|
|
88
|
-
webm: "video/webm",
|
|
89
|
-
webp: "image/webp",
|
|
90
|
-
woff: "font/woff",
|
|
91
|
-
woff2: "font/woff2",
|
|
92
|
-
xml: "application/xml"
|
|
93
|
-
})
|
|
94
|
-
);
|
|
95
|
-
var contentTypeForPath = (file) => {
|
|
96
|
-
const ext = file.split(".").pop()?.toLowerCase() ?? "";
|
|
97
|
-
return CONTENT_TYPES.get(ext) ?? "application/octet-stream";
|
|
98
|
-
};
|
|
99
|
-
var shouldIgnore = (relPath) => {
|
|
100
|
-
const top = relPath.split(path.sep)[0] ?? "";
|
|
101
|
-
if (IGNORED_TOP_LEVEL.has(top)) {
|
|
102
|
-
return true;
|
|
103
|
-
}
|
|
104
|
-
if (relPath.split(path.sep).some((seg) => seg.startsWith("."))) {
|
|
105
|
-
return true;
|
|
106
|
-
}
|
|
107
|
-
return false;
|
|
108
|
-
};
|
|
109
|
-
var buildManifest = (rootDir) => {
|
|
110
|
-
const files = [];
|
|
111
|
-
const walk = (dir) => {
|
|
112
|
-
for (const entry of readdirSync(dir, { withFileTypes: true })) {
|
|
113
|
-
const abs = path.join(dir, entry.name);
|
|
114
|
-
const rel = path.relative(rootDir, abs);
|
|
115
|
-
if (shouldIgnore(rel)) {
|
|
116
|
-
continue;
|
|
117
|
-
}
|
|
118
|
-
if (entry.isDirectory()) {
|
|
119
|
-
walk(abs);
|
|
120
|
-
continue;
|
|
121
|
-
}
|
|
122
|
-
if (!entry.isFile()) {
|
|
123
|
-
continue;
|
|
124
|
-
}
|
|
125
|
-
const stat = statSync(abs);
|
|
126
|
-
const buf = readFileSync(abs);
|
|
127
|
-
const sha256 = createHash("sha256").update(buf).digest("hex");
|
|
128
|
-
const posixPath = rel.split(path.sep).join("/");
|
|
129
|
-
files.push({
|
|
130
|
-
absolutePath: abs,
|
|
131
|
-
contentType: contentTypeForPath(posixPath),
|
|
132
|
-
path: posixPath,
|
|
133
|
-
sha256,
|
|
134
|
-
size: stat.size
|
|
135
|
-
});
|
|
136
|
-
}
|
|
137
|
-
};
|
|
138
|
-
walk(rootDir);
|
|
139
|
-
return files;
|
|
140
|
-
};
|
|
141
|
-
|
|
142
|
-
// src/lib/upload.ts
|
|
143
|
-
import { readFileSync as readFileSync2 } from "node:fs";
|
|
144
|
-
var uploadAll = async ({
|
|
145
|
-
files,
|
|
146
|
-
uploads,
|
|
147
|
-
concurrency = 6,
|
|
148
|
-
onProgress
|
|
149
|
-
}) => {
|
|
150
|
-
const byPath = new Map(files.map((f) => [f.path, f]));
|
|
151
|
-
let done = 0;
|
|
152
|
-
let cursor = 0;
|
|
153
|
-
const worker = async () => {
|
|
154
|
-
while (true) {
|
|
155
|
-
const idx = cursor;
|
|
156
|
-
cursor += 1;
|
|
157
|
-
if (idx >= uploads.length) {
|
|
158
|
-
return;
|
|
159
|
-
}
|
|
160
|
-
const upload = uploads[idx];
|
|
161
|
-
if (!upload) {
|
|
162
|
-
return;
|
|
163
|
-
}
|
|
164
|
-
const file = byPath.get(upload.path);
|
|
165
|
-
if (!file) {
|
|
166
|
-
throw new Error(`Missing file for upload target: ${upload.path}`);
|
|
167
|
-
}
|
|
168
|
-
const body = readFileSync2(file.absolutePath);
|
|
169
|
-
const res = await fetch(upload.url, {
|
|
170
|
-
body,
|
|
171
|
-
headers: upload.headers,
|
|
172
|
-
method: "PUT"
|
|
173
|
-
});
|
|
174
|
-
if (!res.ok) {
|
|
175
|
-
const text = await res.text().catch(() => "");
|
|
176
|
-
throw new Error(
|
|
177
|
-
`Upload failed for ${upload.path}: ${res.status} ${res.statusText} ${text}`
|
|
178
|
-
);
|
|
179
|
-
}
|
|
180
|
-
done += 1;
|
|
181
|
-
onProgress?.(done, uploads.length);
|
|
182
|
-
}
|
|
183
|
-
};
|
|
184
|
-
const workers = Array.from({ length: Math.min(concurrency, uploads.length) }, () => worker());
|
|
185
|
-
await Promise.all(workers);
|
|
186
|
-
};
|
|
187
|
-
|
|
188
|
-
// src/commands/deploy.ts
|
|
189
|
-
var deployArgs = {
|
|
190
|
-
dir: {
|
|
191
|
-
default: ".",
|
|
192
|
-
description: "Directory to deploy",
|
|
193
|
-
required: false,
|
|
194
|
-
type: "positional"
|
|
195
|
-
},
|
|
196
|
-
slug: {
|
|
197
|
-
description: "Override the slug (bypasses vibedgames.json)",
|
|
198
|
-
required: false,
|
|
199
|
-
type: "string"
|
|
200
|
-
},
|
|
201
|
-
source: {
|
|
202
|
-
default: false,
|
|
203
|
-
description: "Also upload a forkable source archive, letting anyone logged in fork the project.",
|
|
204
|
-
type: "boolean"
|
|
205
|
-
},
|
|
206
|
-
...outputArgs
|
|
207
|
-
};
|
|
208
|
-
var formatBytes = (n) => {
|
|
209
|
-
if (n < 1024) {
|
|
210
|
-
return `${n} B`;
|
|
211
|
-
}
|
|
212
|
-
if (n < 1024 * 1024) {
|
|
213
|
-
return `${(n / 1024).toFixed(1)} KB`;
|
|
214
|
-
}
|
|
215
|
-
return `${(n / (1024 * 1024)).toFixed(1)} MB`;
|
|
216
|
-
};
|
|
217
|
-
var resolveDeployDir = (dir, say) => {
|
|
218
|
-
if (!existsSync(path2.join(dir, "package.json"))) {
|
|
219
|
-
return dir;
|
|
220
|
-
}
|
|
221
|
-
for (const name of ["dist", "build", "out"]) {
|
|
222
|
-
if (existsSync(path2.join(dir, name, "index.html"))) {
|
|
223
|
-
say(`Project root detected \u2014 deploying its build output ${name}/ instead.`);
|
|
224
|
-
return path2.join(dir, name);
|
|
225
|
-
}
|
|
226
|
-
}
|
|
227
|
-
consola.warn(
|
|
228
|
-
"This looks like an unbuilt project (package.json, no dist/build/out) \u2014 run the build first, or the deployed index.html will reference missing source files."
|
|
229
|
-
);
|
|
230
|
-
return dir;
|
|
231
|
-
};
|
|
232
|
-
var promptForConfig = async (dir, say) => {
|
|
233
|
-
if (!process.stdin.isTTY) {
|
|
234
|
-
consola.error(
|
|
235
|
-
"No slug specified and no vibedgames.json found.\n Pass --slug <name> when running without a TTY (e.g. in CI or from a coding agent).\n Example: vg deploy ./dist --slug my-game"
|
|
236
|
-
);
|
|
237
|
-
process.exit(1);
|
|
238
|
-
}
|
|
239
|
-
const slug = await consola.prompt("Slug (e.g. pong):", { type: "text" });
|
|
240
|
-
if (!isJsonString(slug) || !SLUG_RE.test(slug)) {
|
|
241
|
-
consola.error("Invalid slug. Use lowercase letters, digits, hyphens.");
|
|
242
|
-
process.exit(1);
|
|
243
|
-
}
|
|
244
|
-
const name = await consola.prompt("Name (optional):", { type: "text" });
|
|
245
|
-
const config = {
|
|
246
|
-
name: isJsonString(name) && name.length > 0 ? name : void 0,
|
|
247
|
-
slug
|
|
248
|
-
};
|
|
249
|
-
writeProjectConfig(dir, config);
|
|
250
|
-
say(`Wrote ${projectConfigPath(dir)}`);
|
|
251
|
-
return config;
|
|
252
|
-
};
|
|
253
|
-
var resolveDeployConfig = async (dir, slugOverride, say) => {
|
|
254
|
-
let config = null;
|
|
255
|
-
try {
|
|
256
|
-
config = readProjectConfig(dir);
|
|
257
|
-
} catch (error) {
|
|
258
|
-
consola.error(error instanceof Error ? error.message : String(error));
|
|
259
|
-
process.exit(1);
|
|
260
|
-
}
|
|
261
|
-
if (slugOverride) {
|
|
262
|
-
config = { name: config?.name, slug: slugOverride };
|
|
263
|
-
}
|
|
264
|
-
config ??= await promptForConfig(dir, say);
|
|
265
|
-
if (!SLUG_RE.test(config.slug)) {
|
|
266
|
-
consola.error(`Invalid slug in vibedgames.json: ${config.slug}`);
|
|
267
|
-
process.exit(1);
|
|
268
|
-
}
|
|
269
|
-
return config;
|
|
270
|
-
};
|
|
271
|
-
var packForkableSource = async (dir, slug, say) => {
|
|
272
|
-
const root = findProjectRoot(dir);
|
|
273
|
-
if (!root) {
|
|
274
|
-
consola.warn("No vibedgames.json found above the deploy dir \u2014 skipping source upload.");
|
|
275
|
-
return null;
|
|
276
|
-
}
|
|
277
|
-
try {
|
|
278
|
-
const archive = await packSource(root, path2.join(tmpdir(), "vibedgames"));
|
|
279
|
-
say(
|
|
280
|
-
`Source: ${archive.files.length} files, ${formatBytes(archive.bytes)} \u2014 forkable via \`vg fork ${slug}\``
|
|
281
|
-
);
|
|
282
|
-
return archive;
|
|
283
|
-
} catch (error) {
|
|
284
|
-
consola.error(
|
|
285
|
-
`Source archive failed: ${error instanceof Error ? error.message : String(error)}`
|
|
286
|
-
);
|
|
287
|
-
process.exit(1);
|
|
288
|
-
}
|
|
289
|
-
};
|
|
290
|
-
var uploadSourceArchive = async (archive, upload) => {
|
|
291
|
-
try {
|
|
292
|
-
const res = await fetch(upload.url, {
|
|
293
|
-
body: readFileSync3(archive.path),
|
|
294
|
-
headers: upload.headers,
|
|
295
|
-
method: "PUT"
|
|
296
|
-
});
|
|
297
|
-
if (!res.ok) {
|
|
298
|
-
throw new Error(`source upload failed: ${res.status} ${res.statusText}`);
|
|
299
|
-
}
|
|
300
|
-
} catch (error) {
|
|
301
|
-
rmSync(archive.path, { force: true });
|
|
302
|
-
consola.error(error instanceof Error ? error.message : String(error));
|
|
303
|
-
process.exit(1);
|
|
304
|
-
}
|
|
305
|
-
};
|
|
306
|
-
var finalizeDeployment = async (client, deploymentId) => {
|
|
307
|
-
try {
|
|
308
|
-
return await client.deploy.finalize({ deploymentId });
|
|
309
|
-
} catch (error) {
|
|
310
|
-
consola.error(error instanceof Error ? error.message : String(error));
|
|
311
|
-
process.exit(1);
|
|
312
|
-
}
|
|
313
|
-
};
|
|
314
|
-
var deployCommand = defineCommand({
|
|
315
|
-
args: deployArgs,
|
|
316
|
-
meta: {
|
|
317
|
-
description: "Deploy a game to vibedgames",
|
|
318
|
-
name: "deploy"
|
|
319
|
-
},
|
|
320
|
-
run: async ({ args, rawArgs }) => {
|
|
321
|
-
assertKnownFlags(rawArgs, deployArgs);
|
|
322
|
-
const structured = isJsonOutput(args) || Boolean(args.field);
|
|
323
|
-
const say = structured ? () => {
|
|
324
|
-
} : (message) => consola.info(message);
|
|
325
|
-
const dir = path2.resolve(args.dir);
|
|
326
|
-
if (!existsSync(dir)) {
|
|
327
|
-
consola.error(`Directory does not exist: ${dir}`);
|
|
328
|
-
process.exit(1);
|
|
329
|
-
}
|
|
330
|
-
const deployDir = resolveDeployDir(dir, say);
|
|
331
|
-
const config = await resolveDeployConfig(dir, args.slug, say);
|
|
332
|
-
const manifest = buildManifest(deployDir);
|
|
333
|
-
if (manifest.length === 0) {
|
|
334
|
-
consola.error(`No files found in ${deployDir}`);
|
|
335
|
-
process.exit(1);
|
|
336
|
-
}
|
|
337
|
-
const hasIndex = manifest.some((f) => f.path === "index.html");
|
|
338
|
-
if (!hasIndex) {
|
|
339
|
-
consola.error("Deployment must contain an index.html at the root.");
|
|
340
|
-
process.exit(1);
|
|
341
|
-
}
|
|
342
|
-
const totalBytes = manifest.reduce((acc, f) => acc + f.size, 0);
|
|
343
|
-
say(`Deploying ${config.slug}: ${manifest.length} files, ${formatBytes(totalBytes)}`);
|
|
344
|
-
const sourceArchive = args.source ? await packForkableSource(dir, config.slug, say) : null;
|
|
345
|
-
const client = createClient();
|
|
346
|
-
const started = Date.now();
|
|
347
|
-
let created;
|
|
348
|
-
try {
|
|
349
|
-
created = await client.deploy.create({
|
|
350
|
-
files: manifest.map((f) => ({
|
|
351
|
-
contentType: f.contentType,
|
|
352
|
-
path: f.path,
|
|
353
|
-
sha256: f.sha256,
|
|
354
|
-
size: f.size
|
|
355
|
-
})),
|
|
356
|
-
name: config.name,
|
|
357
|
-
slug: config.slug,
|
|
358
|
-
source: sourceArchive ? { bytes: sourceArchive.bytes, sha256: sourceArchive.sha256 } : void 0
|
|
359
|
-
});
|
|
360
|
-
} catch (error) {
|
|
361
|
-
if (sourceArchive) {
|
|
362
|
-
rmSync(sourceArchive.path, { force: true });
|
|
363
|
-
}
|
|
364
|
-
consola.error(error instanceof Error ? error.message : String(error));
|
|
365
|
-
process.exit(1);
|
|
366
|
-
}
|
|
367
|
-
if (!structured) {
|
|
368
|
-
consola.start(`Uploading ${created.uploads.length} files`);
|
|
369
|
-
}
|
|
370
|
-
try {
|
|
371
|
-
await uploadAll({
|
|
372
|
-
files: manifest,
|
|
373
|
-
onProgress: (done, total) => {
|
|
374
|
-
if (done === total || done % 10 === 0) {
|
|
375
|
-
say(`Uploaded ${done}/${total}`);
|
|
376
|
-
}
|
|
377
|
-
},
|
|
378
|
-
uploads: created.uploads
|
|
379
|
-
});
|
|
380
|
-
} catch (error) {
|
|
381
|
-
if (sourceArchive) {
|
|
382
|
-
rmSync(sourceArchive.path, { force: true });
|
|
383
|
-
}
|
|
384
|
-
consola.error(error instanceof Error ? error.message : String(error));
|
|
385
|
-
process.exit(1);
|
|
386
|
-
}
|
|
387
|
-
if (sourceArchive) {
|
|
388
|
-
if (created.sourceUpload) {
|
|
389
|
-
await uploadSourceArchive(sourceArchive, created.sourceUpload);
|
|
390
|
-
}
|
|
391
|
-
rmSync(sourceArchive.path, { force: true });
|
|
392
|
-
}
|
|
393
|
-
const finalized = await finalizeDeployment(client, created.deploymentId);
|
|
394
|
-
const elapsedMs = Date.now() - started;
|
|
395
|
-
if (writeStructured(
|
|
396
|
-
{
|
|
397
|
-
bytes: totalBytes,
|
|
398
|
-
deployment_id: created.deploymentId,
|
|
399
|
-
elapsed_ms: elapsedMs,
|
|
400
|
-
files: manifest.length,
|
|
401
|
-
slug: config.slug,
|
|
402
|
-
source: sourceArchive ? { bytes: sourceArchive.bytes, files: sourceArchive.files.length } : null,
|
|
403
|
-
url: finalized.url
|
|
404
|
-
},
|
|
405
|
-
args
|
|
406
|
-
)) {
|
|
407
|
-
return;
|
|
408
|
-
}
|
|
409
|
-
consola.success(`Deployed ${config.slug} in ${(elapsedMs / 1e3).toFixed(1)}s`);
|
|
410
|
-
consola.log(` ${finalized.url}`);
|
|
411
|
-
}
|
|
412
|
-
});
|
|
413
|
-
export {
|
|
414
|
-
deployCommand
|
|
415
|
-
};
|