Merge branch 'lmazet/trivabble-avoid_serving_git_file'

This commit is contained in:
Raphaël Jakse 2020-05-03 13:43:52 +02:00
commit 1460660895
25 changed files with 70 additions and 23 deletions

4
.gitignore vendored
View File

@ -1,2 +1,2 @@
/games.backup.json
/config.js
/server/games.backup.json
/public/config.js

13
Makefile Normal file
View File

@ -0,0 +1,13 @@
# -*- Makefile -*-
PORT = 3000
help:
@echo make lang: build translation files
@echo make start-dev-server: start a development server
lang:
cd l10n; make
start-dev-server:
DEV_ENABLE_SERVING_FILES=true TRIVABBLE_PORT=$(PORT) node trivabble-server.js

View File

@ -9,7 +9,7 @@ WORKING_DIRECTORY="$(dirname "$(dirname "$0")")"
if [ -d "$WORKING_DIRECTORY/.git" ]; then
if [ -z "$(git status --porcelain | grep '.js$')" ]; then
sed -i -E 's/(^|\(|\s)(let|const)(\s)/\1var\3/g' "$WORKING_DIRECTORY"/*.js
sed -i -E 's/(^|\(|\s)(let|const)(\s)/\1var\3/g' "$WORKING_DIRECTORY/public"/*.js
else
>&2 echo "You have untracked changes in JS files. I'm not going to mess up with your working copy."
exit 1

View File

@ -2,6 +2,6 @@
exec "$(dirname "$0")/disable-const-let.sh"
if ! [ -f "$(dirname "$(dirname "$0")")/config.js" ]; then
touch "$(dirname "$(dirname "$0")")/config.js"
if ! [ -f "$(dirname "$(dirname "$0")")/public/config.js" ]; then
touch "$(dirname "$(dirname "$0")")/public/config.js"
fi

View File

@ -7,22 +7,56 @@ error() {
exit 1
}
if [ -z "${1+x}" ]; then
error "Please provide the production directory in parameter."
fi
help() {
cat <<EOF
$0: - update the production.
This program updates Trivabble to the latest version tagged for production, and copies and prepares Trivabble for use in production.
Trivabble is composed of two parts: the server and the client.
The client is to be served by a regular HTTP server and lives in the public folder.
The server is to be stored somewhere on your system that is not served by your HTTP server.
Parameters:
--prod-public-dir DIR: the path to the public directory, from which your HTTP server will serve the client
--prod-server-dir DIR: the path to the server directory, not served by your HTTP server.
EOF
exit 0
}
if [ "$(id -u)" = "0" ]; then
error "Not running as root. Please run me as your webserver's user for instance, using something like sudo -H -u www-data $0 $1"
fi
PROD_DIR="$1"
while ! [ -z "${1+x}" ]; do
if [ "$1" = "--prod-public-dir" ]; then
PROD_PUBLIC_DIR=$2
shift
shift
elif [ "$1" = "--prod-server-dir" ]; then
PROD_SERVER_DIR=$2
shift
shift
elif [ "$1" = "--help" ] || [ "$1" = "-h" ]; then
help
else
error "Unrecognized argument $1. Type --help for more information."
fi
done
if ! [ -d "$PROD_DIR" ]; then
error "The production directory $PROD_DIR does not exist. I give up."
if [ -z "${PROD_SERVER_DIR+x}" ]; then
error "The server production directory is not set. Type --help for more information."
fi
if [ -d "$PROD_DIR/.git" ]; then
error "The production folder should not be a git repository."
if [ -z "${PROD_PUBLIC_DIR+x}" ]; then
error "The public production directory is not set. Type --help for more information."
fi
if ! [ -d "$PROD_SERVER_DIR" ]; then
error "The server production directory $PROD_SERVER_DIR does not exist. I give up."
fi
if ! [ -d "$PROD_PUBLIC_DIR" ]; then
error "The public production directory $PROD_PUBLIC_DIR does not exist. I give up."
fi
WORKING_DIRECTORY="$(dirname "$(dirname "$0")")"
@ -31,7 +65,7 @@ if ! [ -d "$WORKING_DIRECTORY/.git" ]; then
error "Not a git repository. Cannot update."
fi
if [ -f "$WORKING_DIRECTORY/games.backup.json" ]; then
if [ -f "$WORKING_DIRECTORY/server/games.backup.json" ] || [ -f "$WORKING_DIRECTORY/games.backup.json" ]; then
error "Your working copy has a 'games.backup.json' file. I give up."
fi
@ -51,13 +85,9 @@ git checkout "$new_version"
echo "Setting up production mode..."
"$(dirname $0)"/setup_prod.sh
BACKUP_DIR="$WORKING_DIRECTORY/../trivabble-prod.bak"
echo "Backing up production to $BACKUP_DIR ..."
rsync -avp --delete "$PROD_DIR/" "$BACKUP_DIR/"
echo "Sending to production..."
rsync -avp --delete --exclude 'games.backup.json' --exclude 'config.js' --exclude '/.git' "$WORKING_DIRECTORY/" "$PROD_DIR/"
rsync -avp --delete --exclude 'config.js' "$WORKING_DIRECTORY/public/" "$PROD_PUBLIC_DIR/"
rsync -avp --delete --exclude 'config.js' "$WORKING_DIRECTORY/server/" "$PROD_SERVER_DIR/"
echo echo "Resetting the directory..."
git reset --hard "$new_version"

View File

@ -1,3 +1,5 @@
.PHONY: all
all:
node makejs.js

View File

@ -1,5 +1,7 @@
#!/usr/bin/env node
var ROOT = "../public/l10n/";
/* Builds translation files.*/
var fs = require('fs');
@ -50,7 +52,7 @@ function parseString() {
for (var l in langs) {
var lang = langs[l];
var jsFile = fs.openSync("js/" + lang + ".js", "w");
var jsFile = fs.openSync(ROOT + "js/" + lang + ".js", "w");
fs.writeSync(jsFile, "(function(){var ");
var poFiles = fs.readdirSync("po/" + lang);
for (var p in poFiles) {

View File

Before

Width:  |  Height:  |  Size: 1.7 KiB

After

Width:  |  Height:  |  Size: 1.7 KiB

View File

Before

Width:  |  Height:  |  Size: 2.8 KiB

After

Width:  |  Height:  |  Size: 2.8 KiB

View File

@ -978,9 +978,9 @@ function handleRequest(request, response) {
debuglog("Serving " + request.url);
fs.exists("." + request.url, function (exists) {
fs.exists("public/" + request.url, function (exists) {
if (exists) {
fs.readFile("." + request.url, function(err, contents) {
fs.readFile("public/" + request.url, function(err, contents) {
if (err) {
response.statusCode = 500;
response.setHeader("Content-Type", "text/plain; charset=utf-8");