create-airjam 0.1.8 → 0.2.1

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 (89) hide show
  1. package/dist/index.js +17 -4
  2. package/package.json +10 -8
  3. package/templates/pong/.env.example +9 -2
  4. package/templates/pong/{AI_INSTRUCTIONS.md → AGENTS.md} +9 -2
  5. package/templates/pong/README.md +43 -6
  6. package/templates/pong/_gitignore +5 -0
  7. package/templates/pong/airjam-docs/for-agents/page.md +27 -0
  8. package/templates/pong/airjam-docs/getting-started/architecture/page.md +4 -1
  9. package/templates/pong/airjam-docs/getting-started/quick-start/page.md +24 -3
  10. package/templates/pong/airjam-docs/sdk/hooks/page.md +2 -1
  11. package/templates/pong/airjam-docs/sdk/networked-state/page.md +1 -1
  12. package/templates/pong/package.json +6 -3
  13. package/templates/pong/scripts/dev-secure.mjs +177 -0
  14. package/templates/pong/scripts/secure-init.mjs +134 -0
  15. package/templates/pong/src/App.tsx +2 -0
  16. package/templates/pong/src/vite-env.d.ts +1 -0
  17. package/templates/pong/vercel.json +19 -0
  18. package/templates/pong/vite.config.ts +9 -0
  19. package/templates/pong/dist/assets/index-BwJ4uU20.js +0 -269
  20. package/templates/pong/dist/assets/index-D42jDbB5.css +0 -1
  21. package/templates/pong/dist/index.html +0 -19
  22. package/templates/pong/node_modules/.bin/air-jam-server +0 -17
  23. package/templates/pong/node_modules/.bin/eslint +0 -17
  24. package/templates/pong/node_modules/.bin/eslint-config-prettier +0 -17
  25. package/templates/pong/node_modules/.bin/tsc +0 -17
  26. package/templates/pong/node_modules/.bin/tsserver +0 -17
  27. package/templates/pong/node_modules/.bin/vite +0 -17
  28. package/templates/pong/node_modules/.vite/deps/@radix-ui_react-dialog.js +0 -1680
  29. package/templates/pong/node_modules/.vite/deps/@radix-ui_react-dialog.js.map +0 -7
  30. package/templates/pong/node_modules/.vite/deps/@radix-ui_react-slider.js +0 -638
  31. package/templates/pong/node_modules/.vite/deps/@radix-ui_react-slider.js.map +0 -7
  32. package/templates/pong/node_modules/.vite/deps/@radix-ui_react-slot.js +0 -129
  33. package/templates/pong/node_modules/.vite/deps/@radix-ui_react-slot.js.map +0 -7
  34. package/templates/pong/node_modules/.vite/deps/@radix-ui_react-tabs.js +0 -434
  35. package/templates/pong/node_modules/.vite/deps/@radix-ui_react-tabs.js.map +0 -7
  36. package/templates/pong/node_modules/.vite/deps/_metadata.json +0 -163
  37. package/templates/pong/node_modules/.vite/deps/chunk-6G72RLJL.js +0 -1004
  38. package/templates/pong/node_modules/.vite/deps/chunk-6G72RLJL.js.map +0 -7
  39. package/templates/pong/node_modules/.vite/deps/chunk-BHOBIW4J.js +0 -99
  40. package/templates/pong/node_modules/.vite/deps/chunk-BHOBIW4J.js.map +0 -7
  41. package/templates/pong/node_modules/.vite/deps/chunk-E44IQKDY.js +0 -49
  42. package/templates/pong/node_modules/.vite/deps/chunk-E44IQKDY.js.map +0 -7
  43. package/templates/pong/node_modules/.vite/deps/chunk-E5X4SHYG.js +0 -21
  44. package/templates/pong/node_modules/.vite/deps/chunk-E5X4SHYG.js.map +0 -7
  45. package/templates/pong/node_modules/.vite/deps/chunk-G3PMV62Z.js +0 -35
  46. package/templates/pong/node_modules/.vite/deps/chunk-G3PMV62Z.js.map +0 -7
  47. package/templates/pong/node_modules/.vite/deps/chunk-LI6KBZ3D.js +0 -292
  48. package/templates/pong/node_modules/.vite/deps/chunk-LI6KBZ3D.js.map +0 -7
  49. package/templates/pong/node_modules/.vite/deps/chunk-MDNXVKSA.js +0 -337
  50. package/templates/pong/node_modules/.vite/deps/chunk-MDNXVKSA.js.map +0 -7
  51. package/templates/pong/node_modules/.vite/deps/chunk-METQ356G.js +0 -280
  52. package/templates/pong/node_modules/.vite/deps/chunk-METQ356G.js.map +0 -7
  53. package/templates/pong/node_modules/.vite/deps/chunk-NPTAWNEA.js +0 -171
  54. package/templates/pong/node_modules/.vite/deps/chunk-NPTAWNEA.js.map +0 -7
  55. package/templates/pong/node_modules/.vite/deps/class-variance-authority.js +0 -51
  56. package/templates/pong/node_modules/.vite/deps/class-variance-authority.js.map +0 -7
  57. package/templates/pong/node_modules/.vite/deps/clsx.js +0 -9
  58. package/templates/pong/node_modules/.vite/deps/clsx.js.map +0 -7
  59. package/templates/pong/node_modules/.vite/deps/howler.js +0 -2241
  60. package/templates/pong/node_modules/.vite/deps/howler.js.map +0 -7
  61. package/templates/pong/node_modules/.vite/deps/html5-qrcode.js +0 -29350
  62. package/templates/pong/node_modules/.vite/deps/html5-qrcode.js.map +0 -7
  63. package/templates/pong/node_modules/.vite/deps/lucide-react.js +0 -28662
  64. package/templates/pong/node_modules/.vite/deps/lucide-react.js.map +0 -7
  65. package/templates/pong/node_modules/.vite/deps/package.json +0 -3
  66. package/templates/pong/node_modules/.vite/deps/qrcode.js +0 -2083
  67. package/templates/pong/node_modules/.vite/deps/qrcode.js.map +0 -7
  68. package/templates/pong/node_modules/.vite/deps/react-dom.js +0 -6
  69. package/templates/pong/node_modules/.vite/deps/react-dom.js.map +0 -7
  70. package/templates/pong/node_modules/.vite/deps/react-dom_client.js +0 -20217
  71. package/templates/pong/node_modules/.vite/deps/react-dom_client.js.map +0 -7
  72. package/templates/pong/node_modules/.vite/deps/react-router-dom.js +0 -13900
  73. package/templates/pong/node_modules/.vite/deps/react-router-dom.js.map +0 -7
  74. package/templates/pong/node_modules/.vite/deps/react.js +0 -5
  75. package/templates/pong/node_modules/.vite/deps/react.js.map +0 -7
  76. package/templates/pong/node_modules/.vite/deps/react_jsx-dev-runtime.js +0 -278
  77. package/templates/pong/node_modules/.vite/deps/react_jsx-dev-runtime.js.map +0 -7
  78. package/templates/pong/node_modules/.vite/deps/react_jsx-runtime.js +0 -6
  79. package/templates/pong/node_modules/.vite/deps/react_jsx-runtime.js.map +0 -7
  80. package/templates/pong/node_modules/.vite/deps/socket__io-client.js +0 -3422
  81. package/templates/pong/node_modules/.vite/deps/socket__io-client.js.map +0 -7
  82. package/templates/pong/node_modules/.vite/deps/tailwind-merge.js +0 -2534
  83. package/templates/pong/node_modules/.vite/deps/tailwind-merge.js.map +0 -7
  84. package/templates/pong/node_modules/.vite/deps/zod.js +0 -13810
  85. package/templates/pong/node_modules/.vite/deps/zod.js.map +0 -7
  86. package/templates/pong/node_modules/.vite/deps/zustand.js +0 -56
  87. package/templates/pong/node_modules/.vite/deps/zustand.js.map +0 -7
  88. package/templates/pong/node_modules/.vite/deps/zustand_react_shallow.js +0 -77
  89. package/templates/pong/node_modules/.vite/deps/zustand_react_shallow.js.map +0 -7
