Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
63 changes: 63 additions & 0 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
name: Deploy Demo to GitHub Pages

on:
push:
branches: [ main ]
pull_request:
branches: [ main ]

permissions:
contents: read
pages: write
id-token: write

concurrency:
group: "pages"
cancel-in-progress: false

jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4

- name: Setup pnpm
uses: pnpm/action-setup@v2
with:
version: latest

- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: '18'
cache: 'pnpm'

- name: Install dependencies
run: pnpm install --frozen-lockfile

- name: Build package with types
run: pnpm --filter tps-controls build

- name: Build demo for GitHub Pages
run: pnpm --filter demo build:github

- name: Create .nojekyll file
run: touch demo/dist/.nojekyll

- name: Upload artifact
uses: actions/upload-pages-artifact@v3
with:
path: demo/dist

deploy:
environment:
name: github-pages
url: ${{ steps.deployment.outputs.page_url }}
runs-on: ubuntu-latest
needs: build
if: github.ref == 'refs/heads/main'
steps:
- name: Deploy to GitHub Pages
id: deployment
uses: actions/deploy-pages@v4
2 changes: 2 additions & 0 deletions demo/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
"scripts": {
"dev": "vite",
"build": "tsc -b && vite build",
"build:github": "vite build --base=/TPS-Controls/",
"build:github-with-types": "tsc -b && vite build --base=/TPS-Controls/",
Copy link

Copilot AI Oct 1, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The script 'build:github-with-types' appears to be unused since the workflow uses 'build:github'. Consider removing it to avoid confusion, or document when it should be used instead.

Suggested change
"build:github-with-types": "tsc -b && vite build --base=/TPS-Controls/",

Copilot uses AI. Check for mistakes.
"preview": "vite preview"
},
"dependencies": {
Expand Down
14 changes: 12 additions & 2 deletions demo/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@ import { Player } from "tps-controls"
import { Physics } from '@react-three/rapier';
import { Environment } from './Environment';

// Get the correct asset path for GitHub Pages deployment
const getAssetPath = (path: string) => {
const base = import.meta.env.BASE_URL || '/'
return base + path.replace(/^\//, '')
}

function App() {


Expand All @@ -13,7 +19,7 @@ function App() {
<span
style={{
position: 'absolute',
backgroundImage: "url('/svgs/crosshair.svg')",
backgroundImage: `url('${getAssetPath('svgs/crosshair.svg')}')`,
width: '50px',
height: '50px',
top: '50%',
Expand Down Expand Up @@ -64,7 +70,11 @@ function App() {
<Environment />

{/* Player with shadow casting */}
<Player castShadow receiveShadow />
<Player
castShadow
receiveShadow
modelPath={getAssetPath('models/player.glb')}
/>
</Physics>
</Canvas>
</KeyboardControls>
Expand Down
9 changes: 7 additions & 2 deletions demo/vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@ import { defineConfig } from 'vite'
import react from '@vitejs/plugin-react'

// https://vite.dev/config/
export default defineConfig({
export default defineConfig(({ command, mode }) => ({
plugins: [react()],
})
base: mode === 'production' ? '/TPS-Controls/' : '/',
Comment on lines 3 to +7
Copy link

Copilot AI Oct 1, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The hardcoded repository name '/TPS-Controls/' creates a maintenance burden. Consider using an environment variable or deriving it from package.json to avoid manual updates if the repository is renamed.

Copilot uses AI. Check for mistakes.
build: {
outDir: 'dist',
assetsDir: 'assets',
},
}))
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
"dev:watch": "concurrently \"pnpm --filter tps-controls dev\" \"pnpm --filter demo dev\"",
"build": "pnpm --filter tps-controls build",
"build:demo": "pnpm --filter demo build",
"build:github": "pnpm run build && pnpm --filter demo build:github",
"deploy:github": "pnpm run build:github && echo '✅ Demo built for GitHub Pages! Push to main branch to deploy.'",
"publish:package": "pnpm run build && pnpm --filter tps-controls publish",
"test": "pnpm --filter '*' test",
"lint": "eslint . --ext .ts,.tsx",
Expand Down