From cf190b84c5379dff86c48405d36f99835333db68 Mon Sep 17 00:00:00 2001
From: ezsh <ezsh.junk@gmail.com>
Date: Tue, 9 Jun 2020 13:23:32 +0200
Subject: [PATCH] Add Git commit hash to the App.Version object

---
 .gitignore                          |  1 +
 Makefile                            |  4 ++--
 compile.sh                          | 11 +++--------
 src/002-config/fc-version.js        |  3 ++-
 src/gui/mainMenu/AlphaDisclaimer.tw |  4 ++--
 5 files changed, 10 insertions(+), 13 deletions(-)

diff --git a/.gitignore b/.gitignore
index 89e2504c207..230dd8b9dad 100644
--- a/.gitignore
+++ b/.gitignore
@@ -135,3 +135,4 @@ fc-pregmod
 TODO.txt
 temp.*
 *.temp
+src/002-config/fc-version.js.commitHash.js
diff --git a/Makefile b/Makefile
index deeeed4e2d7..e1bee417127 100644
--- a/Makefile
+++ b/Makefile
@@ -30,7 +30,7 @@ bin/resources: resources
 	test -L "$@" || ln -s "../$<" bin/
 
 bin/%.html: bin/tmp
-	git checkout -- src/gui/mainMenu/AlphaDisclaimer.tw
+	rm src/002-config/fc-version.js.commitHash.js
 	mv $< $@
 
 bin/fc.js: bin/
@@ -41,7 +41,7 @@ bin/tmp: bin/fc.js injectGitCommitHash
 	rm -f bin/fc.js
 
 injectGitCommitHash:
-	sed -Ei "s/build: .releaseID/\0, commit $(COMMIT)/" src/gui/mainMenu/AlphaDisclaimer.tw
+	printf "App.Version.commitHash = '%s';\n" $(COMMIT) > src/002-config/fc-version.js.commitHash.js
 
 bin/:
 	mkdir -p $@
diff --git a/compile.sh b/compile.sh
index ef62d7c3edc..b692df31e8c 100755
--- a/compile.sh
+++ b/compile.sh
@@ -64,16 +64,13 @@ function compile() {
 		esac
 	fi
 
+	file="bin/FC_pregmod.html"
 	if [[ -d .git ]]; then
 		COMMIT=$(git rev-parse --short HEAD) # Find and insert current commit
+		printf "App.Version.commitHash = '%s';\n" $(COMMIT) > src/002-config/fc-version.js.commitHash.js
 		if [[ "$usehash" ]]; then
 			file="bin/FC_pregmod_${COMMIT}.html"
-		else
-			sed -Ei "s/build: .releaseID/\0, commit: $COMMIT/" src/gui/mainMenu/AlphaDisclaimer.tw
-			file="bin/FC_pregmod.html"
 		fi
-	else
-		file="bin/FC_pregmod.html"
 	fi
 
 	devTools/concatFiles.sh js/ '*.js' bin/fc.js
@@ -84,10 +81,8 @@ function compile() {
 		exit 1
 	fi
 
-	#Make the output prettier, replacing \t with a tab and \n with a newline
-	sed -i -e '/^.*<div id="store-area".*$/s/\\t/\t/g' -e '/^.*<div id="store-area".*$/s/\\n/\n/g' $file
 	if [[ -d .git ]]; then
-		git checkout -- src/gui/mainMenu/AlphaDisclaimer.tw # Revert AlphaDisclaimer for next compilation
+		rm src/002-config/fc-version.js.commitHash.js
 	fi
 	echoMessage "Saved to $file."
 }
diff --git a/src/002-config/fc-version.js b/src/002-config/fc-version.js
index bd057a26dea..88d1b12cba6 100644
--- a/src/002-config/fc-version.js
+++ b/src/002-config/fc-version.js
@@ -1,7 +1,8 @@
 App.Version = {
 	base: "0.10.7.1", // The vanilla version the mod is based off of, this should never be changed.
 	pmod: "3.5.2",
-	release: 1072,
+	commitHash: null,
+	release: 1072
 };
 
 /* Use release as save version */
diff --git a/src/gui/mainMenu/AlphaDisclaimer.tw b/src/gui/mainMenu/AlphaDisclaimer.tw
index 661fb76ccc7..717c8b16c4e 100644
--- a/src/gui/mainMenu/AlphaDisclaimer.tw
+++ b/src/gui/mainMenu/AlphaDisclaimer.tw
@@ -30,7 +30,7 @@
 	 	Pregmod is a modification of the original <i>Free Cities</i> created by FCdev, which can be seen at https://freecitiesblog.blogspot.com/.
 	</div>
 	<div class="note">
-		version: $ver, mod version: $pmodVer, build: $releaseID
+		version: $ver, mod version: $pmodVer, build: $releaseID <<if App.Version.commitHash>>commit: <<= App.Version.commitHash>><</if>>
 	</div>
 	<div id="version">
 		<<link "More version info">>
@@ -59,4 +59,4 @@
 
 <p>
 	[[I am 18 or more years of age, I understand, and I wish to continue|Economy Intro]]
-</p>
\ No newline at end of file
+</p>
-- 
GitLab