package/dist/index.js CHANGED
@@ -82,6 +82,11 @@ Creating project in ${targetDir}...
82
82
  return true;
83
83
  }
84
84
  });
85
+ const gitignorePlaceholderPath = path.join(targetDir, "_gitignore");
86
+ const gitignorePath = path.join(targetDir, ".gitignore");
87
+ if (fs.existsSync(gitignorePlaceholderPath)) {
88
+ await fs.move(gitignorePlaceholderPath, gitignorePath, { overwrite: true });
89
+ }
85
90
  const pkgPath = path.join(targetDir, "package.json");
86
91
  if (fs.existsSync(pkgPath)) {
87
92
  const pkg = await fs.readJson(pkgPath);
@@ -106,14 +111,22 @@ Creating project in ${targetDir}...
106
111
  }
107
112
  console.log("Next steps:\n");
108
113
  console.log(kleur.cyan(` cd ${projectName}`));
109
- console.log(kleur.cyan(" cp .env.example .env"));
114
+ console.log(kleur.cyan(" cp .env.example .env.local"));
115
+ console.log(kleur.cyan(" pnpm run dev:server # Terminal 1 - Start server"));
116
+ console.log(kleur.cyan(" pnpm run dev # Terminal 2 - Start game"));
110
117
  console.log(
111
118
  kleur.cyan(
112
- " # Edit .env and set AIR_JAM_MASTER_KEY (optional for local dev)"
119
+ " # Optional HTTPS mode (needed for gyro/camera testing on phones)"
113
120
  )
114
121
  );
