BlueGit

projects-timfalken-com meteors

Files

meteors / src / build.sh

build.sh

build.sh 1.9 KiB Download Raw
1#!/usr/bin/env bash
2# Concatenate game sources into build/game.js, same pattern as raytracer / frameworkv3.
3# Also copies the PHP API into build/ so a local `php -S` and the FTP deploy
4# serve the same tree. data/config.php and any sqlite are NEVER copied.
5set -euo pipefail
6ROOT="$(cd "$(dirname "$0")/.." && pwd)"
7BUILD_FILE="$ROOT/build/game.js"
8SRC_DIR="$ROOT/src"
9
10mkdir -p "$ROOT/build"
11
12printf "Build started, output file: %s\n" "$BUILD_FILE"
13rm -f "$BUILD_FILE"
14
15FILES=(
16 "$SRC_DIR/rng.js"
17 "$SRC_DIR/planet.js"
18 "$SRC_DIR/easing.js"
19 "$SRC_DIR/gameCore.js"
20 "$SRC_DIR/online.js"
21 "$SRC_DIR/main.js"
22)
23
24{
25 printf '%s\n' "/*"
26 printf '%s\n' " * AUTO-GENERATED FILE — DO NOT EDIT BY HAND."
27 printf '%s\n' " * Built by src/build.sh from the sources in src/."
28 printf '%s\n' " */"
29} >> "$BUILD_FILE"
30
31for file in "${FILES[@]}"
32do
33 if [[ ! -f "$file" ]]
34 then
35 printf "Missing source file: %s\n" "$file" >&2
36 exit 1
37 fi
38 printf "\n/*\n * Start File:\n * %s\n */ \n" "$file" >> "$BUILD_FILE"
39 printf "Building %s\n" "$file"
40 cat "$file" >> "$BUILD_FILE"
41 printf "\n/*\n * End File:\n * %s\n */ \n" "$file" >> "$BUILD_FILE"
42done
43
44# PHP API lives next to the static game so api.php, auth.php and callback.php
45# share a cookie path. Never copy secrets or the database.
46SERVER="$ROOT/server"
47cp -f "$SERVER/api.php" "$SERVER/auth.php" "$SERVER/callback.php" \
48 "$SERVER/logout.php" "$SERVER/router.php" "$SERVER/.htaccess" \
49 "$ROOT/build/"
50mkdir -p "$ROOT/build/lib"
51cp -f "$SERVER/lib/bootstrap.php" "$SERVER/lib/Store.php" "$ROOT/build/lib/"
52mkdir -p "$ROOT/build/data"
53cp -f "$SERVER/data/.htaccess" "$ROOT/build/data/.htaccess"
54# Belt and braces: a leftover local config or db must never enter build/.
55rm -f "$ROOT/build/data/config.php" "$ROOT/build/data/config.lock"
56rm -f "$ROOT/build/data/"*.sqlite "$ROOT/build/data/"*.sqlite-journal
57rm -rf "$ROOT/build/data/sessions"
58
59printf "DONE\n"