ctucx.git: trainsearch

web based trip-planner, fork of https://cyberchaos.dev/yuka/trainsearch

commit cab13f8ae113b2a75bc14c272675f778394e4edc
parent fe008383474dda50264b33b6ea42ae26ce20973e
Author: Katja (ctucx) <git@ctu.cx>
Date: Mon, 27 Jan 2025 13:33:30 +0100

searchView: show running version
5 files changed, 27 insertions(+), 3 deletions(-)
diff --git a/flake.nix b/flake.nix
@@ -15,7 +15,11 @@
         name = "trainsearch";
         src  = self;
 
-        npmDepsHash = "sha256-netsELe2etLYmXxUtAf5IasVqQp8OZuZbTpW44T9GeQ=";
+        GIT_VERSION    = if (self.sourceInfo ? shortRev) then self.sourceInfo.shortRev else "dirty";
+        GIT_COMMIT     = if (self.sourceInfo ? rev)      then self.sourceInfo.rev      else "dirty";
+        GIT_COMMITDATE = builtins.concatStringsSep "-" (builtins.match "(.{4})(.{2})(.{2}).*" self.lastModifiedDate);
+
+        npmDepsHash = "sha256-NrQlSXvaK9pVNuDci/KVvuyL3nJS2Efbv3LDi433Z6g=";
         makeCacheWritable = true;
 
         npmBuildScript = "build";

@@ -40,7 +44,7 @@
       packages.trainsearch = pkgs.trainsearch;
 
       devShells.default = pkgs.mkShell {
-        nativeBuildInputs = with pkgs; [
+        buildInputs = with pkgs; [
           nodejs
           nodePackages.webpack
           nodePackages.webpack-cli
diff --git a/package-lock.json b/package-lock.json
@@ -14,6 +14,7 @@
         "date-fns": "^4.1.0",
         "date-fns-tz": "^3.2.0",
         "db-vendo-client": "https://github.com/yuyuyureka/db-vendo-client#main",
+        "git-revision-webpack-plugin": "^5.0.0",
         "hafas-client": "https://github.com/yu-re-ka/hafas-client#main",
         "idb": "^8.0.1",
         "lit-html": "^3.2.1",

@@ -4243,6 +4244,18 @@
         "url": "https://github.com/sponsors/ljharb"
       }
     },
+    "node_modules/git-revision-webpack-plugin": {
+      "version": "5.0.0",
+      "resolved": "https://registry.npmjs.org/git-revision-webpack-plugin/-/git-revision-webpack-plugin-5.0.0.tgz",
+      "integrity": "sha512-RptQN/4UKcEPkCBmRy8kLPo5i8MnF8+XfAgFYN9gbwmKLTLx4YHsQw726H+C5+sIGDixDkmGL3IxPA2gKo+u4w==",
+      "license": "MIT",
+      "engines": {
+        "node": ">=10"
+      },
+      "peerDependencies": {
+        "webpack": "^5.0.0"
+      }
+    },
     "node_modules/glob": {
       "version": "7.2.3",
       "resolved": "https://registry.npmjs.org/glob/-/glob-7.2.3.tgz",
diff --git a/package.json b/package.json
@@ -15,6 +15,7 @@
     "date-fns": "^4.1.0",
     "date-fns-tz": "^3.2.0",
     "db-vendo-client": "https://github.com/yuyuyureka/db-vendo-client#main",
+    "git-revision-webpack-plugin": "^5.0.0",
     "hafas-client": "https://github.com/yu-re-ka/hafas-client#main",
     "idb": "^8.0.1",
     "lit-html": "^3.2.1",
diff --git a/src/searchView.js b/src/searchView.js
@@ -169,7 +169,7 @@ const searchTemplate = (journeysHistory) => html`
 		</div>
 
 		<footer>
-			<a href="https://git.ctu.cx/trainsearch">Source-Code</a>
+			<a href="https://git.ctu.cx/trainsearch" title="commit ${COMMIT} from ${COMMITDATE}">Source-Code (${VERSION})</a>
 			<a href="https://ctu.cx/imprint.html">Imprint</a>
 		</footer>
 	</div>
diff --git a/webpack.config.js b/webpack.config.js
@@ -1,7 +1,9 @@
 const path = require("path");
 const CopyPlugin = require("copy-webpack-plugin");
 const { DefinePlugin, ProvidePlugin, NormalModuleReplacementPlugin } = require("webpack");
+const { GitRevisionPlugin } = require('git-revision-webpack-plugin');
 const WorkboxPlugin = require('workbox-webpack-plugin');
+const gitRevisionPlugin = new GitRevisionPlugin();
 
 const dist = path.resolve(__dirname, "dist");
 

@@ -51,6 +53,10 @@ module.exports = {
     new DefinePlugin({
       "process.env": "{}",
       "isDevServer": process.env.WEBPACK_SERVE,
+      "APPNAME":     JSON.stringify("TrainSearch"),
+      "VERSION":     JSON.stringify(process.env.GIT_VERSION    ? process.env.GIT_VERSION    : gitRevisionPlugin.version()),
+      "COMMIT":      JSON.stringify(process.env.GIT_COMMIT     ? process.env.GIT_COMMIT     : gitRevisionPlugin.commithash()),
+      "COMMITDATE":  JSON.stringify(process.env.GIT_COMMITDATE ? process.env.GIT_COMMITDATE : gitRevisionPlugin.lastcommitdatetime()),
     }),
     new ProvidePlugin({
       Buffer: ['buffer', 'Buffer'],