115
- console.log(kleur.cyan(" pnpm run dev:server # Terminal 1 - Start server"));
116
- console.log(kleur.cyan(" pnpm run dev # Terminal 2 - Start game"));
122
+ console.log(
123
+ kleur.cyan(
124
+ " pnpm run secure:init -- --hostname my-game-dev.example.com --tunnel my-game-dev"
125
+ )
126
+ );
127
+ console.log(
128
+ kleur.cyan(" pnpm run dev:secure # Optional HTTPS mode for sensors")
129
+ );
117
130
  console.log("");
118
131
  console.log(
119
132
  kleur.dim(
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "create-airjam",
3
- "version": "0.1.8",
3
+ "version": "0.2.1",
4
4
  "description": "CLI to scaffold Air Jam game projects",
5
5
  "type": "module",
6
6
  "license": "MIT",
@@ -10,6 +10,9 @@
10
10
  "directory": "packages/create-airjam"
11
11
  },
12
12
  "homepage": "https://github.com/vucinatim/air-jam#readme",
13
+ "bugs": {
14
+ "url": "https://github.com/vucinatim/air-jam/issues"
15
+ },
13
16
  "keywords": [
14
17
  "air-jam",
15
18
  "cli",
@@ -28,12 +31,6 @@
28
31
  "dist",
29
32
  "templates"
30
33
  ],
31
- "scripts": {
32
- "extract-docs": "tsx scripts/extract-docs.ts",
33
- "build": "pnpm extract-docs && tsup",
34
- "dev": "tsup --watch",
35
- "prepublishOnly": "node scripts/prepublish.js && pnpm build"
36
- },
37
34
  "dependencies": {
38
35
  "commander": "^14.0.0",
39
36
  "fs-extra": "^11.3.0",
@@ -46,5 +43,10 @@
46
43
  "tsup": "^8.5.1",
47
44
  "tsx": "^4.19.2",
48
45
  "typescript": "~5.9.3"
46
+ },
47
+ "scripts": {
48
+ "extract-docs": "tsx scripts/extract-docs.ts",
49
+ "build": "pnpm extract-docs && tsup",
50
+ "dev": "tsup --watch"
49
51
  }
50
- }
52
+ }
@@ -5,7 +5,14 @@
5
5
  # For production, set to your official Air Jam server URL: wss://api.air-jam.app
6
6
  VITE_AIR_JAM_SERVER_URL=http://localhost:4000
7
7
 
8
- # API Key - optional for local development (not required when using local server)
8
+ # Public API Key - optional for local development (not required when using local server)
9
9
  # Required for production - get from Air Jam platform
10
- VITE_AIR_JAM_API_KEY=
10
+ VITE_AIR_JAM_PUBLIC_KEY=
11
11
 
12
+ # HTTPS host used only by `pnpm run dev:secure` (set by `pnpm run secure:init`)
13
+ # Example: https://my-game-dev.example.com
14
+ AIR_JAM_SECURE_PUBLIC_HOST=
15
+
16
+ # Named Cloudflare tunnel used by `pnpm run dev:secure`
17
+ # Example: my-airjam-dev
18
+ CLOUDFLARE_TUNNEL_NAME=
@@ -3,13 +3,16 @@ description: Universal project rules and tech stack standards
3
3
  globs: "**/*.ts, **/*.tsx, **/*.js, **/*.jsx, **/*.json"
4
4
  alwaysApply: true
5
5
  ---
6
+
6
7
  # Identity & Goals
8
+
7
9
  - You are a senior frontend architect and full-stack engineer.
8
10
  - Focus on modern, type-safe, and functional programming patterns.
9
11
  - Prioritize maintainability and strict type safety over brevity.
10
- - Use airjam-docs for documentation on the Air Jam SDK.
12
+ - Use ./airjam-docs for documentation on the Air Jam SDK.
11
13
 
