BlueGit

projects-timfalken-com meteors

Files

meteors / src / build.sh

build.sh

build.sh 2.5 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/i18n.js"
18 "$SRC_DIR/planet.js"
19 "$SRC_DIR/blocks.js"
20 "$SRC_DIR/easing.js"
21 "$SRC_DIR/gameCore.js"
22 "$SRC_DIR/flameFx.js"
23 "$SRC_DIR/miniLayout.js"
24 "$SRC_DIR/miniPredict.js"
25 "$SRC_DIR/online.js"
26 "$SRC_DIR/offline.js"
27 "$SRC_DIR/reward.js"
28 "$SRC_DIR/designer.js"
29 "$SRC_DIR/loginPrompt.js"
30 "$SRC_DIR/main.js"
31)
32
33{
34 printf '%s\n' "/*"
35 printf '%s\n' " * AUTO-GENERATED FILE — DO NOT EDIT BY HAND."
36 printf '%s\n' " * Built by src/build.sh from the sources in src/."
37 printf '%s\n' " */"
38 printf '%s' "var PLANET_CATALOG = "
39 cat "$ROOT/server/lib/planets.json"
40 printf ';\n'
41 printf '%s' "var BLOCK_REGISTRY = "
42 cat "$ROOT/server/lib/blocks.json"
43 printf ';\n'
44 printf '%s' "var I18N_CATALOG = "
45 cat "$ROOT/server/lib/i18n.json"
46 printf ';\n'
47} >> "$BUILD_FILE"
48
49for file in "${FILES[@]}"
50do
51 if [[ ! -f "$file" ]]
52 then
53 printf "Missing source file: %s\n" "$file" >&2
54 exit 1
55 fi
56 printf "\n/*\n * Start File:\n * %s\n */ \n" "$file" >> "$BUILD_FILE"
57 printf "Building %s\n" "$file"
58 cat "$file" >> "$BUILD_FILE"
59 printf "\n/*\n * End File:\n * %s\n */ \n" "$file" >> "$BUILD_FILE"
60done
61
62# PHP API lives next to the static game so api.php, auth.php and callback.php
63# share a cookie path. Never copy secrets or the database.
64SERVER="$ROOT/server"
65cp -f "$SERVER/api.php" "$SERVER/auth.php" "$SERVER/callback.php" \
66 "$SERVER/logout.php" "$SERVER/router.php" "$SERVER/.htaccess" \
67 "$ROOT/build/"
68mkdir -p "$ROOT/build/lib"
69cp -f "$SERVER/lib/bootstrap.php" "$SERVER/lib/Store.php" \
70 "$SERVER/lib/Planets.php" "$SERVER/lib/planets.json" \
71 "$SERVER/lib/Blocks.php" "$SERVER/lib/blocks.json" \
72 "$SERVER/lib/i18n.json" "$SERVER/lib/I18n.php" \
73 "$ROOT/build/lib/"
74mkdir -p "$ROOT/build/data"
75cp -f "$SERVER/data/.htaccess" "$ROOT/build/data/.htaccess"
76# Belt and braces: a leftover local config or db must never enter build/.
77rm -f "$ROOT/build/data/config.php" "$ROOT/build/data/config.lock"
78rm -f "$ROOT/build/data/"*.sqlite "$ROOT/build/data/"*.sqlite-journal
79rm -rf "$ROOT/build/data/sessions"
80
81printf "DONE\n"