| 1 | #!/usr/bin/env bash |
| 2 | # Concatenate sources into build/game.js and copy the PHP API into build/. |
| 3 | # data/config.php and any sqlite are NEVER copied. |
| 4 | set -euo pipefail |
| 5 | ROOT="$(cd "$(dirname "$0")/.." && pwd)" |
| 6 | BUILD_FILE="$ROOT/build/game.js" |
| 7 | SRC_DIR="$ROOT/src" |
| 8 | |
| 9 | mkdir -p "$ROOT/build" |
| 10 | |
| 11 | printf "Build started, output file: %s\n" "$BUILD_FILE" |
| 12 | rm -f "$BUILD_FILE" |
| 13 | |
| 14 | FILES=( |
| 15 | "$SRC_DIR/i18n.js" |
| 16 | "$SRC_DIR/rules.js" |
| 17 | "$SRC_DIR/api.js" |
| 18 | "$SRC_DIR/avatar.js" |
| 19 | "$SRC_DIR/main.js" |
| 20 | ) |
| 21 | |
| 22 | { |
| 23 | printf '%s\n' "/*" |
| 24 | printf '%s\n' " * AUTO-GENERATED FILE — DO NOT EDIT BY HAND." |
| 25 | printf '%s\n' " * Built by src/build.sh from the sources in src/." |
| 26 | printf '%s\n' " */" |
| 27 | printf '%s' "var I18N_CATALOG = " |
| 28 | cat "$ROOT/server/lib/i18n.json" |
| 29 | printf ';\n' |
| 30 | } >> "$BUILD_FILE" |
| 31 | |
| 32 | for file in "${FILES[@]}" |
| 33 | do |
| 34 | if [[ ! -f "$file" ]] |
| 35 | then |
| 36 | printf "Missing source file: %s\n" "$file" >&2 |
| 37 | exit 1 |
| 38 | fi |
| 39 | printf "\n/*\n * Start File:\n * %s\n */ \n" "$file" >> "$BUILD_FILE" |
| 40 | printf "Building %s\n" "$file" |
| 41 | cat "$file" >> "$BUILD_FILE" |
| 42 | printf "\n/*\n * End File:\n * %s\n */ \n" "$file" >> "$BUILD_FILE" |
| 43 | done |
| 44 | |
| 45 | SERVER="$ROOT/server" |
| 46 | cp -f "$SERVER/api.php" "$SERVER/auth.php" "$SERVER/callback.php" \ |
| 47 | "$SERVER/logout.php" "$SERVER/router.php" "$SERVER/.htaccess" \ |
| 48 | "$ROOT/build/" |
| 49 | mkdir -p "$ROOT/build/lib" |
| 50 | cp -f "$SERVER/lib/bootstrap.php" "$SERVER/lib/Store.php" \ |
| 51 | "$SERVER/lib/Engine.php" "$SERVER/lib/i18n.json" "$SERVER/lib/I18n.php" \ |
| 52 | "$ROOT/build/lib/" |
| 53 | mkdir -p "$ROOT/build/data" |
| 54 | cp -f "$SERVER/data/.htaccess" "$ROOT/build/data/.htaccess" |
| 55 | rm -f "$ROOT/build/data/config.php" "$ROOT/build/data/config.lock" |
| 56 | rm -f "$ROOT/build/data/"*.sqlite "$ROOT/build/data/"*.sqlite-journal |
| 57 | rm -rf "$ROOT/build/data/sessions" |
| 58 | |
| 59 | printf "DONE\n" |
projects-timfalken-com allianties