12
14
  # Tech Stack (Strict)
15
+
13
16
  - **Manager**: pnpm (monorepo structure)
14
17
  - **Framework**: React (Frontend), Vite (Build)
15
18
  - **Language**: TypeScript (Strict mode)
@@ -17,6 +20,7 @@ alwaysApply: true
17
20
  - **State**: Zustand (Global)
18
21
 
19
22
  # Coding Conventions
23
+
20
24
  - **Naming**:
21
25
  - `camelCase` for variables and functions.
22
26
  - `PascalCase` for React components and Type definitions.
@@ -26,6 +30,7 @@ alwaysApply: true
26
30
  - **Direct Access**: Do NOT pass props (prop drilling) if data is available via Zustand store or React Context.
27
31
 
28
32
  # Type Safety & Linting & State Management
33
+
29
34
  - **Zod First**: Define schema validation with Zod before implementing logic.
30
35
  - **No Any**: `any` are strictly forbidden. Use generic types or specific interfaces.
31
36
  - **TSC**: Code must pass `tsc` check without errors.
@@ -33,12 +38,14 @@ alwaysApply: true
33
38
  - **Zustand**: Use atomic selectors when consuming state to prevent unnecessary re-renders.
34
39
 
35
40
  # File Structure & Refactoring
41
+
36
42
  - **Co-location**:
37
43
  - If a component is used only once, keep it in the same file as the parent.
38
44
  - If a component is used >1 time, extract to `components/` folder.
39
45
  - **Shared Code**: All shared schemas/types must reside in the `packages/shared` workspace.
40
46
 
41
47
  # Agent Behavior
48
+
42
49
  - **Dependencies**: Always use `pnpm add` to install new packages.
43
50
  - **Verification**: Verify file paths before creation. Ensure imports match the `kebab-case` filename convention.
44
- - **Cleanliness**: Remove unused imports and dead code immediately; do not comment them out.
51
+ - **Cleanliness**: Remove unused imports and dead code immediately; do not comment them out.
@@ -7,15 +7,17 @@ A starter template for building multiplayer games with Air Jam. This template in
7
7
  ### Installation
8
8
 
9
9
  1. Install dependencies:
10
+
10
11
  ```bash
11
12
  pnpm install
12
13
  ```
13
14
 
14
15
  2. Configure environment variables (optional - defaults work for local dev):
16
+
15
17
  ```bash
16
- mv .env.example .env.local
18
+ cp .env.example .env.local
17
19
  ```
18
-
20
+
19
21
  Then edit `.env.local` with your settings if needed.
20
22
 
21
23
  ## Local Development
@@ -23,6 +25,7 @@ A starter template for building multiplayer games with Air Jam. This template in
23
25
  ### Option 1: Run Server and Game Separately (Recommended)
24
26
 
25
27
  **Terminal 1 - Start the local server:**
28
+
26
29
  ```bash
27
30
  pnpm run dev:server
28
31
  ```
@@ -30,6 +33,7 @@ pnpm run dev:server
30
33
  The server will start on `http://localhost:4000` in development mode (no authentication required).
31
34
 
32
35
  **Terminal 2 - Start the game:**
36
+
33
37
  ```bash
34
38
  pnpm run dev
35
39
  ```
@@ -44,13 +48,43 @@ If you prefer to use the official Air Jam server instead of running locally:
44
48
  2. Set in `.env.local`:
45
49
  ```bash
46
50
  VITE_AIR_JAM_SERVER_URL=https://api.air-jam.app
47
- VITE_AIR_JAM_API_KEY=your-api-key-here
51
+ VITE_AIR_JAM_PUBLIC_KEY=your-public-key-here
48
52
  ```
49
53
  3. Run only the game:
50
54
  ```bash
51
55
  pnpm run dev
52
56
  ```
53
57
 
