From 844d23e0a6c2e2ef9d576b4f94bc03dcf9373b9f Mon Sep 17 00:00:00 2001
From: Starbeamrainbowlabs <sbrl@starbeamrainbowlabs.com>
Date: Sat, 26 Jan 2019 22:00:37 +0000
Subject: [PATCH] Add version file & auto-insertion into client app code

---
 client_src/js/Config.mjs     |  2 ++
 client_src/js/MapManager.mjs |  2 +-
 package-lock.json            | 44 ++++++++++++++++++++++++++++++++++++
 package.json                 |  1 +
 rollup.config.js             | 11 +++++++++
 version                      |  1 +
 6 files changed, 60 insertions(+), 1 deletion(-)
 create mode 100644 version

diff --git a/client_src/js/Config.mjs b/client_src/js/Config.mjs
index 0545f89..eee51fa 100644
--- a/client_src/js/Config.mjs
+++ b/client_src/js/Config.mjs
@@ -1,6 +1,8 @@
 "use strict";
 
 export default {
+	version: "__VERSION__",
+	buid_date: new Date("__BUILD_DATE__"),
 	// The url of api.php. Can be relative.
 	api_root: "../api.php",
 	// The default location to show on the map when loading the page.
diff --git a/client_src/js/MapManager.mjs b/client_src/js/MapManager.mjs
index 6bf9f9c..6ae6e45 100644
--- a/client_src/js/MapManager.mjs
+++ b/client_src/js/MapManager.mjs
@@ -11,7 +11,7 @@ import UI from './UI.mjs';
 
 class MapManager {
 	constructor() {
-		
+		console.log(Config);
 	}
 	
 	setup() {
diff --git a/package-lock.json b/package-lock.json
index 277814d..9330c3d 100644
--- a/package-lock.json
+++ b/package-lock.json
@@ -296,6 +296,24 @@
       "integrity": "sha512-+hN/Zh2D08Mx65pZ/4g5bsmNiZUuChDiQfTUQ7qJr4/kuopCr88xZsAXv6mBoZEsUI4OuGHlX59qE94K2mMW8Q==",
       "dev": true
     },
+    "brace-expansion": {
+      "version": "1.1.11",
+      "resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-1.1.11.tgz",
+      "integrity": "sha512-iCuPHDFgrHX7H2vEI/5xpz07zSHB00TpugqhmYtVmMO6518mCuRMoOYFldEBl0g187ufozdaHgWKcYFb61qGiA==",
+      "dev": true,
+      "requires": {
+        "balanced-match": "^1.0.0",
+        "concat-map": "0.0.1"
+      },
+      "dependencies": {
+        "balanced-match": {
+          "version": "1.0.0",
+          "resolved": "https://registry.npmjs.org/balanced-match/-/balanced-match-1.0.0.tgz",
+          "integrity": "sha1-ibTRmasr7kneFk6gK4nORi1xt2c=",
+          "dev": true
+        }
+      }
+    },
     "braces": {
       "version": "1.8.5",
       "resolved": "https://registry.npmjs.org/braces/-/braces-1.8.5.tgz",
@@ -557,6 +575,12 @@
       "integrity": "sha1-E3kY1teCg/ffemt8WmPhQOaUJeY=",
       "dev": true
     },
+    "concat-map": {
+      "version": "0.0.1",
+      "resolved": "https://registry.npmjs.org/concat-map/-/concat-map-0.0.1.tgz",
+      "integrity": "sha1-2Klr13/Wjfd5OnMDajug1UBdR3s=",
+      "dev": true
+    },
     "concat-with-sourcemaps": {
       "version": "1.1.0",
       "resolved": "https://registry.npmjs.org/concat-with-sourcemaps/-/concat-with-sourcemaps-1.1.0.tgz",
@@ -1701,6 +1725,15 @@
         "regex-cache": "^0.4.2"
       }
     },
+    "minimatch": {
+      "version": "3.0.4",
+      "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-3.0.4.tgz",
+      "integrity": "sha512-yJHVQEhyqPLUTgt9B83PXu6W3rx4MvvHvSUvToogpwoGDOUQ+yDrR0HRot+yOCdCO7u4hX3pWft6kWBBcqh0UA==",
+      "dev": true,
+      "requires": {
+        "brace-expansion": "^1.1.7"
+      }
+    },
     "minimist": {
       "version": "0.0.8",
       "resolved": "https://registry.npmjs.org/minimist/-/minimist-0.0.8.tgz",
@@ -4449,6 +4482,17 @@
         "style-inject": "^0.3.0"
       }
     },
+    "rollup-plugin-replace": {
+      "version": "2.1.0",
+      "resolved": "https://registry.npmjs.org/rollup-plugin-replace/-/rollup-plugin-replace-2.1.0.tgz",
+      "integrity": "sha512-SxrAIgpH/B5/W4SeULgreOemxcpEgKs2gcD42zXw50bhqGWmcnlXneVInQpAqzA/cIly4bJrOpeelmB9p4YXSQ==",
+      "dev": true,
+      "requires": {
+        "magic-string": "^0.25.1",
+        "minimatch": "^3.0.2",
+        "rollup-pluginutils": "^2.0.1"
+      }
+    },
     "rollup-plugin-terser": {
       "version": "4.0.2",
       "resolved": "https://registry.npmjs.org/rollup-plugin-terser/-/rollup-plugin-terser-4.0.2.tgz",
diff --git a/package.json b/package.json
index 3c4b36b..9b6ef6b 100644
--- a/package.json
+++ b/package.json
@@ -37,6 +37,7 @@
     "rollup-plugin-commonjs": "^9.2.0",
     "rollup-plugin-node-resolve": "^4.0.0",
     "rollup-plugin-postcss": "^1.6.3",
+    "rollup-plugin-replace": "^2.1.0",
     "rollup-plugin-terser": "^4.0.2"
   }
 }
diff --git a/rollup.config.js b/rollup.config.js
index 1791289..93be6e2 100644
--- a/rollup.config.js
+++ b/rollup.config.js
@@ -1,10 +1,12 @@
 import os from 'os';
 import path from 'path';
+import fs from 'fs';
 
 import resolve from 'rollup-plugin-node-resolve';
 import commonjs from 'rollup-plugin-commonjs';
 import postcss from 'rollup-plugin-postcss';
 import { terser } from "rollup-plugin-terser";
+import replace from 'rollup-plugin-replace';
 
 import postcss_import from 'postcss-import';
 import postcss_copy from 'postcss-copy';
@@ -33,6 +35,15 @@ let plugins = [
 		extensions: ['.mjs', '.js', '.jsx', '.json'], // Default: [ '.mjs', '.js', '.json', '.node' ]
 	}),
 	
+	
+	replace({
+		exclude: 'node_modules/**',
+		values: {
+			"__BUILD_DATE__": () => new Date().toISOString(),
+			"__VERSION__": fs.readFileSync("version", "utf8").trim()
+		}
+	}),
+	
 	commonjs({
 		
 	}),
diff --git a/version b/version
new file mode 100644
index 0000000..1474d00
--- /dev/null
+++ b/version
@@ -0,0 +1 @@
+v0.2.0
