initial commit

This commit is contained in:
2026-07-31 18:35:00 +02:00
commit 395f761870
5 changed files with 208 additions and 0 deletions
+45
View File
@@ -0,0 +1,45 @@
# phaser-tools
CI/CD templates for [Phaser](https://phaser.io) (JavaScript) game
projects, in the same spirit as
[ebitengine-tools](../ebitengine-tools) and
[love-tools](../love-tools).
- `example-makefile.make` — project Makefile: local dev targets
(`build`, `web`, `serve`, `export`, `watch`, `clean`) plus the
Woodpecker pipeline targets (`ci-version`, `ci-export`, `ci-upload`,
`ci-update`).
- `example-woodpecker.yaml` — Woodpecker pipeline: version → build
(`node:22-alpine`, syntax check + web bundle) → upload (scp to the
droparea) → update (calls the teletypegames `/update` endpoint with
`platform=phaser`).
- `example-tasks.json` — VS Code `.vscode/tasks.json` with the common
dev tasks: **Serve** (`make serve`, default build task,
`Cmd+Shift+B`), **Build Web** and **Make build**.
- `web/index.html` — the HTML shell downloaded by `make web` and
packaged next to `phaser.min.js` and the bundled `game.js`.
There is no bundler and no `node_modules`: the pinned
`phaser.min.js` build is downloaded from the jsDelivr CDN at export
time (the same way love-tools downloads love.js), and the game
sources in `src/*.js` are concatenated in filename order into a
single `game.js`. Node is only used for a `node --check` syntax pass.
## Usage in a game repo
1. Copy `example-makefile.make` to `Makefile`, set `PROJECT` and
`PHASER_VERSION`, and put the game sources into `src/` (they are
concatenated in filename order — prefix with numbers if load order
matters).
2. Copy `example-woodpecker.yaml` to `.woodpecker.yaml` and add the
`droparea_ssh_password` / `update_secret_key` secrets in Woodpecker.
3. Copy `example-tasks.json` to `.vscode/tasks.json`.
`make serve` builds the web bundle and serves it on
`http://localhost:8000` (Python 3's built-in HTTP server).
The pipeline uploads `$(PROJECT)-$(VERSION).html.zip` to the droparea,
then triggers
`/update?platform=phaser&name=$(PROJECT)&version=$(VERSION)`.
Detailed documentation lives on the wiki: `/development/phaser`.
+82
View File
@@ -0,0 +1,82 @@
# -----------------------------------------
# Makefile Phaser project builder
# -----------------------------------------
PROJECT = phaserdemo
PHASER_VERSION = 3.90.0
SRC_DIR = src
DIST_DIR = dist
WEB_DIR = $(DIST_DIR)/web
OUTPUT_ZIP = $(PROJECT)-$(VERSION).html.zip
VERSION_FILE = .version
PHASER_JS_URL = https://cdn.jsdelivr.net/npm/phaser@$(PHASER_VERSION)/dist/phaser.min.js
INDEX_HTML_URL = https://git.teletype.hu/tools/phaser-tools/raw/branch/master/web/index.html
all: build
build:
@echo "==> Checking JS syntax"
@for f in $(SRC_DIR)/*.js; do node --check $$f; done
web: build
@mkdir -p $(WEB_DIR)
@echo "==> Downloading Phaser $(PHASER_VERSION)"
curl -sSL $(PHASER_JS_URL) -o $(WEB_DIR)/phaser.min.js
@echo "==> Downloading index.html"
curl -sSL $(INDEX_HTML_URL) -o $(WEB_DIR)/index.html
@echo "==> Bundling game sources"
cat $(SRC_DIR)/*.js > $(WEB_DIR)/game.js
serve: web
@echo "==> Serving on http://localhost:8000"
python3 -m http.server -d $(WEB_DIR) 8000
export: web
@if [ -z "$(VERSION)" ]; then \
echo "ERROR: VERSION not set!"; exit 1; \
fi
@echo "==> Packaging web build for $(VERSION)"
cd $(WEB_DIR) && zip -r ../../$(OUTPUT_ZIP) .
@echo "==> Cleaning temporary files"
rm -rf $(WEB_DIR)
watch:
fswatch -o $(SRC_DIR) | while read; do make build; done
clean:
rm -rf $(DIST_DIR)
ci-version:
@if [ -f metadata.json ]; then \
VERSION=$$(jq -r '.version' metadata.json); \
else \
VERSION=$$(git rev-parse --short HEAD); \
fi; \
BRANCH=$$(git rev-parse --abbrev-ref HEAD); \
if [ "$$BRANCH" != "main" ] && [ "$$BRANCH" != "master" ]; then \
VERSION="dev-$$VERSION-$$BRANCH"; \
fi; \
echo $$VERSION > $(VERSION_FILE)
ci-export:
@VERSION=$$(cat $(VERSION_FILE)); \
$(MAKE) export VERSION=$$VERSION
ci-upload:
@VERSION=$$(cat $(VERSION_FILE)); \
FILE="$(PROJECT)-$$VERSION.html.zip"; \
META_SRC="metadata.json"; \
META_DST="$(PROJECT)-$$VERSION.metadata.json"; \
cp $$META_SRC $$META_DST; \
sshpass -p "$(DROPAREA_SSH_PASSWORD)" scp -o StrictHostKeyChecking=no -P $(DROPAREA_PORT) \
$$FILE $$META_DST \
$(DROPAREA_USER)@$(DROPAREA_HOST):$(DROPAREA_TARGET_PATH)/
ci-update:
@VERSION=$$(cat $(VERSION_FILE)); \
curl "$(UPDATE_SERVER)/update?secret=$(UPDATE_SECRET)&name=$(PROJECT)&platform=phaser&version=$$VERSION"
.PHONY: all build web serve export watch clean ci-version ci-export ci-upload ci-update
+29
View File
@@ -0,0 +1,29 @@
{
// See https://go.microsoft.com/fwlink/?LinkId=733558
// for the documentation about the tasks.json format
// Copy to .vscode/tasks.json.
"version": "2.0.0",
"tasks": [
{
"label": "Serve",
"type": "shell",
"command": "make serve",
"problemMatcher": [],
"group": {
"kind": "build",
"isDefault": true
}
},
{
"label": "Build Web",
"type": "shell",
"command": "make web",
"problemMatcher": []
},
{
"label": "Make build",
"type": "shell",
"command": "make build"
}
]
}
+35
View File
@@ -0,0 +1,35 @@
steps:
- name: version
image: alpine
commands:
- apk add --no-cache git make jq
- make ci-version
- name: build
image: node:22-alpine
commands:
- apk add --no-cache zip make curl
- make ci-export
- name: upload
image: alpine
environment:
DROPAREA_HOST: vps.teletype.hu
DROPAREA_PORT: 2223
DROPAREA_TARGET_PATH: /home/drop
DROPAREA_USER: drop
DROPAREA_SSH_PASSWORD:
from_secret: droparea_ssh_password
commands:
- apk add --no-cache make openssh-client sshpass
- make ci-upload
- name: update
image: alpine
environment:
UPDATE_SERVER: https://teletypegames.org
UPDATE_SECRET:
from_secret: update_secret_key
commands:
- apk add --no-cache make curl
- make ci-update
+17
View File
@@ -0,0 +1,17 @@
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Phaser Game</title>
<style>
html, body { margin: 0; padding: 0; background: #000; height: 100%; overflow: hidden; }
#game { display: flex; justify-content: center; align-items: center; height: 100%; }
canvas { display: block; }
</style>
</head>
<body>
<div id="game"></div>
<script src="phaser.min.js"></script>
<script src="game.js"></script>
</body>
</html>