58
+ ### Option 3: Optional HTTPS for Device Sensors (Gyroscope/Camera)
59
+
60
+ Most local development works on plain HTTP. Use this only when you need secure browser APIs (gyroscope, motion sensors, some camera APIs).
61
+
62
+ One-time setup per project:
63
+
64
+ 1. Log in to Cloudflare Tunnel:
65
+ ```bash
66
+ cloudflared tunnel login
67
+ ```
68
+ 2. Initialize secure mode:
69
+ ```bash
70
+ pnpm run secure:init -- --hostname my-game-dev.example.com --tunnel my-game-dev
71
+ ```
72
+ This writes `.cloudflared/config.yml` and updates `.env.local`.
73
+
74
+ Daily secure dev:
75
+
76
+ ```bash
77
+ pnpm run dev:secure
78
+ ```
79
+
80
+ What `dev:secure` does:
81
+
82
+ - starts local Air Jam server on `http://localhost:4000`
83
+ - starts Vite on `http://localhost:5173`
84
+ - runs your named Cloudflare tunnel
85
+ - serves your host/controller over the configured HTTPS hostname
86
+ - injects `VITE_AIR_JAM_SERVER_URL` and `VITE_AIR_JAM_PUBLIC_HOST` at runtime from `AIR_JAM_SECURE_PUBLIC_HOST`
87
+
54
88
  ## Playing the Game
55
89
 
56
90
  1. Open the game URL in your browser (host view)
@@ -74,7 +108,10 @@ src/
74
108
  See `.env.example` for all available environment variables. Key variables:
75
109
 
76
110
  - `VITE_AIR_JAM_SERVER_URL` - Server URL (defaults to localhost:4000 for local dev)
77
- - `VITE_AIR_JAM_API_KEY` - API key (optional for local dev, required for production)
111
+ - `VITE_AIR_JAM_PUBLIC_KEY` - Public API key (optional for local dev, required for production)
112
+ - `VITE_AIR_JAM_API_KEY` - Legacy public key variable (still supported)
113
+ - `AIR_JAM_SECURE_PUBLIC_HOST` - HTTPS hostname used by `dev:secure` for host/controller URLs
114
+ - `CLOUDFLARE_TUNNEL_NAME` - Named Cloudflare tunnel used by `dev:secure`
78
115
 
79
116
  ## Production Deployment
80
117
 
@@ -82,7 +119,7 @@ See `.env.example` for all available environment variables. Key variables:
82
119
 
83
120
  1. Set environment variables in Vercel:
84
121
  - `VITE_AIR_JAM_SERVER_URL` - Your official Air Jam server URL
85
- - `VITE_AIR_JAM_API_KEY` - Your API key from the Air Jam platform
122
+ - `VITE_AIR_JAM_PUBLIC_KEY` - Your public API key from the Air Jam platform
86
123
 
87
124
  2. Deploy:
88
125
  ```bash
@@ -90,6 +127,7 @@ See `.env.example` for all available environment variables. Key variables:
90
127
  ```
91
128
 
92
129
  The game will connect to the official Air Jam server - no local server needed!
130
+ `vercel.json` is included in this template so `/controller?room=XXXX` and other SPA routes resolve correctly.
93
131
 
94
132
  ### Building for Production
95
133
 
@@ -108,4 +146,3 @@ The built files will be in the `dist/` directory.
108
146
  ## License
109
147
 
110
148
  MIT
111
-
@@ -0,0 +1,5 @@
1
+ node_modules
2
+ dist
3
+ dist-ssr
4
+ .env.local
5
+ .cloudflared
@@ -0,0 +1,27 @@
1
+ # For Agents
2
+
3
+ This page is the fastest entrypoint for LLM agents and automation tools.
4
+
5
+ ## What Air Jam Is
6
+
7
+ Air Jam is a multiplayer game platform and SDK where players join sessions by scanning a QR code on their phone.
8
+ Hosts run in your game, inputs are routed through the Air Jam server, and your game consumes typed controller state via React hooks.
9
+
10
+ ## Read These First
11
+
12
+ 1. [Introduction](/docs/getting-started/introduction)
13
+ 2. [Quick Start](/docs/getting-started/quick-start)
14
+ 3. [Architecture](/docs/how-it-works/architecture)
15
+ 4. [Host System](/docs/how-it-works/host-system)
16
+ 5. [SDK Hooks](/docs/sdk/hooks)
17
+
18
+ ## SDK Focus Areas
19
+
20
+ - [Input System](/docs/sdk/input-system)
21
+ - [Networked State](/docs/sdk/networked-state)
22
+
23
+ ## Machine Discovery
24
+
25
+ - [LLMs Index](/llms.txt)
26
+ - [Sitemap](/sitemap.xml)
27
+ - [Robots](/robots.txt)
@@ -13,12 +13,14 @@ Air Jam consists of four main components in a monorepo structure. This page expl
13
13
  **Technology:** Next.js 15, TypeScript, tRPC, BetterAuth, PostgreSQL (Drizzle ORM)
14
14
 
15
15
  **Key Features:**
16
+
16
17
  - **Developer Portal** - Account management, API key generation, analytics
17
18
  - **Game Catalog** - Submit, manage, and discover Air Jam games
18
19
  - **Arcade Mode** - Browse and launch games from a unified interface
19
20
  - **Controller Shell** - Persistent mobile wrapper that loads game controllers
20
21
 
21
22
  **Arcade Mode Flow:**
23
+
22
24
  ```
23
25
  1. Player scans QR on arcade screen
24
26
  2. Platform loads controller shell on phone
@@ -59,6 +61,7 @@ Air Jam consists of four main components in a monorepo structure. This page expl
59
61
  **Technology:** React, Vite, React Three Fiber, Rapier Physics
60
62
 
61
63
  **Demonstrates:**
64
+
62
65
  - Host-side game logic with physics
63
66
  - Controller UI with joystick and buttons
64
67
  - Player spawning/despawning on join/leave
@@ -162,4 +165,4 @@ Controller runs inside platform's shell (iframe communication).
162
165
 
163
166
  - Zod schemas validate all incoming input
164
167
  - Invalid input is rejected with console warning
165
- - Protects game logic from malformed data
168
+ - Protects game logic from malformed data
@@ -25,7 +25,7 @@ You'll need two terminal windows to run the local development environment: one f
25
25
  This runs the local WebSocket server that handles game connections.
26
26
 
27
27
  ```bash
28
- pnpm dev:server
28
+ pnpm run dev:server
29
29
  ```
30
30
 
31
31
  > **Note:** The local server runs on `http://localhost:4000`.
@@ -34,7 +34,7 @@ pnpm dev:server
34
34
  This runs the game client (Vite).
35
35
 
36
36
  ```bash
37
- pnpm dev
37
+ pnpm run dev
38
38
  ```
39
39
 
40
40
  ## 3. Play the Game
@@ -44,10 +44,31 @@ Open your browser and visit:
44
44
  [http://localhost:5173](http://localhost:5173)
45
45
 
46
46
  You should see the Pong template game. You can now:
47
+
47
48
  1. Open the game in your browser (Host view)
48
49
  2. Scan the QR code with your phone (Controller view)
49
50
  3. Play the game!
50
51
 
52
+ ## Optional: HTTPS for Motion Sensors
53
+
54
+ Most local Air Jam development works on HTTP. Enable HTTPS only when you need secure browser APIs such as gyroscope or motion sensors.
55
+
56
+ 1. One-time Cloudflare login:
57
+ ```bash
58
+ cloudflared tunnel login
59
+ ```
60
+ 2. One-time project secure setup:
61
+ ```bash
62
+ pnpm run secure:init -- --hostname my-game-dev.example.com --tunnel my-game-dev
63
+ ```
64
+ 3. Run secure dev:
65
+ ```bash
66
+ pnpm run dev:secure
67
+ ```
68
+
69
+ This keeps the local Air Jam server on `http://localhost:4000`, tunnels only the Vite host URL through HTTPS, and uses that secure host for controller QR URLs.
70
+ `dev:secure` injects secure `VITE_AIR_JAM_SERVER_URL` and `VITE_AIR_JAM_PUBLIC_HOST` at runtime from `AIR_JAM_SECURE_PUBLIC_HOST`.
71
+
51
72
  ## 4. Customize & Build
52
73
 
53
74
  This project is "vibecode friendly"—it includes documentation and AI instructions to help you build faster.
@@ -72,7 +93,7 @@ When you're ready to share your game, you'll need to deploy it and connect it to
72
93
  - Set the following environment variables in your deployment settings:
73
94
 
74
95
  ```bash
75
- VITE_AIR_JAM_API_KEY=your_api_key_here
96
+ VITE_AIR_JAM_PUBLIC_KEY=your_public_key_here
76
97
  VITE_AIR_JAM_SERVER_URL=wss://api.air-jam.app
77
98
  ```
78
99
 
@@ -43,7 +43,8 @@ const inputSchema = z.object({
43
43
  The provider automatically reads from these environment variables if props aren't provided:
44
44
 
45
45
  - `VITE_AIR_JAM_SERVER_URL` / `NEXT_PUBLIC_AIR_JAM_SERVER_URL` - WebSocket server URL
46
- - `VITE_AIR_JAM_API_KEY` / `NEXT_PUBLIC_AIR_JAM_API_KEY` - API key
46
+ - `VITE_AIR_JAM_PUBLIC_KEY` / `NEXT_PUBLIC_AIR_JAM_PUBLIC_KEY` - Public API key
47
+ - `VITE_AIR_JAM_API_KEY` / `NEXT_PUBLIC_AIR_JAM_API_KEY` - Legacy public key variable (still supported)
47
48
 
48
49
  ---
49
50
 
@@ -572,4 +572,4 @@ const useGameStore = createAirJamStore<GameState>((set) => ({
572
572
 
573
573
  - [SDK Hooks](/docs/sdk/hooks) - Other SDK hooks and utilities
574
574
  - [Input System](/docs/sdk/input-system) - Handling controller input
575
- - [Architecture](/docs/getting-started/architecture) - System overview
575
+ - [Architecture](/docs/how-it-works/architecture) - System overview
@@ -6,12 +6,14 @@
6
6
  "scripts": {
7
7
  "dev": "vite",
8
8
  "dev:server": "air-jam-server",
9
+ "secure:init": "node ./scripts/secure-init.mjs",
10
+ "dev:secure": "node ./scripts/dev-secure.mjs",
9
11
  "build": "tsc && vite build",
10
12
  "preview": "vite preview",
11
13
  "typecheck": "tsc --noEmit"
12
14
  },
13
15
  "dependencies": {
14
- "@air-jam/sdk": "^0.1.3",
16
+ "@air-jam/sdk": "^0.1.4",
15
17
  "react": "^19.0.0",
16
18
  "react-dom": "^19.0.0",
17
19
  "react-router-dom": "^7.0.0",
@@ -21,10 +23,10 @@
21
23
  "@air-jam/server": "^0.1.3",
22
24
  "@eslint/js": "^9.39.1",
23
25
  "@tailwindcss/vite": "^4.0.0",
26
+ "@types/node": "^22.0.0",
24
27
  "@types/react": "^19.0.0",
25
28
  "@types/react-dom": "^19.0.0",
26
29
  "@vitejs/plugin-react": "^4.3.0",
27
- "@types/node": "^22.0.0",
28
30
  "eslint": "^9.39.1",
29
31
  "eslint-config-prettier": "^10.1.8",
30
32
  "eslint-plugin-react-hooks": "^7.0.1",
@@ -33,6 +35,7 @@
33
35
  "tailwindcss": "^4.0.0",
34
36
  "typescript": "~5.6.0",
35
37
  "typescript-eslint": "^8.46.4",
36
- "vite": "^6.0.0"
38
+ "vite": "^6.0.0",
39
+ "cloudflared": "^0.7.1"
37
40
  }
38
41
  }
@@ -0,0 +1,177 @@
1
+ #!/usr/bin/env node
2
+
3
+ import { spawn } from "node:child_process";
4
+ import fs from "node:fs";
5
+ import net from "node:net";
6
+
7
+ const SERVER_PORT = 4000;
8
+ const GAME_PORT = 5173;
9
+ const START_TIMEOUT_MS = 20_000;
10
+
11
+ const children = [];
12
+
13
+ function loadEnvFile(filePath) {
14
+ if (!fs.existsSync(filePath)) return;
15
+ const content = fs.readFileSync(filePath, "utf8");
16
+ for (const rawLine of content.split("\n")) {
17
+ const line = rawLine.trim();
18
+ if (!line || line.startsWith("#")) continue;
19
+ const eq = line.indexOf("=");
20
+ if (eq <= 0) continue;
21
+ const key = line.slice(0, eq).trim();
22
+ const value = line.slice(eq + 1).trim();
23
+ if (!process.env[key]) {
24
+ process.env[key] = value;
25
+ }
26
+ }
27
+ }
28
+
29
+ function logPrefix(prefix, data) {
30
+ const text = data.toString();
31
+ for (const line of text.split("\n")) {
32
+ if (!line.trim()) continue;
33
+ console.log(`[${prefix}] ${line}`);
34
+ }
35
+ }
36
+
37
+ function run(name, command, args, options = {}) {
38
+ const { fatal = true, ...spawnOptions } = options;
39
+ const child = spawn(command, args, {
40
+ stdio: ["inherit", "pipe", "pipe"],
41
+ ...spawnOptions,
42
+ });
43
+
44
+ child.stdout.on("data", (data) => logPrefix(name, data));
45
+ child.stderr.on("data", (data) => logPrefix(name, data));
46
+ child.on("exit", (code) => {
47
+ if (fatal && code !== 0) {
48
+ console.error(`[${name}] exited with code ${code}`);
49
+ shutdown(code ?? 1);
50
+ }
51
+ });
52
+
53
+ children.push(child);
54
+ return child;
55
+ }
56
+
57
+ function isPortOpen(port) {
58
+ return new Promise((resolve) => {
59
+ const socket = net.createConnection({ port, host: "127.0.0.1" });
60
+ const done = (value) => {
61
+ socket.removeAllListeners();
62
+ socket.destroy();
63
+ resolve(value);
64
+ };
65
+
66
+ socket.setTimeout(400);
67
+ socket.on("connect", () => done(true));
68
+ socket.on("timeout", () => done(false));
69
+ socket.on("error", () => done(false));
70
+ });
71
+ }
72
+
73
+ function waitForPort(port, timeoutMs) {
74
+ return new Promise((resolve, reject) => {
75
+ const start = Date.now();
76
+
77
+ const tryConnect = () => {
78
+ const socket = net.createConnection({ port, host: "127.0.0.1" });
79
+
80
+ socket.on("connect", () => {
81
+ socket.end();
82
+ resolve(true);
83
+ });
84
+
85
+ socket.on("error", () => {
86
+ socket.destroy();
87
+ if (Date.now() - start > timeoutMs) {
88
+ reject(new Error(`Timed out waiting for localhost:${port}`));
89
+ return;
90
+ }
91
+ setTimeout(tryConnect, 300);
92
+ });
93
+ };
94
+
95
+ tryConnect();
96
+ });
97
+ }
98
+
99
+ let isShuttingDown = false;
100
+ function shutdown(code = 0) {
101
+ if (isShuttingDown) return;
102
+ isShuttingDown = true;
103
+
104
+ for (const child of children) {
105
+ if (!child.killed) {
106
+ child.kill("SIGTERM");
107
+ }
108
+ }
109
+
110
+ setTimeout(() => process.exit(code), 100);
111
+ }
112
+
113
+ process.on("SIGINT", () => shutdown(0));
114
+ process.on("SIGTERM", () => shutdown(0));
115
+
116
+ async function main() {
117
+ console.log("Starting Air Jam secure dev mode (Cloudflare named tunnel)...");
118
+ loadEnvFile(".env");
119
+ loadEnvFile(".env.local");
120
+
121
+ const publicHost =
122
+ process.env.AIR_JAM_SECURE_PUBLIC_HOST ||
123
+ process.env.VITE_AIR_JAM_PUBLIC_HOST;
124
+ const tunnelName = process.env.CLOUDFLARE_TUNNEL_NAME;
125
+ if (!publicHost || !tunnelName) {
126
+ throw new Error(
127
+ "Missing AIR_JAM_SECURE_PUBLIC_HOST (or VITE_AIR_JAM_PUBLIC_HOST) or CLOUDFLARE_TUNNEL_NAME. Run `pnpm run secure:init` first.",
128
+ );
129
+ }
130
+
131
+ const hasExistingServer = await isPortOpen(SERVER_PORT);
132
+ if (hasExistingServer) {
133
+ console.log(
134
+ `Detected existing local server on :${SERVER_PORT}, reusing it.`,
135
+ );
136
+ } else {
137
+ run("server", "pnpm", ["run", "dev:server"]);
138
+ await waitForPort(SERVER_PORT, START_TIMEOUT_MS);
139
+ }
140
+
141
+ const hasExistingGame = await isPortOpen(GAME_PORT);
142
+ if (hasExistingGame) {
143
+ throw new Error(
144
+ `Port ${GAME_PORT} is already in use. Stop existing Vite dev server and retry.`,
145
+ );
146
+ }
147
+
148
+ run("game", "pnpm", ["run", "dev"], {
149
+ env: {
150
+ ...process.env,
151
+ VITE_AIR_JAM_PUBLIC_HOST: publicHost,
152
+ VITE_AIR_JAM_SERVER_URL: publicHost,
153
+ },
154
+ });
155
+ await waitForPort(GAME_PORT, START_TIMEOUT_MS);
156
+
157
+ run("cloudflared", "pnpm", [
158
+ "exec",
159
+ "cloudflared",
160
+ "tunnel",
161
+ "--config",
162
+ ".cloudflared/config.yml",
163
+ "run",
164
+ tunnelName,
165
+ ]);
166
+
167
+ console.log("\nAir Jam secure dev is running.");
168
+ console.log(`Open host: ${publicHost}`);
169
+ console.log(`Cloudflare tunnel: ${tunnelName}`);
170
+ console.log("Local server remains on http://localhost:4000 via Vite proxy.");
171
+ console.log("QR codes use the secure host above.");
172
+ }
173
+
174
+ main().catch((error) => {
175
+ console.error(error.message || error);
176
+ shutdown(1);
177
+ });